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>

pub fn is_error(&self) -> bool

If this diagnostic’s level is Level::Error.

§

impl 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>

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>

Emits all if possible, otherwise returns Err containing a TokenStream of compile_error!(...) calls.

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>

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,

§

fn clone(&self) -> Diagnostic<S>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl<S> Debug for Diagnostic<S>
where S: Debug,

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

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>,

Deserialize this value from the given Serde deserializer. Read more
§

impl Display for Diagnostic

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Display for Diagnostic<SerdeSpan>

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl From<Error> for Diagnostic

§

fn from(value: Error) -> Diagnostic

Converts to this type from the input type.
§

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,

Serialize this value into the given Serde serializer. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T