Skip to main content

Diagnostic

Struct Diagnostic 

Source
pub struct Diagnostic {
    pub code: &'static str,
    pub severity: Severity,
    pub message: String,
    pub file: FileId,
    pub primary: Label,
    pub secondary: Vec<Label>,
    pub notes: Vec<String>,
    pub fix: Option<Fix>,
}
Expand description

One problem, at one place, with one cause.

Cascades are deliberately not modelled. If a single root cause would produce several diagnostics, the producer is expected to emit one diagnostic with secondary labels instead, because a wall of derived errors buries the line that actually needs editing.

Fields§

§code: &'static str

Stable identifier, for example DEED1002. Codes are never reused.

§severity: Severity§message: String§file: FileId§primary: Label§secondary: Vec<Label>§notes: Vec<String>§fix: Option<Fix>

Implementations§

Source§

impl Diagnostic

Source

pub fn error( code: &'static str, file: FileId, span: Span, message: impl Into<String>, ) -> Self

Source

pub fn warning( code: &'static str, file: FileId, span: Span, message: impl Into<String>, ) -> Self

Source

pub fn with_primary_label(self, message: impl Into<String>) -> Self

Overrides the primary label, when the underline should say something shorter or more specific than the headline message.

Source

pub fn with_secondary(self, span: Span, message: impl Into<String>) -> Self

Source

pub fn with_secondary_in( self, file: FileId, span: Span, message: impl Into<String>, ) -> Self

The same, about somewhere else.

For the producer that has a span from another module in hand: a precondition failure names a clause in the callee and is filed against the caller, and a postcondition failure is the other way round. Passing the diagnostic’s own file here is harmless and says the same thing as Self::with_secondary.

Source

pub fn with_note(self, note: impl Into<String>) -> Self

Source

pub fn with_fix( self, message: impl Into<String>, span: Span, replacement: impl Into<String>, applicability: Applicability, ) -> Self

Source

pub fn with_edits( self, message: impl Into<String>, edits: Vec<SuggestedEdit>, applicability: Applicability, ) -> Self

A fix made of several edits that only mean anything together.

One edit is the ordinary case, which is what Self::with_fix is for. This is for a repair that has to wrap something: turning n as String into to_string(n) is an insertion in front of the value and a replacement behind it, and either half on its own leaves the line worse than it was found. Whoever applies a fix has to take all of it or none.

The edits are given in the order they appear in the file.

Source

pub fn is_error(&self) -> bool

Trait Implementations§

Source§

impl Clone for Diagnostic

Source§

fn clone(&self) -> Diagnostic

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Diagnostic

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> 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, 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.