#[must_use]
pub struct DiagnosticBuilder<'a> {
pub handler: &'a Handler,
// some fields omitted
}
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
.
handler: &'a Handler
Buffers the diagnostic for later emission, unless handler
has disabled such buffering.
Convenience function for internal use, clients should use one of the
span_* methods instead.
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.
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.
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.
Cancel the diagnostic (a structured diagnostic must either be emitted or
canceled or it will panic when dropped).
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.
Deprecated:
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.
Deprecated:
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.
Deprecated:
Use multipart_suggestion_with_applicability
Deprecated:
Use span_suggestions_with_applicability
Prints out a message with multiple suggested edits of the code.
This is a suggestion that may contain mistakes or fillers and should
be read and understood by a human.
Used by a lint. Copies over all details but the "main
message".
Convenience function for internal use, clients should use one of the
public methods above.
Performs copy-assignment from source
. Read more
Destructor bomb - a DiagnosticBuilder
must be either emitted or canceled
or we emit a bug.
Executes the destructor for this type. Read more
Formats the value using the given formatter. Read more
The resulting type after dereferencing.
Mutably dereferences the value.
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
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Create an error for a missing method specialization. Defaults to panicking with type, trait & method names. S
is the encoder/decoder state type, T
is the type being encoded/decoded, and the arguments are the names of the trait and method that should've been overridden. Read more