Struct rustc_errors::DiagnosticBuilder[][src]

pub struct DiagnosticBuilder<'a>(Box<DiagnosticBuilderInner<'a>>);
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.

Implementations

Emit the diagnostic.

Emit the diagnostic unless delay is true, in which case the emission will be delayed as a bug.

See emit and delay_as_bug for details.

Stashes diagnostic for possible later improvement in a different, later stage of the compiler. The diagnostic can be accessed with the provided span and key through Handler::steal_diagnostic().

As with buffer, this is unless the handler has disabled such buffering.

Converts the builder to a Diagnostic for later emission, unless handler has disabled such buffering.

Buffers the diagnostic for later emission, unless handler has disabled such buffering.

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.

Appends a labeled span to the diagnostic.

Labels are used to convey additional context for the diagnostic’s primary span. They will be shown together with the original diagnostic’s span, not with spans added by span_note, span_help, etc. Therefore, if the primary span is not displayable (because the span is DUMMY_SP or the source code isn’t found), labels will not be displayed either.

Implementation-wise, the label span is pushed onto the MultiSpan that was created when the diagnostic was constructed. However, the label 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 Diagnostic::span_label() for more information.

See Diagnostic::tool_only_span_suggestion() for more information.

Allow attaching suggestions this diagnostic. If this is set to false, then any suggestions attached with the span_suggestion_* methods after this is set to false will be ignored.

Convenience function for internal use, clients should use one of the struct_* methods on Handler.

Convenience function for internal use, clients should use one of the struct_* methods on Handler.

Creates a new DiagnosticBuilder with an already constructed diagnostic.

Methods from Deref<Target = Diagnostic>

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.

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.

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.

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

Show a suggestion that has multiple parts to it. 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 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.

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.

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.

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

The resulting type after dereferencing.

Dereferences the value.

Mutably dereferences the value.

Destructor bomb - a DiagnosticBuilder must be either emitted or canceled or we emit a bug.

Executes the destructor for this type. Read more

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

Performs the conversion.

Performs the conversion.

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)

recently added

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 be different between compiler versions and platforms. 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: 8 bytes