Struct dfir_lang::diagnostic::Diagnostic
source · pub struct Diagnostic<S = Span> {
pub span: S,
pub level: Level,
pub message: String,
}
Expand description
Diagnostic. A warning or error (or lower Level
) with a message and span. Shown by IDEs
usually as a squiggly red or yellow underline.
Diagnostics must be emitted via Diagnostic::try_emit
, Diagnostic::to_tokens
, or
Diagnostic::try_emit_all
for diagnostics to show up.
Fields§
§span: S
Span (source code location).
level: Level
Severity level.
message: String
Human-readable message.
Implementations§
source§impl<S> Diagnostic<S>
impl<S> Diagnostic<S>
sourcepub fn is_error(&self) -> bool
pub fn is_error(&self) -> bool
If this diagnostic’s level is Level::Error
.
source§impl Diagnostic
impl Diagnostic
sourcepub fn spanned(span: Span, level: Level, message: impl Into<String>) -> Self
pub fn spanned(span: Span, level: Level, message: impl Into<String>) -> Self
Create a new diagnostic from the given span, level, and message.
sourcepub fn try_emit(&self) -> Result<(), TokenStream>
pub fn try_emit(&self) -> Result<(), TokenStream>
Emit if possible, otherwise return Err
containing a TokenStream
of a
compile_error!(...)
call.
sourcepub fn try_emit_all<'a>(
diagnostics: impl IntoIterator<Item = &'a Self>,
) -> Result<(), TokenStream>
pub fn try_emit_all<'a>( diagnostics: impl IntoIterator<Item = &'a Self>, ) -> Result<(), TokenStream>
Emits all if possible, otherwise returns Err
containing a TokenStream
of
compile_error!(...)
calls.
sourcepub fn to_tokens(&self) -> TokenStream
pub fn to_tokens(&self) -> TokenStream
Used to emulate proc_macro::Diagnostic::emit
by turning this diagnostic into a properly spanned TokenStream
that emits an error via compile_error!(...)
with this diagnostic’s message.
sourcepub fn to_serde(&self) -> Diagnostic<SerdeSpan>
pub fn to_serde(&self) -> Diagnostic<SerdeSpan>
Converts this into a serializable and deserializable Diagnostic. Span information is
converted into SerdeSpan
which keeps the span info but cannot be plugged into or
emitted through the Rust compiler’s diagnostic system.
Trait Implementations§
source§impl<S: Clone> Clone for Diagnostic<S>
impl<S: Clone> Clone for Diagnostic<S>
source§fn clone(&self) -> Diagnostic<S>
fn clone(&self) -> Diagnostic<S>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<S: Debug> Debug for Diagnostic<S>
impl<S: Debug> Debug for Diagnostic<S>
source§impl<'de, S> Deserialize<'de> for Diagnostic<S>where
S: Deserialize<'de>,
impl<'de, S> Deserialize<'de> for Diagnostic<S>where
S: Deserialize<'de>,
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl Display for Diagnostic
impl Display for Diagnostic
source§impl Display for Diagnostic<SerdeSpan>
impl Display for Diagnostic<SerdeSpan>
source§impl From<Error> for Diagnostic
impl From<Error> for Diagnostic
Auto Trait Implementations§
impl<S> Freeze for Diagnostic<S>where
S: Freeze,
impl<S> RefUnwindSafe for Diagnostic<S>where
S: RefUnwindSafe,
impl<S> Send for Diagnostic<S>where
S: Send,
impl<S> Sync for Diagnostic<S>where
S: Sync,
impl<S> Unpin for Diagnostic<S>where
S: Unpin,
impl<S> UnwindSafe for Diagnostic<S>where
S: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more