pub struct DiagnosticBuilder<'a> { /* private fields */ }
Expand description
Used for emitting structured error messages and other diagnostic information.
Implementations§
Source§impl<'a> DiagnosticBuilder<'a>
impl<'a> DiagnosticBuilder<'a>
Sourcepub fn span_label<T: Into<String>>(&mut self, span: Span, label: T) -> &mut Self
pub fn span_label<T: Into<String>>(&mut self, span: Span, label: T) -> &mut Self
Add a span/label to be included in the resulting snippet.
This is pushed onto the MultiSpan
that was created when the
diagnostic was first built. If you don’t call this function at
all, and you just supplied a Span
to create the diagnostic,
then the snippet will just include that Span
, which is
called the primary span.
pub fn note_expected_found( &mut self, label: &dyn Display, expected: DiagnosticStyledString, found: DiagnosticStyledString, ) -> &mut Self
pub fn note_expected_found_extra( &mut self, label: &dyn Display, expected: DiagnosticStyledString, found: DiagnosticStyledString, expected_extra: &dyn Display, found_extra: &dyn Display, ) -> &mut Self
pub fn note(&mut self, msg: &str) -> &mut Self
pub fn span_note<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self
pub fn warn(&mut self, msg: &str) -> &mut Self
pub fn span_warn<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self
pub fn help(&mut self, msg: &str) -> &mut Self
pub fn span_help<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self
pub fn span_suggestion( &mut self, sp: Span, msg: &str, suggestion: String, ) -> &mut Self
pub fn span_suggestions( &mut self, sp: Span, msg: &str, suggestions: Vec<String>, ) -> &mut Self
pub fn set_span<S: Into<MultiSpan>>(&mut self, sp: S) -> &mut Self
pub fn code(&mut self, s: String) -> &mut Self
Sourcepub fn new(
handler: &'a Handler,
level: Level,
message: &str,
) -> DiagnosticBuilder<'a>
pub fn new( handler: &'a Handler, level: Level, message: &str, ) -> DiagnosticBuilder<'a>
Convenience function for internal use, clients should use one of the struct_* methods on Handler.
Sourcepub fn new_with_code(
handler: &'a Handler,
level: Level,
code: Option<String>,
message: &str,
) -> DiagnosticBuilder<'a>
pub fn new_with_code( handler: &'a Handler, level: Level, code: Option<String>, message: &str, ) -> DiagnosticBuilder<'a>
Convenience function for internal use, clients should use one of the struct_* methods on Handler.
pub fn into_diagnostic(self) -> Diagnostic
Methods from Deref<Target = Diagnostic>§
Sourcepub fn cancel(&mut self)
pub fn cancel(&mut self)
Cancel the diagnostic (a structured diagnostic must either be emitted or
cancelled or it will panic when dropped).
BEWARE: if this DiagnosticBuilder is an error, then creating it will
bump the error count on the Handler and cancelling it won’t undo that.
If you want to decrement the error count you should use Handler::cancel
.
pub fn cancelled(&self) -> bool
pub fn is_fatal(&self) -> bool
Sourcepub fn span_label<T: Into<String>>(&mut self, span: Span, label: T) -> &mut Self
pub fn span_label<T: Into<String>>(&mut self, span: Span, label: T) -> &mut Self
Add a span/label to be included in the resulting snippet.
This is pushed onto the MultiSpan
that was created when the
diagnostic was first built. If you don’t call this function at
all, and you just supplied a Span
to create the diagnostic,
then the snippet will just include that Span
, which is
called the primary span.
pub fn note_expected_found( &mut self, label: &dyn Display, expected: DiagnosticStyledString, found: DiagnosticStyledString, ) -> &mut Self
pub fn note_expected_found_extra( &mut self, label: &dyn Display, expected: DiagnosticStyledString, found: DiagnosticStyledString, expected_extra: &dyn Display, found_extra: &dyn Display, ) -> &mut Self
pub fn note(&mut self, msg: &str) -> &mut Self
pub fn highlighted_note(&mut self, msg: Vec<(String, Style)>) -> &mut Self
pub fn span_note<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self
pub fn warn(&mut self, msg: &str) -> &mut Self
pub fn span_warn<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self
pub fn help(&mut self, msg: &str) -> &mut Self
pub fn span_help<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self
Sourcepub fn span_suggestion(
&mut self,
sp: Span,
msg: &str,
suggestion: String,
) -> &mut Self
pub fn span_suggestion( &mut self, sp: Span, msg: &str, suggestion: String, ) -> &mut Self
Prints out a message with a suggested edit of the code.
See diagnostic::CodeSuggestion
for more information.
pub fn span_suggestions( &mut self, sp: Span, msg: &str, suggestions: Vec<String>, ) -> &mut Self
pub fn set_span<S: Into<MultiSpan>>(&mut self, sp: S) -> &mut Self
pub fn code(&mut self, s: String) -> &mut Self
pub fn message(&self) -> String
pub fn styled_message(&self) -> &Vec<(String, Style)>
pub fn level(&self) -> Level
Sourcepub fn copy_details_not_message(&mut self, from: &Diagnostic)
pub fn copy_details_not_message(&mut self, from: &Diagnostic)
Used by a lint. Copies over all details but the “main message”.
Trait Implementations§
Source§impl<'a> Clone for DiagnosticBuilder<'a>
impl<'a> Clone for DiagnosticBuilder<'a>
Source§fn clone(&self) -> DiagnosticBuilder<'a>
fn clone(&self) -> DiagnosticBuilder<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more