Struct rustc_errors::Diagnostic
source · [−]pub struct Diagnostic {
pub level: Level,
pub message: Vec<(String, Style)>,
pub code: Option<DiagnosticId>,
pub span: MultiSpan,
pub children: Vec<SubDiagnostic>,
pub suggestions: Result<Vec<CodeSuggestion>, SuggestionsDisabled>,
pub sort_span: Span,
pub is_lint: bool,
}Fields
level: Levelmessage: Vec<(String, Style)>code: Option<DiagnosticId>span: MultiSpanchildren: Vec<SubDiagnostic>suggestions: Result<Vec<CodeSuggestion>, SuggestionsDisabled>sort_span: SpanThis 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.
is_lint: boolIf diagnostic is from Lint, custom hash function ignores notes otherwise hash is based on the all the fields
Implementations
sourceimpl Diagnostic
impl Diagnostic
pub fn new(level: Level, message: &str) -> Self
pub fn new_with_code(
level: Level,
code: Option<DiagnosticId>,
message: &str
) -> Self
pub fn is_error(&self) -> bool
pub fn has_future_breakage(&self) -> bool
pub fn is_force_warn(&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).
sourcepub fn cancelled(&self) -> bool
pub fn cancelled(&self) -> bool
Check if this diagnostic was cancelled.
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
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 replace_span_with(&mut self, after: Span) -> &mut Self
pub(crate) fn note_expected_found(
&mut self,
expected_label: &dyn Display,
expected: DiagnosticStyledString,
found_label: &dyn Display,
found: DiagnosticStyledString
) -> &mut Self
pub(crate) fn note_unsuccessful_coercion(
&mut self,
expected: DiagnosticStyledString,
found: DiagnosticStyledString
) -> &mut Self
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 note_trait_signature(
&mut self,
name: String,
signature: String
) -> &mut Self
pub fn highlighted_note(&mut self, msg: Vec<(String, Style)>) -> &mut Self
sourcepub(crate) fn span_note<S: Into<MultiSpan>>(
&mut self,
sp: S,
msg: &str
) -> &mut Self
pub(crate) fn span_note<S: Into<MultiSpan>>(
&mut self,
sp: S,
msg: &str
) -> &mut Self
Prints the span with a note above it.
This is like Diagnostic::note(), but it gets its own span.
sourcepub(crate) fn warn(&mut self, msg: &str) -> &mut Self
pub(crate) fn warn(&mut self, msg: &str) -> &mut Self
Add a warning attached to this diagnostic.
sourcepub(crate) fn span_warn<S: Into<MultiSpan>>(
&mut self,
sp: S,
msg: &str
) -> &mut Self
pub(crate) fn span_warn<S: Into<MultiSpan>>(
&mut self,
sp: S,
msg: &str
) -> &mut Self
Prints the span with a warning above it.
This is like Diagnostic::warn(), but it gets its own span.
sourcepub(crate) fn help(&mut self, msg: &str) -> &mut Self
pub(crate) fn help(&mut self, msg: &str) -> &mut Self
Add a help message attached to this diagnostic.
sourcepub(crate) fn span_help<S: Into<MultiSpan>>(
&mut self,
sp: S,
msg: &str
) -> &mut Self
pub(crate) fn span_help<S: Into<MultiSpan>>(
&mut self,
sp: S,
msg: &str
) -> &mut Self
Prints the span with some help above it.
This is like Diagnostic::help(), but it gets its own span.
sourcepub fn disable_suggestions(&mut self) -> &mut Self
pub fn disable_suggestions(&mut self) -> &mut Self
Disallow attaching suggestions this diagnostic.
Any suggestions attached e.g. with the span_suggestion_* methods
(before and after the call to disable_suggestions) will be ignored.
sourcefn push_suggestion(&mut self, suggestion: CodeSuggestion)
fn push_suggestion(&mut self, suggestion: CodeSuggestion)
Helper for pushing to self.suggestions, if available (not disable).
sourcepub 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.
sourcepub fn multipart_suggestion_verbose(
&mut self,
msg: &str,
suggestion: Vec<(Span, String)>,
applicability: Applicability
) -> &mut Self
pub fn multipart_suggestion_verbose(
&mut self,
msg: &str,
suggestion: Vec<(Span, String)>,
applicability: Applicability
) -> &mut Self
Show a suggestion that has multiple parts to it, always as it’s own subdiagnostic. In other words, multiple changes need to be applied as part of this suggestion.
sourcepub 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.
sourcepub 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.
sourcepub 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.
sourcepub 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.
sourcepub 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.
sourcepub 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().
sourcepub fn multipart_suggestions(
&mut self,
msg: &str,
suggestions: impl Iterator<Item = Vec<(Span, String)>>,
applicability: Applicability
) -> &mut Self
pub fn multipart_suggestions(
&mut self,
msg: &str,
suggestions: impl Iterator<Item = Vec<(Span, String)>>,
applicability: Applicability
) -> &mut Self
Prints out a message with multiple suggested edits of the code.
See also Diagnostic::span_suggestion().
sourcepub 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.
sourcepub 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.
sourcepub 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.
pub fn set_span<S: Into<MultiSpan>>(&mut self, sp: S) -> &mut Self
pub fn set_is_lint(&mut self) -> &mut Self
pub fn code(&mut self, s: DiagnosticId) -> &mut Self
pub fn clear_code(&mut self) -> &mut Self
pub fn get_code(&self) -> Option<DiagnosticId>
pub(crate) fn set_primary_message<M: Into<String>>(
&mut self,
msg: M
) -> &mut Self
pub fn message(&self) -> String
pub fn styled_message(&self) -> &Vec<(String, Style)>
sourcepub fn sub(
&mut self,
level: Level,
message: &str,
span: MultiSpan,
render_span: Option<MultiSpan>
)
pub fn sub(
&mut self,
level: Level,
message: &str,
span: MultiSpan,
render_span: Option<MultiSpan>
)
Convenience function for internal use, clients should use one of the public methods above.
Used by proc_macro_server for implementing server::Diagnostic.
sourcefn sub_with_highlights(
&mut self,
level: Level,
message: Vec<(String, Style)>,
span: MultiSpan,
render_span: Option<MultiSpan>
)
fn sub_with_highlights(
&mut self,
level: Level,
message: Vec<(String, Style)>,
span: MultiSpan,
render_span: Option<MultiSpan>
)
Convenience function for internal use, clients should use one of the public methods above.
sourcefn keys(
&self
) -> (&Level, &Vec<(String, Style)>, &Option<DiagnosticId>, &MultiSpan, &Result<Vec<CodeSuggestion>, SuggestionsDisabled>, Option<&Vec<SubDiagnostic>>)
fn keys(
&self
) -> (&Level, &Vec<(String, Style)>, &Option<DiagnosticId>, &MultiSpan, &Result<Vec<CodeSuggestion>, SuggestionsDisabled>, Option<&Vec<SubDiagnostic>>)
Fields used for Hash, and PartialEq trait
Trait Implementations
sourceimpl Clone for Diagnostic
impl Clone for Diagnostic
sourcefn clone(&self) -> Diagnostic
fn clone(&self) -> Diagnostic
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source. Read more
sourceimpl Debug for Diagnostic
impl Debug for Diagnostic
sourceimpl<__E: Encoder> Encodable<__E> for Diagnostic
impl<__E: Encoder> Encodable<__E> for Diagnostic
sourceimpl Hash for Diagnostic
impl Hash for Diagnostic
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more
Layout
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference’s “Type Layout” chapter for details on type layout guarantees.
Size: 168 bytes