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>

source

pub fn is_error(&self) -> bool

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

source§

impl Diagnostic

source

pub fn spanned(span: Span, level: Level, message: impl Into<String>) -> Self

Create a new diagnostic from the given span, level, and message.

source

pub fn try_emit(&self) -> Result<(), TokenStream>

Emit if possible, otherwise return Err containing a TokenStream of a compile_error!(...) call.

source

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.

source

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.

source

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>

source§

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
source§

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

source§

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

Formats the value using the given formatter. Read more
source§

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

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

impl Display for Diagnostic

source§

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

Formats the value using the given formatter. Read more
source§

impl Display for Diagnostic<SerdeSpan>

source§

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

Formats the value using the given formatter. Read more
source§

impl From<Error> for Diagnostic

source§

fn from(value: Error) -> Self

Converts to this type from the input type.
source§

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

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::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 T)

🔬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§

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