pub struct Diagnostic {
pub severity: Severity,
pub code: &'static str,
pub message: String,
pub span: Option<DiagSpan>,
pub source_hint: Option<String>,
pub notes: Vec<String>,
}Expand description
A single compiler diagnostic with an optional source location.
Fields§
§severity: Severity§code: &'static strShort alphanumeric code, e.g. “E001”.
message: String§span: Option<DiagSpan>Byte range in the source file, if known.
source_hint: Option<String>A short extract of the source shown below the message, if provided.
notes: Vec<String>Free-form follow-up lines following common formatting / conventions
cos why the hell not (=note = ...). Preserves order.
Implementations§
Source§impl Diagnostic
impl Diagnostic
pub fn error(code: &'static str, message: impl Into<String>) -> Self
pub fn warning(code: &'static str, message: impl Into<String>) -> Self
pub fn with_span(self, span: DiagSpan) -> Self
pub fn with_source_hint(self, hint: impl Into<String>) -> Self
Sourcepub fn with_note(self, msg: impl Into<String>) -> Self
pub fn with_note(self, msg: impl Into<String>) -> Self
Attach a follow-up note. Notes appear after the caret line when using styled render output - printed in the note colour for extra awesomeness. Multiple notes pushed will stack in the order they are inserted.
Sourcepub fn render(&self, source: &Source<'_>) -> String
pub fn render(&self, source: &Source<'_>) -> String
Render the diagnostic with a source listing and a caret under
the span that actually caused it. If the diagnostic has no span,
falls back to Display representation. Output has no escape codes
(not styled) - used if writing out to a file or pipe :D
Sourcepub fn render_styled(&self, source: &Source<'_>, style: Style) -> String
pub fn render_styled(&self, source: &Source<'_>, style: Style) -> String
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