pub struct DiagBuilder<'a, G>where
G: EmissionGuarantee,{ /* private fields */ }Expand description
Used for emitting structured error messages and other diagnostic information.
Note: Incorrect usage of this type results in a panic when dropped. This is to ensure that all errors are either emitted or cancelled.
Implementations§
Source§impl<'a, G> DiagBuilder<'a, G>where
G: EmissionGuarantee,
impl<'a, G> DiagBuilder<'a, G>where
G: EmissionGuarantee,
Sourcepub fn new<M>(dcx: &'a DiagCtxt, level: Level, msg: M) -> DiagBuilder<'a, G>
pub fn new<M>(dcx: &'a DiagCtxt, level: Level, msg: M) -> DiagBuilder<'a, G>
Creates a new DiagBuilder.
Sourcepub fn emit(self) -> <G as EmissionGuarantee>::EmitResult
pub fn emit(self) -> <G as EmissionGuarantee>::EmitResult
Emits the diagnostic.
Source§impl<G> DiagBuilder<'_, G>where
G: EmissionGuarantee,
Forwarded methods to Diag.
impl<G> DiagBuilder<'_, G>where
G: EmissionGuarantee,
Forwarded methods to Diag.
Sourcepub fn span(self, span: impl Into<MultiSpan>) -> DiagBuilder<'_, G>
pub fn span(self, span: impl Into<MultiSpan>) -> DiagBuilder<'_, G>
See Diag::span().
Sourcepub fn code(self, code: impl Into<DiagId>) -> DiagBuilder<'_, G>
pub fn code(self, code: impl Into<DiagId>) -> DiagBuilder<'_, G>
See Diag::code().
Sourcepub fn span_label(
self,
span: Span,
label: impl Into<DiagMsg>,
) -> DiagBuilder<'_, G>
pub fn span_label( self, span: Span, label: impl Into<DiagMsg>, ) -> DiagBuilder<'_, G>
See Diag::span_label().
Sourcepub fn span_labels(
self,
spans: impl IntoIterator<Item = Span>,
label: impl Into<DiagMsg>,
) -> DiagBuilder<'_, G>
pub fn span_labels( self, spans: impl IntoIterator<Item = Span>, label: impl Into<DiagMsg>, ) -> DiagBuilder<'_, G>
See Diag::span_labels().
Sourcepub fn warn(self, msg: impl Into<DiagMsg>) -> DiagBuilder<'_, G>
pub fn warn(self, msg: impl Into<DiagMsg>) -> DiagBuilder<'_, G>
See Diag::warn().
Sourcepub fn span_warn(
self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagMsg>,
) -> DiagBuilder<'_, G>
pub fn span_warn( self, span: impl Into<MultiSpan>, msg: impl Into<DiagMsg>, ) -> DiagBuilder<'_, G>
See Diag::span_warn().
Sourcepub fn note(self, msg: impl Into<DiagMsg>) -> DiagBuilder<'_, G>
pub fn note(self, msg: impl Into<DiagMsg>) -> DiagBuilder<'_, G>
See Diag::note().
Sourcepub fn span_note(
self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagMsg>,
) -> DiagBuilder<'_, G>
pub fn span_note( self, span: impl Into<MultiSpan>, msg: impl Into<DiagMsg>, ) -> DiagBuilder<'_, G>
See Diag::span_note().
Sourcepub fn highlighted_note(
self,
messages: Vec<(impl Into<DiagMsg>, Style)>,
) -> DiagBuilder<'_, G>
pub fn highlighted_note( self, messages: Vec<(impl Into<DiagMsg>, Style)>, ) -> DiagBuilder<'_, G>
Sourcepub fn note_once(self, msg: impl Into<DiagMsg>) -> DiagBuilder<'_, G>
pub fn note_once(self, msg: impl Into<DiagMsg>) -> DiagBuilder<'_, G>
See Diag::note_once().
Sourcepub fn span_note_once(
self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagMsg>,
) -> DiagBuilder<'_, G>
pub fn span_note_once( self, span: impl Into<MultiSpan>, msg: impl Into<DiagMsg>, ) -> DiagBuilder<'_, G>
Sourcepub fn help(self, msg: impl Into<DiagMsg>) -> DiagBuilder<'_, G>
pub fn help(self, msg: impl Into<DiagMsg>) -> DiagBuilder<'_, G>
See Diag::help().
Sourcepub fn help_once(self, msg: impl Into<DiagMsg>) -> DiagBuilder<'_, G>
pub fn help_once(self, msg: impl Into<DiagMsg>) -> DiagBuilder<'_, G>
See Diag::help_once().
Sourcepub fn highlighted_help(
self,
messages: Vec<(impl Into<DiagMsg>, Style)>,
) -> DiagBuilder<'_, G>
pub fn highlighted_help( self, messages: Vec<(impl Into<DiagMsg>, Style)>, ) -> DiagBuilder<'_, G>
Sourcepub fn span_help(
self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagMsg>,
) -> DiagBuilder<'_, G>
pub fn span_help( self, span: impl Into<MultiSpan>, msg: impl Into<DiagMsg>, ) -> DiagBuilder<'_, G>
See Diag::span_help().
Sourcepub fn span_suggestion(
self,
span: Span,
msg: impl Into<DiagMsg>,
suggestion: impl Into<DiagMsg>,
applicability: Applicability,
) -> DiagBuilder<'_, G>
pub fn span_suggestion( self, span: Span, msg: impl Into<DiagMsg>, suggestion: impl Into<DiagMsg>, applicability: Applicability, ) -> DiagBuilder<'_, G>
Sourcepub fn span_suggestion_with_style(
self,
span: Span,
msg: impl Into<DiagMsg>,
suggestion: impl Into<DiagMsg>,
applicability: Applicability,
style: SuggestionStyle,
) -> DiagBuilder<'_, G>
pub fn span_suggestion_with_style( self, span: Span, msg: impl Into<DiagMsg>, suggestion: impl Into<DiagMsg>, applicability: Applicability, style: SuggestionStyle, ) -> DiagBuilder<'_, G>
Sourcepub fn multipart_suggestion(
self,
msg: impl Into<DiagMsg>,
substitutions: Vec<(Span, DiagMsg)>,
applicability: Applicability,
) -> DiagBuilder<'_, G>
pub fn multipart_suggestion( self, msg: impl Into<DiagMsg>, substitutions: Vec<(Span, DiagMsg)>, applicability: Applicability, ) -> DiagBuilder<'_, G>
Sourcepub fn multipart_suggestion_with_style(
self,
msg: impl Into<DiagMsg>,
substitutions: Vec<(Span, DiagMsg)>,
applicability: Applicability,
style: SuggestionStyle,
) -> DiagBuilder<'_, G>
pub fn multipart_suggestion_with_style( self, msg: impl Into<DiagMsg>, substitutions: Vec<(Span, DiagMsg)>, applicability: Applicability, style: SuggestionStyle, ) -> DiagBuilder<'_, G>
Methods from Deref<Target = Diag>§
Sourcepub fn label_with_style(&self, supports_color: bool) -> Cow<'_, str>
pub fn label_with_style(&self, supports_color: bool) -> Cow<'_, str>
Formats the diagnostic messages into a single string with ANSI color codes if applicable.
Sourcepub fn span(&mut self, span: impl Into<MultiSpan>) -> &mut Diag
pub fn span(&mut self, span: impl Into<MultiSpan>) -> &mut Diag
Sets the span of this diagnostic.
Sourcepub fn span_label(&mut self, span: Span, label: impl Into<DiagMsg>) -> &mut Diag
pub fn span_label(&mut self, span: Span, label: impl Into<DiagMsg>) -> &mut Diag
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 Into<DiagMsg>,
) -> &mut Diag
pub fn span_labels( &mut self, spans: impl IntoIterator<Item = Span>, label: impl Into<DiagMsg>, ) -> &mut Diag
Labels all the given spans with the provided label.
See Self::span_label() for more information.
Sourcepub fn warn(&mut self, msg: impl Into<DiagMsg>) -> &mut Diag
pub fn warn(&mut self, msg: impl Into<DiagMsg>) -> &mut Diag
Add a warning attached to this diagnostic.
Sourcepub fn span_warn(
&mut self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagMsg>,
) -> &mut Diag
pub fn span_warn( &mut self, span: impl Into<MultiSpan>, msg: impl Into<DiagMsg>, ) -> &mut Diag
Prints the span with a warning above it.
This is like Diag::warn(), but it gets its own span.
Sourcepub fn span_note(
&mut self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagMsg>,
) -> &mut Diag
pub fn span_note( &mut self, span: impl Into<MultiSpan>, msg: impl Into<DiagMsg>, ) -> &mut Diag
Prints the span with a note above it.
This is like Diag::note(), but it gets its own span.
pub fn highlighted_note( &mut self, messages: Vec<(impl Into<DiagMsg>, Style)>, ) -> &mut Diag
Sourcepub fn note_once(&mut self, msg: impl Into<DiagMsg>) -> &mut Diag
pub fn note_once(&mut self, msg: impl Into<DiagMsg>) -> &mut Diag
Prints the span with a note above it.
This is like Diag::note(), but it gets emitted only once.
Sourcepub fn span_note_once(
&mut self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagMsg>,
) -> &mut Diag
pub fn span_note_once( &mut self, span: impl Into<MultiSpan>, msg: impl Into<DiagMsg>, ) -> &mut Diag
Prints the span with a note above it.
This is like Diag::note_once(), but it gets its own span.
Sourcepub fn help(&mut self, msg: impl Into<DiagMsg>) -> &mut Diag
pub fn help(&mut self, msg: impl Into<DiagMsg>) -> &mut Diag
Add a help message attached to this diagnostic.
Sourcepub fn help_once(&mut self, msg: impl Into<DiagMsg>) -> &mut Diag
pub fn help_once(&mut self, msg: impl Into<DiagMsg>) -> &mut Diag
Prints the span with a help above it.
This is like Diag::help(), but it gets its own span.
Sourcepub fn highlighted_help(
&mut self,
msgs: Vec<(impl Into<DiagMsg>, Style)>,
) -> &mut Diag
pub fn highlighted_help( &mut self, msgs: Vec<(impl Into<DiagMsg>, Style)>, ) -> &mut Diag
Add a help message attached to this diagnostic with a customizable highlighted message.
Sourcepub fn span_help(
&mut self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagMsg>,
) -> &mut Diag
pub fn span_help( &mut self, span: impl Into<MultiSpan>, msg: impl Into<DiagMsg>, ) -> &mut Diag
Prints the span with some help above it.
This is like Diag::help(), but it gets its own span.
Sourcepub fn disable_suggestions(&mut self) -> &mut Diag
pub fn disable_suggestions(&mut self) -> &mut Diag
Disallow attaching suggestions to 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 seal_suggestions(&mut self) -> &mut Diag
pub fn seal_suggestions(&mut self) -> &mut Diag
Prevent new suggestions from being added to this diagnostic.
Suggestions added before the call to .seal_suggestions() will be preserved
and new suggestions will be ignored.
Sourcepub fn span_suggestion(
&mut self,
span: Span,
msg: impl Into<DiagMsg>,
suggestion: impl Into<DiagMsg>,
applicability: Applicability,
) -> &mut Diag
pub fn span_suggestion( &mut self, span: Span, msg: impl Into<DiagMsg>, suggestion: impl Into<DiagMsg>, applicability: Applicability, ) -> &mut Diag
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,
span: Span,
msg: impl Into<DiagMsg>,
suggestion: impl Into<DiagMsg>,
applicability: Applicability,
style: SuggestionStyle,
) -> &mut Diag
pub fn span_suggestion_with_style( &mut self, span: Span, msg: impl Into<DiagMsg>, suggestion: impl Into<DiagMsg>, applicability: Applicability, style: SuggestionStyle, ) -> &mut Diag
Diag::span_suggestion() but you can set the SuggestionStyle.
Sourcepub fn multipart_suggestion(
&mut self,
msg: impl Into<DiagMsg>,
substitutions: Vec<(Span, DiagMsg)>,
applicability: Applicability,
) -> &mut Diag
pub fn multipart_suggestion( &mut self, msg: impl Into<DiagMsg>, substitutions: Vec<(Span, DiagMsg)>, applicability: Applicability, ) -> &mut Diag
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_with_style(
&mut self,
msg: impl Into<DiagMsg>,
substitutions: Vec<(Span, DiagMsg)>,
applicability: Applicability,
style: SuggestionStyle,
) -> &mut Diag
pub fn multipart_suggestion_with_style( &mut self, msg: impl Into<DiagMsg>, substitutions: Vec<(Span, DiagMsg)>, applicability: Applicability, style: SuggestionStyle, ) -> &mut Diag
Diag::multipart_suggestion() but you can set the SuggestionStyle.
Trait Implementations§
Source§impl<G> Clone for DiagBuilder<'_, G>where
G: EmissionGuarantee,
impl<G> Clone for DiagBuilder<'_, G>where
G: EmissionGuarantee,
Source§fn clone(&self) -> DiagBuilder<'_, G>
fn clone(&self) -> DiagBuilder<'_, G>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<G> Debug for DiagBuilder<'_, G>where
G: EmissionGuarantee,
impl<G> Debug for DiagBuilder<'_, G>where
G: EmissionGuarantee,
Source§impl<G> Deref for DiagBuilder<'_, G>where
G: EmissionGuarantee,
impl<G> Deref for DiagBuilder<'_, G>where
G: EmissionGuarantee,
Source§impl<G> DerefMut for DiagBuilder<'_, G>where
G: EmissionGuarantee,
impl<G> DerefMut for DiagBuilder<'_, G>where
G: EmissionGuarantee,
Source§impl<G> Drop for DiagBuilder<'_, G>where
G: EmissionGuarantee,
impl<G> Drop for DiagBuilder<'_, G>where
G: EmissionGuarantee,
Auto Trait Implementations§
impl<'a, G> Freeze for DiagBuilder<'a, G>
impl<'a, G> !RefUnwindSafe for DiagBuilder<'a, G>
impl<'a, G> Send for DiagBuilder<'a, G>where
G: Send,
impl<'a, G> Sync for DiagBuilder<'a, G>where
G: Sync,
impl<'a, G> Unpin for DiagBuilder<'a, G>where
G: Unpin,
impl<'a, G> !UnwindSafe for DiagBuilder<'a, G>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more