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 strStable 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
impl Diagnostic
pub fn error( code: &'static str, file: FileId, span: Span, message: impl Into<String>, ) -> Self
pub fn warning( code: &'static str, file: FileId, span: Span, message: impl Into<String>, ) -> Self
Sourcepub fn with_primary_label(self, message: impl Into<String>) -> Self
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.
pub fn with_secondary(self, span: Span, message: impl Into<String>) -> Self
Sourcepub fn with_secondary_in(
self,
file: FileId,
span: Span,
message: impl Into<String>,
) -> Self
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.
pub fn with_note(self, note: impl Into<String>) -> Self
pub fn with_fix( self, message: impl Into<String>, span: Span, replacement: impl Into<String>, applicability: Applicability, ) -> Self
Sourcepub fn with_edits(
self,
message: impl Into<String>,
edits: Vec<SuggestedEdit>,
applicability: Applicability,
) -> Self
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.
pub fn is_error(&self) -> bool
Trait Implementations§
Source§impl Clone for Diagnostic
impl Clone for Diagnostic
Source§fn clone(&self) -> Diagnostic
fn clone(&self) -> Diagnostic
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more