pub struct DiagnosticBuilder<'a, G: EmissionGuarantee> {
inner: DiagnosticBuilderInner<'a>,
_marker: PhantomData<G>,
}
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
.
Fields
inner: DiagnosticBuilderInner<'a>
_marker: PhantomData<G>
Implementations
sourceimpl<'a> DiagnosticBuilder<'a, ErrorGuaranteed>
impl<'a> DiagnosticBuilder<'a, ErrorGuaranteed>
sourcepub(crate) fn new_guaranteeing_error<M: Into<DiagnosticMessage>, const L: Level>(
handler: &'a Handler,
message: M
) -> Selfwhere
(): IsError<L>,
pub(crate) fn new_guaranteeing_error<M: Into<DiagnosticMessage>, const L: Level>(
handler: &'a Handler,
message: M
) -> Selfwhere
(): IsError<L>,
Convenience function for internal use, clients should use one of the
struct_*
methods on Handler
.
sourcepub fn forget_guarantee(self) -> DiagnosticBuilder<'a, ()>
pub fn forget_guarantee(self) -> DiagnosticBuilder<'a, ()>
Discard the guarantee .emit()
would return, in favor of having the
type DiagnosticBuilder<'a, ()>
. This may be necessary whenever there
is a common codepath handling both errors and warnings.
sourceimpl<'a> DiagnosticBuilder<'a, ()>
impl<'a> DiagnosticBuilder<'a, ()>
sourcepub(crate) fn new<M: Into<DiagnosticMessage>>(
handler: &'a Handler,
level: Level,
message: M
) -> Self
pub(crate) fn new<M: Into<DiagnosticMessage>>(
handler: &'a Handler,
level: Level,
message: M
) -> Self
Convenience function for internal use, clients should use one of the
struct_*
methods on Handler
.
sourcepub(crate) fn new_diagnostic(
handler: &'a Handler,
diagnostic: Diagnostic
) -> Self
pub(crate) fn new_diagnostic(
handler: &'a Handler,
diagnostic: Diagnostic
) -> Self
Creates a new DiagnosticBuilder
with an already constructed
diagnostic.
sourceimpl<'a> DiagnosticBuilder<'a, !>
impl<'a> DiagnosticBuilder<'a, !>
sourcepub(crate) fn new_fatal(
handler: &'a Handler,
message: impl Into<DiagnosticMessage>
) -> Self
pub(crate) fn new_fatal(
handler: &'a Handler,
message: impl Into<DiagnosticMessage>
) -> Self
Convenience function for internal use, clients should use one of the
struct_*
methods on Handler
.
sourcepub(crate) fn new_diagnostic_fatal(
handler: &'a Handler,
diagnostic: Diagnostic
) -> Self
pub(crate) fn new_diagnostic_fatal(
handler: &'a Handler,
diagnostic: Diagnostic
) -> Self
Creates a new DiagnosticBuilder
with an already constructed
diagnostic.
sourceimpl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G>
impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G>
sourcepub fn emit_unless(&mut self, delay: bool) -> G
pub fn emit_unless(&mut self, delay: bool) -> G
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.
sourcepub fn cancel(self)
pub fn cancel(self)
Cancel the diagnostic (a structured diagnostic must either be emitted or cancelled or it will panic when dropped).
This method takes self
by-value to disallow calling .emit()
on it,
which may be expected to guarantee the emission of an error, either
at the time of the call, or through a prior .emit()
call.
sourcepub fn stash(self, span: Span, key: StashKey)
pub fn stash(self, span: Span, key: StashKey)
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.
sourcepub fn into_diagnostic(self) -> Option<(Diagnostic, &'a Handler)>
pub fn into_diagnostic(self) -> Option<(Diagnostic, &'a Handler)>
Converts the builder to a Diagnostic
for later emission,
unless handler has disabled such buffering, or .emit()
was called.
sourcepub fn buffer(self, buffered_diagnostics: &mut Vec<Diagnostic>)
pub fn buffer(self, buffered_diagnostics: &mut Vec<Diagnostic>)
Buffers the diagnostic for later emission, unless handler has disabled such buffering.
sourcepub fn delay_as_bug(&mut self)
pub fn delay_as_bug(&mut self)
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.
sourcepub fn downgrade_to_delayed_bug(&mut self) -> &mut Self
pub fn downgrade_to_delayed_bug(&mut self) -> &mut Self
sourcepub fn span_label(
&mut self,
span: Span,
label: impl Into<SubdiagnosticMessage>
) -> &mut Self
pub fn span_label(
&mut self,
span: Span,
label: impl Into<SubdiagnosticMessage>
) -> &mut Self
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.
See Diagnostic::span_label()
.
sourcepub fn span_labels(
&mut self,
spans: impl IntoIterator<Item = Span>,
label: impl AsRef<str>
) -> &mut Self
pub fn span_labels(
&mut self,
spans: impl IntoIterator<Item = Span>,
label: impl AsRef<str>
) -> &mut Self
Labels all the given spans with the provided label.
See Diagnostic::span_label()
for more information.
See Diagnostic::span_labels()
.
sourcepub fn note_expected_found(
&mut self,
expected_label: &dyn Display,
expected: DiagnosticStyledString,
found_label: &dyn Display,
found: DiagnosticStyledString
) -> &mut Self
pub fn note_expected_found(
&mut self,
expected_label: &dyn Display,
expected: DiagnosticStyledString,
found_label: &dyn Display,
found: DiagnosticStyledString
) -> &mut Self
sourcepub 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_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
sourcepub fn note_unsuccessful_coercion(
&mut self,
expected: DiagnosticStyledString,
found: DiagnosticStyledString
) -> &mut Self
pub fn note_unsuccessful_coercion(
&mut self,
expected: DiagnosticStyledString,
found: DiagnosticStyledString
) -> &mut Self
sourcepub fn note(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self
pub fn note(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self
See Diagnostic::note()
.
sourcepub fn note_once(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self
pub fn note_once(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self
sourcepub fn span_note(
&mut self,
sp: impl Into<MultiSpan>,
msg: impl Into<SubdiagnosticMessage>
) -> &mut Self
pub fn span_note(
&mut self,
sp: impl Into<MultiSpan>,
msg: impl Into<SubdiagnosticMessage>
) -> &mut Self
sourcepub fn span_note_once(
&mut self,
sp: impl Into<MultiSpan>,
msg: impl Into<SubdiagnosticMessage>
) -> &mut Self
pub fn span_note_once(
&mut self,
sp: impl Into<MultiSpan>,
msg: impl Into<SubdiagnosticMessage>
) -> &mut Self
sourcepub fn warn(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self
pub fn warn(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self
See Diagnostic::warn()
.
sourcepub fn span_warn(
&mut self,
sp: impl Into<MultiSpan>,
msg: impl Into<SubdiagnosticMessage>
) -> &mut Self
pub fn span_warn(
&mut self,
sp: impl Into<MultiSpan>,
msg: impl Into<SubdiagnosticMessage>
) -> &mut Self
sourcepub fn help(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self
pub fn help(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self
See Diagnostic::help()
.
sourcepub fn span_help(
&mut self,
sp: impl Into<MultiSpan>,
msg: impl Into<SubdiagnosticMessage>
) -> &mut Self
pub fn span_help(
&mut self,
sp: impl Into<MultiSpan>,
msg: impl Into<SubdiagnosticMessage>
) -> &mut Self
sourcepub fn help_use_latest_edition(&mut self) -> &mut Self
pub fn help_use_latest_edition(&mut self) -> &mut Self
sourcepub fn set_is_lint(&mut self) -> &mut Self
pub fn set_is_lint(&mut self) -> &mut Self
sourcepub fn disable_suggestions(&mut self) -> &mut Self
pub fn disable_suggestions(&mut self) -> &mut Self
sourcepub fn clear_suggestions(&mut self) -> &mut Self
pub fn clear_suggestions(&mut self) -> &mut Self
sourcepub fn multipart_suggestion(
&mut self,
msg: impl Into<SubdiagnosticMessage>,
suggestion: Vec<(Span, String)>,
applicability: Applicability
) -> &mut Self
pub fn multipart_suggestion(
&mut self,
msg: impl Into<SubdiagnosticMessage>,
suggestion: Vec<(Span, String)>,
applicability: Applicability
) -> &mut Self
sourcepub fn multipart_suggestion_verbose(
&mut self,
msg: impl Into<SubdiagnosticMessage>,
suggestion: Vec<(Span, String)>,
applicability: Applicability
) -> &mut Self
pub fn multipart_suggestion_verbose(
&mut self,
msg: impl Into<SubdiagnosticMessage>,
suggestion: Vec<(Span, String)>,
applicability: Applicability
) -> &mut Self
sourcepub fn tool_only_multipart_suggestion(
&mut self,
msg: impl Into<SubdiagnosticMessage>,
suggestion: Vec<(Span, String)>,
applicability: Applicability
) -> &mut Self
pub fn tool_only_multipart_suggestion(
&mut self,
msg: impl Into<SubdiagnosticMessage>,
suggestion: Vec<(Span, String)>,
applicability: Applicability
) -> &mut Self
sourcepub fn span_suggestion(
&mut self,
sp: Span,
msg: impl Into<SubdiagnosticMessage>,
suggestion: impl ToString,
applicability: Applicability
) -> &mut Self
pub fn span_suggestion(
&mut self,
sp: Span,
msg: impl Into<SubdiagnosticMessage>,
suggestion: impl ToString,
applicability: Applicability
) -> &mut Self
sourcepub fn span_suggestions(
&mut self,
sp: Span,
msg: impl Into<SubdiagnosticMessage>,
suggestions: impl Iterator<Item = String>,
applicability: Applicability
) -> &mut Self
pub fn span_suggestions(
&mut self,
sp: Span,
msg: impl Into<SubdiagnosticMessage>,
suggestions: impl Iterator<Item = String>,
applicability: Applicability
) -> &mut Self
sourcepub fn multipart_suggestions(
&mut self,
msg: impl Into<SubdiagnosticMessage>,
suggestions: impl Iterator<Item = Vec<(Span, String)>>,
applicability: Applicability
) -> &mut Self
pub fn multipart_suggestions(
&mut self,
msg: impl Into<SubdiagnosticMessage>,
suggestions: impl Iterator<Item = Vec<(Span, String)>>,
applicability: Applicability
) -> &mut Self
sourcepub fn span_suggestion_short(
&mut self,
sp: Span,
msg: impl Into<SubdiagnosticMessage>,
suggestion: impl ToString,
applicability: Applicability
) -> &mut Self
pub fn span_suggestion_short(
&mut self,
sp: Span,
msg: impl Into<SubdiagnosticMessage>,
suggestion: impl ToString,
applicability: Applicability
) -> &mut Self
sourcepub fn span_suggestion_verbose(
&mut self,
sp: Span,
msg: impl Into<SubdiagnosticMessage>,
suggestion: impl ToString,
applicability: Applicability
) -> &mut Self
pub fn span_suggestion_verbose(
&mut self,
sp: Span,
msg: impl Into<SubdiagnosticMessage>,
suggestion: impl ToString,
applicability: Applicability
) -> &mut Self
sourcepub fn tool_only_span_suggestion(
&mut self,
sp: Span,
msg: impl Into<SubdiagnosticMessage>,
suggestion: impl ToString,
applicability: Applicability
) -> &mut Self
pub fn tool_only_span_suggestion(
&mut self,
sp: Span,
msg: impl Into<SubdiagnosticMessage>,
suggestion: impl ToString,
applicability: Applicability
) -> &mut Self
sourcepub fn set_primary_message(
&mut self,
msg: impl Into<DiagnosticMessage>
) -> &mut Self
pub fn set_primary_message(
&mut self,
msg: impl Into<DiagnosticMessage>
) -> &mut Self
sourcepub fn code(&mut self, s: DiagnosticId) -> &mut Self
pub fn code(&mut self, s: DiagnosticId) -> &mut Self
See Diagnostic::code()
.
sourcepub fn set_arg(
&mut self,
name: impl Into<Cow<'static, str>>,
arg: impl IntoDiagnosticArg
) -> &mut Self
pub fn set_arg(
&mut self,
name: impl Into<Cow<'static, str>>,
arg: impl IntoDiagnosticArg
) -> &mut Self
sourcepub fn subdiagnostic(
&mut self,
subdiagnostic: impl AddSubdiagnostic
) -> &mut Self
pub fn subdiagnostic(
&mut self,
subdiagnostic: impl AddSubdiagnostic
) -> &mut Self
Methods from Deref<Target = Diagnostic>
pub fn level(&self) -> Level
pub fn is_error(&self) -> bool
pub fn update_unstable_expectation_id(
&mut self,
unstable_to_stable: &FxHashMap<LintExpectationId, LintExpectationId>
)
pub fn has_future_breakage(&self) -> bool
pub fn is_force_warn(&self) -> bool
sourcepub fn downgrade_to_delayed_bug(&mut self) -> &mut Self
pub fn downgrade_to_delayed_bug(&mut self) -> &mut Self
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.
sourcepub fn span_label(
&mut self,
span: Span,
label: impl Into<SubdiagnosticMessage>
) -> &mut Self
pub fn span_label(
&mut self,
span: Span,
label: impl Into<SubdiagnosticMessage>
) -> &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.
sourcepub fn span_labels(
&mut self,
spans: impl IntoIterator<Item = Span>,
label: impl AsRef<str>
) -> &mut Self
pub fn span_labels(
&mut self,
spans: impl IntoIterator<Item = Span>,
label: impl AsRef<str>
) -> &mut Self
Labels all the given spans with the provided label.
See Self::span_label()
for more information.
pub fn replace_span_with(&mut self, after: Span) -> &mut Self
pub fn note_expected_found(
&mut self,
expected_label: &dyn Display,
expected: DiagnosticStyledString,
found_label: &dyn Display,
found: DiagnosticStyledString
) -> &mut Self
pub 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: Symbol,
signature: String
) -> &mut Self
sourcepub fn note(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self
pub fn note(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self
Add a note attached to this diagnostic.
pub fn highlighted_note<M: Into<SubdiagnosticMessage>>(
&mut self,
msg: Vec<(M, Style)>
) -> &mut Self
sourcepub fn note_once(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self
pub fn note_once(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self
Prints the span with a note above it.
This is like Diagnostic::note()
, but it gets its own span.
sourcepub fn span_note<S: Into<MultiSpan>>(
&mut self,
sp: S,
msg: impl Into<SubdiagnosticMessage>
) -> &mut Self
pub fn span_note<S: Into<MultiSpan>>(
&mut self,
sp: S,
msg: impl Into<SubdiagnosticMessage>
) -> &mut Self
Prints the span with a note above it.
This is like Diagnostic::note()
, but it gets its own span.
sourcepub fn span_note_once<S: Into<MultiSpan>>(
&mut self,
sp: S,
msg: impl Into<SubdiagnosticMessage>
) -> &mut Self
pub fn span_note_once<S: Into<MultiSpan>>(
&mut self,
sp: S,
msg: impl Into<SubdiagnosticMessage>
) -> &mut Self
Prints the span with a note above it.
This is like Diagnostic::note()
, but it gets its own span.
sourcepub fn warn(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self
pub fn warn(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self
Add a warning attached to this diagnostic.
sourcepub fn span_warn<S: Into<MultiSpan>>(
&mut self,
sp: S,
msg: impl Into<SubdiagnosticMessage>
) -> &mut Self
pub fn span_warn<S: Into<MultiSpan>>(
&mut self,
sp: S,
msg: impl Into<SubdiagnosticMessage>
) -> &mut Self
Prints the span with a warning above it.
This is like Diagnostic::warn()
, but it gets its own span.
sourcepub fn help(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self
pub fn help(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self
Add a help message attached to this diagnostic.
sourcepub fn highlighted_help(&mut self, msg: Vec<(String, Style)>) -> &mut Self
pub fn highlighted_help(&mut self, msg: Vec<(String, Style)>) -> &mut Self
Add a help message attached to this diagnostic with a customizable highlighted message.
sourcepub fn span_help<S: Into<MultiSpan>>(
&mut self,
sp: S,
msg: impl Into<SubdiagnosticMessage>
) -> &mut Self
pub fn span_help<S: Into<MultiSpan>>(
&mut self,
sp: S,
msg: impl Into<SubdiagnosticMessage>
) -> &mut Self
Prints the span with some help above it.
This is like Diagnostic::help()
, but it gets its own span.
sourcepub fn help_use_latest_edition(&mut self) -> &mut Self
pub fn help_use_latest_edition(&mut self) -> &mut Self
Help the user upgrade to the latest edition.
This is factored out to make sure it does the right thing with Cargo.toml
.
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.
sourcepub fn clear_suggestions(&mut self) -> &mut Self
pub fn clear_suggestions(&mut self) -> &mut Self
Clear any existing suggestions.
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: impl Into<SubdiagnosticMessage>,
suggestion: Vec<(Span, String)>,
applicability: Applicability
) -> &mut Self
pub fn multipart_suggestion(
&mut self,
msg: impl Into<SubdiagnosticMessage>,
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: impl Into<SubdiagnosticMessage>,
suggestion: Vec<(Span, String)>,
applicability: Applicability
) -> &mut Self
pub fn multipart_suggestion_verbose(
&mut self,
msg: impl Into<SubdiagnosticMessage>,
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: impl Into<SubdiagnosticMessage>,
suggestion: Vec<(Span, String)>,
applicability: Applicability,
style: SuggestionStyle
) -> &mut Self
pub fn multipart_suggestion_with_style(
&mut self,
msg: impl Into<SubdiagnosticMessage>,
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: impl Into<SubdiagnosticMessage>,
suggestion: Vec<(Span, String)>,
applicability: Applicability
) -> &mut Self
pub fn tool_only_multipart_suggestion(
&mut self,
msg: impl Into<SubdiagnosticMessage>,
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: impl Into<SubdiagnosticMessage>,
suggestion: impl ToString,
applicability: Applicability
) -> &mut Self
pub fn span_suggestion(
&mut self,
sp: Span,
msg: impl Into<SubdiagnosticMessage>,
suggestion: impl ToString,
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: impl Into<SubdiagnosticMessage>,
suggestion: impl ToString,
applicability: Applicability,
style: SuggestionStyle
) -> &mut Self
pub fn span_suggestion_with_style(
&mut self,
sp: Span,
msg: impl Into<SubdiagnosticMessage>,
suggestion: impl ToString,
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: impl Into<SubdiagnosticMessage>,
suggestion: impl ToString,
applicability: Applicability
) -> &mut Self
pub fn span_suggestion_verbose(
&mut self,
sp: Span,
msg: impl Into<SubdiagnosticMessage>,
suggestion: impl ToString,
applicability: Applicability
) -> &mut Self
Always show the suggested change.
sourcepub fn span_suggestions(
&mut self,
sp: Span,
msg: impl Into<SubdiagnosticMessage>,
suggestions: impl Iterator<Item = String>,
applicability: Applicability
) -> &mut Self
pub fn span_suggestions(
&mut self,
sp: Span,
msg: impl Into<SubdiagnosticMessage>,
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: impl Into<SubdiagnosticMessage>,
suggestions: impl Iterator<Item = Vec<(Span, String)>>,
applicability: Applicability
) -> &mut Self
pub fn multipart_suggestions(
&mut self,
msg: impl Into<SubdiagnosticMessage>,
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: impl Into<SubdiagnosticMessage>,
suggestion: impl ToString,
applicability: Applicability
) -> &mut Self
pub fn span_suggestion_short(
&mut self,
sp: Span,
msg: impl Into<SubdiagnosticMessage>,
suggestion: impl ToString,
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: impl Into<SubdiagnosticMessage>,
suggestion: impl ToString,
applicability: Applicability
) -> &mut Self
pub fn tool_only_span_suggestion(
&mut self,
sp: Span,
msg: impl Into<SubdiagnosticMessage>,
suggestion: impl ToString,
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 subdiagnostic(
&mut self,
subdiagnostic: impl AddSubdiagnostic
) -> &mut Self
pub fn subdiagnostic(
&mut self,
subdiagnostic: impl AddSubdiagnostic
) -> &mut Self
Add a subdiagnostic from a type that implements SessionSubdiagnostic
- see
rustc_macros::SessionSubdiagnostic.
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 fn set_primary_message(
&mut self,
msg: impl Into<DiagnosticMessage>
) -> &mut Self
pub fn args(&self) -> &[DiagnosticArg<'static>]
pub fn set_arg(
&mut self,
name: impl Into<Cow<'static, str>>,
arg: impl IntoDiagnosticArg
) -> &mut Self
pub fn styled_message(&self) -> &[(DiagnosticMessage, Style)]
sourcefn subdiagnostic_message_to_diagnostic_message(
&self,
attr: impl Into<SubdiagnosticMessage>
) -> DiagnosticMessage
fn subdiagnostic_message_to_diagnostic_message(
&self,
attr: impl Into<SubdiagnosticMessage>
) -> DiagnosticMessage
Helper function that takes a SubdiagnosticMessage
and returns a DiagnosticMessage
by
combining it with the primary message of the diagnostic (if translatable, otherwise it just
passes the user’s string along).
sourcepub fn sub(
&mut self,
level: Level,
message: impl Into<SubdiagnosticMessage>,
span: MultiSpan,
render_span: Option<MultiSpan>
)
pub fn sub(
&mut self,
level: Level,
message: impl Into<SubdiagnosticMessage>,
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<M: Into<SubdiagnosticMessage>>(
&mut self,
level: Level,
message: Vec<(M, Style)>,
span: MultiSpan,
render_span: Option<MultiSpan>
)
fn sub_with_highlights<M: Into<SubdiagnosticMessage>>(
&mut self,
level: Level,
message: Vec<(M, 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, &[(DiagnosticMessage, Style)], &Option<DiagnosticId>, &MultiSpan, &Result<Vec<CodeSuggestion>, SuggestionsDisabled>, Option<&[SubDiagnostic]>)
fn keys(
&self
) -> (&Level, &[(DiagnosticMessage, Style)], &Option<DiagnosticId>, &MultiSpan, &Result<Vec<CodeSuggestion>, SuggestionsDisabled>, Option<&[SubDiagnostic]>)
Fields used for Hash, and PartialEq trait
Trait Implementations
sourceimpl<'a, G: Clone + EmissionGuarantee> Clone for DiagnosticBuilder<'a, G>
impl<'a, G: Clone + EmissionGuarantee> Clone for DiagnosticBuilder<'a, G>
sourcefn clone(&self) -> DiagnosticBuilder<'a, G>
fn clone(&self) -> DiagnosticBuilder<'a, G>
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresourceimpl<G: EmissionGuarantee> Debug for DiagnosticBuilder<'_, G>
impl<G: EmissionGuarantee> Debug for DiagnosticBuilder<'_, G>
sourceimpl<G: EmissionGuarantee> Deref for DiagnosticBuilder<'_, G>
impl<G: EmissionGuarantee> Deref for DiagnosticBuilder<'_, G>
type Target = Diagnostic
type Target = Diagnostic
sourcefn deref(&self) -> &Diagnostic
fn deref(&self) -> &Diagnostic
sourceimpl<G: EmissionGuarantee> DerefMut for DiagnosticBuilder<'_, G>
impl<G: EmissionGuarantee> DerefMut for DiagnosticBuilder<'_, G>
sourcefn deref_mut(&mut self) -> &mut Diagnostic
fn deref_mut(&mut self) -> &mut Diagnostic
Auto Trait Implementations
impl<'a, G> !RefUnwindSafe for DiagnosticBuilder<'a, G>
impl<'a, G> !Send for DiagnosticBuilder<'a, G>
impl<'a, G> !Sync for DiagnosticBuilder<'a, G>
impl<'a, G> Unpin for DiagnosticBuilder<'a, G>where
G: Unpin,
impl<'a, G> !UnwindSafe for DiagnosticBuilder<'a, G>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
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: 16 bytes