Struct Diagnostic
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§
§impl<S> Diagnostic<S>
impl<S> Diagnostic<S>
pub fn is_error(&self) -> bool
pub fn is_error(&self) -> bool
If this diagnostic’s level is Level::Error
.
§impl Diagnostic
impl Diagnostic
pub fn spanned(
span: Span,
level: Level,
message: impl Into<String>,
) -> Diagnostic
pub fn spanned( span: Span, level: Level, message: impl Into<String>, ) -> Diagnostic
Create a new diagnostic from the given span, level, and message.
pub 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.
pub fn try_emit_all<'a>(
diagnostics: impl IntoIterator<Item = &'a Diagnostic>,
) -> Result<(), TokenStream>
pub fn try_emit_all<'a>( diagnostics: impl IntoIterator<Item = &'a Diagnostic>, ) -> Result<(), TokenStream>
Emits all if possible, otherwise returns Err
containing a TokenStream
of
compile_error!(...)
calls.
pub 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.
pub 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§
§impl<S> Clone for Diagnostic<S>where
S: Clone,
impl<S> Clone for Diagnostic<S>where
S: Clone,
§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 more§impl<S> Debug for Diagnostic<S>where
S: Debug,
impl<S> Debug for Diagnostic<S>where
S: Debug,
§impl<'de, S> Deserialize<'de> for Diagnostic<S>where
S: Deserialize<'de>,
impl<'de, S> Deserialize<'de> for Diagnostic<S>where
S: Deserialize<'de>,
§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Diagnostic<S>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Diagnostic<S>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
§impl Display for Diagnostic
impl Display for Diagnostic
§impl Display for Diagnostic<SerdeSpan>
impl Display for Diagnostic<SerdeSpan>
§impl From<Error> for Diagnostic
impl From<Error> for Diagnostic
§fn from(value: Error) -> Diagnostic
fn from(value: Error) -> Diagnostic
§impl<S> Serialize for Diagnostic<S>where
S: Serialize,
impl<S> Serialize for Diagnostic<S>where
S: Serialize,
§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
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§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