pub struct DiagnosticWrapper<K> {
pub kind: K,
/* private fields */
}Expand description
A compilation diagnostic (error or warning) with optional source location.
This is a generic wrapper that holds a diagnostic kind along with optional source location and rich diagnostic information (labels, notes, helps).
Use the type aliases CompileError and CompileWarning for the
specific error and warning types.
Diagnostics can include rich information using the builder methods:
CompileError::new(ErrorKind::TypeMismatch { ... }, span)
.with_label("expected because of this", other_span)
.with_note("types must match exactly")
.with_help("consider adding a type conversion")Fields§
§kind: KThe specific kind of diagnostic.
Implementations§
Source§impl<K> DiagnosticWrapper<K>
impl<K> DiagnosticWrapper<K>
Sourcepub fn without_span(kind: K) -> Self
pub fn without_span(kind: K) -> Self
Create a diagnostic without a source location.
Use this for diagnostics that don’t correspond to a specific source location, such as “no main function found” or linker errors.
Sourcepub fn has_span(&self) -> bool
pub fn has_span(&self) -> bool
Returns true if this diagnostic has source location information.
Sourcepub fn diagnostic(&self) -> &Diagnostic
pub fn diagnostic(&self) -> &Diagnostic
Get the diagnostic information.
Sourcepub fn with_label(self, message: impl Into<String>, span: Span) -> Self
pub fn with_label(self, message: impl Into<String>, span: Span) -> Self
Add a secondary label pointing to related code.
Labels appear as additional annotations in the source snippet.
Sourcepub fn with_note(self, message: impl Into<String>) -> Self
pub fn with_note(self, message: impl Into<String>) -> Self
Add an informational note.
Notes appear as footer messages providing context.
Sourcepub fn with_help(self, message: impl Into<String>) -> Self
pub fn with_help(self, message: impl Into<String>) -> Self
Add a help suggestion.
Helps appear as footer messages with actionable advice.
Sourcepub fn with_suggestion(self, suggestion: Suggestion) -> Self
pub fn with_suggestion(self, suggestion: Suggestion) -> Self
Add a code suggestion that can be applied to fix the issue.
Suggestions provide machine-readable fix information for IDEs and tools.
Trait Implementations§
Source§impl<K: Clone> Clone for DiagnosticWrapper<K>
impl<K: Clone> Clone for DiagnosticWrapper<K>
Source§fn clone(&self) -> DiagnosticWrapper<K>
fn clone(&self) -> DiagnosticWrapper<K>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more