Struct swc_common::errors::DiagnosticBuilder
source · [−]pub struct DiagnosticBuilder<'a> {
pub handler: &'a Handler,
/* private fields */
}
Expand description
Used for emitting structured error messages and other diagnostic information.
If there is some state in a downstream crate you would like to
access in the methods of DiagnosticBuilder
here, consider
extending HandlerFlags
, accessed via self.handler.flags
.
Fields
handler: &'a Handler
Implementations
sourceimpl<'a> DiagnosticBuilder<'a>
impl<'a> DiagnosticBuilder<'a>
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_short(
&mut self,
sp: Span,
msg: &str,
suggestion: String
) -> &mut Self
pub fn multipart_suggestion(
&mut self,
msg: &str,
suggestion: Vec<(Span, String)>
) -> &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: DiagnosticId) -> &mut Self
sourcepub fn buffer(self, buffered_diagnostics: &mut Vec<Diagnostic>)
pub fn buffer(self, buffered_diagnostics: &mut Vec<Diagnostic>)
Buffers the diagnostic for later emission, unless handler has disabled such buffering.
sourcepub fn sub<S: Into<MultiSpan>>(
&mut self,
level: Level,
message: &str,
span: Option<S>
) -> &mut Self
pub fn sub<S: Into<MultiSpan>>(
&mut self,
level: Level,
message: &str,
span: Option<S>
) -> &mut Self
Convenience function for internal use, clients should use one of the span_* methods instead.
sourcepub fn delay_as_bug(&mut self)
pub fn delay_as_bug(&mut self)
Delay emission of this diagnostic as a bug.
This can be useful in contexts where an error indicates a bug but typically this only happens when other compilation errors have already happened. In those cases this can be used to defer emission of this diagnostic as a bug in the compiler only if no other errors have been emitted.
In the meantime, though, callsites are required to deal with the “bug” locally in whichever way makes the most sense.
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 multipart_suggestion_with_applicability(
&mut self,
msg: &str,
suggestion: Vec<(Span, String)>,
applicability: Applicability
) -> &mut Self
pub fn span_suggestion_with_applicability(
&mut self,
sp: Span,
msg: &str,
suggestion: String,
applicability: Applicability
) -> &mut Self
pub fn span_suggestions_with_applicability(
&mut self,
sp: Span,
msg: &str,
suggestions: impl Iterator<Item = String>,
applicability: Applicability
) -> &mut Self
pub fn span_suggestion_short_with_applicability(
&mut self,
sp: Span,
msg: &str,
suggestion: String,
applicability: Applicability
) -> &mut Self
pub fn allow_suggestions(&mut self, allow: bool) -> &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<DiagnosticId>,
message: &str
) -> DiagnosticBuilder<'a>
pub fn new_with_code(
handler: &'a Handler,
level: Level,
code: Option<DiagnosticId>,
message: &str
) -> DiagnosticBuilder<'a>
Convenience function for internal use, clients should use one of the struct_* methods on Handler.
sourcepub fn new_diagnostic(
handler: &'a Handler,
diagnostic: Diagnostic
) -> DiagnosticBuilder<'a>
pub fn new_diagnostic(
handler: &'a Handler,
diagnostic: Diagnostic
) -> DiagnosticBuilder<'a>
Creates a new DiagnosticBuilder
with an already constructed
diagnostic.
Methods from Deref<Target = Diagnostic>
pub fn is_error(&self) -> bool
sourcepub fn cancel(&mut self)
pub fn cancel(&mut self)
Cancel the diagnostic (a structured diagnostic must either be emitted or canceled or it will panic when dropped).
pub fn cancelled(&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 replace_span_with(&mut self, after: Span) -> &mut Self
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_trait_signature(
&mut self,
name: String,
signature: String
) -> &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_short(
&mut self,
sp: Span,
msg: &str,
suggestion: String
) -> &mut Self
👎Deprecated: Use span_suggestion_short_with_applicability
pub fn span_suggestion_short(
&mut self,
sp: Span,
msg: &str,
suggestion: String
) -> &mut Self
Use span_suggestion_short_with_applicability
Prints out a message with a suggested edit of the code. If the suggestion is presented inline it will only show the text message and not the text.
See CodeSuggestion
for more information.
sourcepub fn span_suggestion(
&mut self,
sp: Span,
msg: &str,
suggestion: String
) -> &mut Self
👎Deprecated: Use span_suggestion_with_applicability
pub fn span_suggestion(
&mut self,
sp: Span,
msg: &str,
suggestion: String
) -> &mut Self
Use span_suggestion_with_applicability
Prints out a message with a suggested edit of the code.
In case of short messages and a simple suggestion, rustc displays it as a label like
“try adding parentheses: (tup.0).1
”
The message
- should not end in any punctuation (a
:
is added automatically) - should not be a question
- should not contain any parts like “the following”, “as shown”
- may look like “to do xyz, use” or “to do xyz, use abc”
- may contain a name of a function, variable or type, but not whole expressions
See CodeSuggestion
for more information.
pub fn multipart_suggestion_with_applicability(
&mut self,
msg: &str,
suggestion: Vec<(Span, String)>,
applicability: Applicability
) -> &mut Self
pub fn multipart_suggestion(
&mut self,
msg: &str,
suggestion: Vec<(Span, String)>
) -> &mut Self
Use multipart_suggestion_with_applicability
sourcepub fn span_suggestions(
&mut self,
sp: Span,
msg: &str,
suggestions: Vec<String>
) -> &mut Self
👎Deprecated: Use span_suggestions_with_applicability
pub fn span_suggestions(
&mut self,
sp: Span,
msg: &str,
suggestions: Vec<String>
) -> &mut Self
Use span_suggestions_with_applicability
Prints out a message with multiple suggested edits of the code.
sourcepub fn span_suggestion_with_applicability(
&mut self,
sp: Span,
msg: &str,
suggestion: String,
applicability: Applicability
) -> &mut Self
pub fn span_suggestion_with_applicability(
&mut self,
sp: Span,
msg: &str,
suggestion: String,
applicability: Applicability
) -> &mut Self
This is a suggestion that may contain mistakes or fillers and should be read and understood by a human.
pub fn span_suggestions_with_applicability(
&mut self,
sp: Span,
msg: &str,
suggestions: impl Iterator<Item = String>,
applicability: Applicability
) -> &mut Self
pub fn span_suggestion_short_with_applicability(
&mut self,
sp: Span,
msg: &str,
suggestion: String,
applicability: Applicability
) -> &mut Self
pub fn set_span<S: Into<MultiSpan>>(&mut self, sp: S) -> &mut Self
pub fn code(&mut self, s: DiagnosticId) -> &mut Self
pub fn get_code(&self) -> Option<DiagnosticId>
pub fn message(&self) -> String
pub fn styled_message(&self) -> &Vec<(String, Style)>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
A: Allocator,
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
sourceimpl<'a> Clone for DiagnosticBuilder<'a>
impl<'a> Clone for DiagnosticBuilder<'a>
sourcefn clone(&self) -> DiagnosticBuilder<'a>
fn clone(&self) -> DiagnosticBuilder<'a>
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more