pub struct Diagnostic {
    pub(crate) level: Level,
    pub message: Vec<(DiagnosticMessage, Style)>,
    pub code: Option<DiagnosticId>,
    pub span: MultiSpan,
    pub children: Vec<SubDiagnostic>,
    pub suggestions: Result<Vec<CodeSuggestion>, SuggestionsDisabled>,
    args: Vec<DiagnosticArg<'static>>,
    pub sort_span: Span,
    pub is_lint: bool,
}

Fields

level: Levelmessage: Vec<(DiagnosticMessage, Style)>code: Option<DiagnosticId>span: MultiSpanchildren: Vec<SubDiagnostic>suggestions: Result<Vec<CodeSuggestion>, SuggestionsDisabled>args: Vec<DiagnosticArg<'static>>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.

is_lint: bool

If diagnostic is from Lint, custom hash function ignores notes otherwise hash is based on the all the fields

Implementations

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.

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.

Labels all the given spans with the provided label. See Self::span_label() for more information.

Add a note attached to this diagnostic.

Prints the span with a note above it. This is like Diagnostic::note(), but it gets its own span.

Prints the span with a note above it. This is like Diagnostic::note(), but it gets its own span.

Prints the span with a note above it. This is like Diagnostic::note(), but it gets its own span.

Add a warning attached to this diagnostic.

Prints the span with a warning above it. This is like Diagnostic::warn(), but it gets its own span.

Add a help message attached to this diagnostic.

Add a help message attached to this diagnostic with a customizable highlighted message.

Prints the span with some help above it. This is like Diagnostic::help(), but it gets its own span.

Help the user upgrade to the latest edition. This is factored out to make sure it does the right thing with Cargo.toml.

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.

Helper for pushing to self.suggestions, if available (not disable).

Show a suggestion that has multiple parts to it. In other words, multiple changes need to be applied as part of this suggestion.

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.

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.

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.

Always show the suggested change.

Prints out a message with multiple suggested edits of the code. See also Diagnostic::span_suggestion().

Prints out a message with multiple suggested edits of the code. See also Diagnostic::span_suggestion().

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.

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.

Add a subdiagnostic from a type that implements SessionSubdiagnostic - see rustc_macros::SessionSubdiagnostic.

Convenience function for internal use, clients should use one of the public methods above.

Used by proc_macro_server for implementing server::Diagnostic.

Convenience function for internal use, clients should use one of the public methods above.

Fields used for Hash, and PartialEq trait

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

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: 208 bytes