Struct rustc_ap_rustc_errors::Diagnostic [−][src]
pub struct Diagnostic { pub level: Level, pub message: Vec<(String, Style)>, pub code: Option<DiagnosticId>, pub span: MultiSpan, pub children: Vec<SubDiagnostic>, pub suggestions: Vec<CodeSuggestion>, pub sort_span: Span, }
Fields
level: Level
message: Vec<(String, Style)>
code: Option<DiagnosticId>
span: MultiSpan
children: Vec<SubDiagnostic>
suggestions: Vec<CodeSuggestion>
sort_span: Span
This is not used for highlighting or rendering any error message. Rather, it can be used
as a sort key to sort a buffer of diagnostics. By default, it is the primary span of
span
if there is one. Otherwise, it is DUMMY_SP
.
Implementations
Cancel the diagnostic (a structured diagnostic must either be emitted or canceled or it will panic when dropped).
Check if this diagnostic was cancelled.
Adds 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. That means it will be shown together with the original
span/label, not a span added by one of the span_{note,warn,help,suggestions}
methods.
This span is not considered a “primary span”; only
the Span
supplied when creating the diagnostic is primary.
pub fn note_expected_found_extra(
&mut self,
expected_label: &dyn Display,
expected: DiagnosticStyledString,
found_label: &dyn Display,
found: DiagnosticStyledString,
expected_extra: &dyn Display,
found_extra: &dyn Display
) -> &mut Self
pub fn multipart_suggestion(
&mut self,
msg: &str,
suggestion: Vec<(Span, String)>,
applicability: Applicability
) -> &mut Self
pub fn multipart_suggestion(
&mut self,
msg: &str,
suggestion: Vec<(Span, String)>,
applicability: Applicability
) -> &mut Self
Show a suggestion that has multiple parts to it. In other words, multiple changes need to be applied as part of this suggestion.
pub fn multipart_suggestion_with_style(
&mut self,
msg: &str,
suggestion: Vec<(Span, String)>,
applicability: Applicability,
style: SuggestionStyle
) -> &mut Self
pub fn multipart_suggestion_with_style(
&mut self,
msg: &str,
suggestion: Vec<(Span, String)>,
applicability: Applicability,
style: SuggestionStyle
) -> &mut Self
Diagnostic::multipart_suggestion()
but you can set the SuggestionStyle
.
pub fn tool_only_multipart_suggestion(
&mut self,
msg: &str,
suggestion: Vec<(Span, String)>,
applicability: Applicability
) -> &mut Self
pub fn tool_only_multipart_suggestion(
&mut self,
msg: &str,
suggestion: Vec<(Span, String)>,
applicability: Applicability
) -> &mut Self
Prints out a message with for a multipart suggestion without showing the suggested code.
This is intended to be used for suggestions that are obvious in what the changes need to be from the message, showing the span label inline would be visually unpleasant (marginally overlapping spans or multiline spans) and showing the snippet window wouldn’t improve understandability.
pub fn span_suggestion(
&mut self,
sp: Span,
msg: &str,
suggestion: String,
applicability: Applicability
) -> &mut Self
pub fn span_suggestion(
&mut self,
sp: Span,
msg: &str,
suggestion: String,
applicability: Applicability
) -> &mut Self
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:
try adding parentheses: `(tup.0).1`
The message
- should not end in any punctuation (a
:
is added automatically) - should not be a question (avoid language like “did you mean”)
- should not contain any phrases like “the following”, “as shown”, etc.
- 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 span_suggestion_with_style(
&mut self,
sp: Span,
msg: &str,
suggestion: String,
applicability: Applicability,
style: SuggestionStyle
) -> &mut Self
pub fn span_suggestion_with_style(
&mut self,
sp: Span,
msg: &str,
suggestion: String,
applicability: Applicability,
style: SuggestionStyle
) -> &mut Self
Diagnostic::span_suggestion()
but you can set the SuggestionStyle
.
pub fn span_suggestion_verbose(
&mut self,
sp: Span,
msg: &str,
suggestion: String,
applicability: Applicability
) -> &mut Self
pub fn span_suggestion_verbose(
&mut self,
sp: Span,
msg: &str,
suggestion: String,
applicability: Applicability
) -> &mut Self
Always show the suggested change.
pub fn span_suggestions(
&mut self,
sp: Span,
msg: &str,
suggestions: impl Iterator<Item = String>,
applicability: Applicability
) -> &mut Self
pub fn span_suggestions(
&mut self,
sp: Span,
msg: &str,
suggestions: impl Iterator<Item = String>,
applicability: Applicability
) -> &mut Self
Prints out a message with multiple suggested edits of the code.
See also Diagnostic::span_suggestion()
.
pub fn span_suggestion_short(
&mut self,
sp: Span,
msg: &str,
suggestion: String,
applicability: Applicability
) -> &mut Self
pub fn span_suggestion_short(
&mut self,
sp: Span,
msg: &str,
suggestion: String,
applicability: Applicability
) -> &mut Self
Prints out a message with a suggested edit of the code. If the suggestion is presented inline, it will only show the message and not the suggestion.
See CodeSuggestion
for more information.
Prints out a message for a suggestion without showing the suggested code.
This is intended to be used for suggestions that are obvious in what the changes need to be from the message, showing the span label inline would be visually unpleasant (marginally overlapping spans or multiline spans) and showing the snippet window wouldn’t improve understandability.
pub fn tool_only_span_suggestion(
&mut self,
sp: Span,
msg: &str,
suggestion: String,
applicability: Applicability
) -> &mut Self
pub fn tool_only_span_suggestion(
&mut self,
sp: Span,
msg: &str,
suggestion: String,
applicability: Applicability
) -> &mut Self
Adds a suggestion to the JSON output that will not be shown in the CLI.
This is intended to be used for suggestions that are very obvious in what the changes need to be from the message, but we still want other tools to be able to apply them.
pub fn tool_only_suggestion_with_metadata(
&mut self,
msg: &str,
applicability: Applicability,
tool_metadata: Json
)
pub fn tool_only_suggestion_with_metadata(
&mut self,
msg: &str,
applicability: Applicability,
tool_metadata: Json
)
Adds a suggestion intended only for a tool. The intent is that the metadata encodes the suggestion in a tool-specific way, as it may not even directly involve Rust code.
Trait Implementations
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
This method tests for !=
.
Auto Trait Implementations
impl RefUnwindSafe for Diagnostic
impl !Send for Diagnostic
impl !Sync for Diagnostic
impl Unpin for Diagnostic
impl UnwindSafe for Diagnostic
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
type Output = T
type Output = T
Should always be Self
pub fn vzip(self) -> V