pub struct DiagnosticBuilder<'a, 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: EmissionGuarantee> DiagnosticBuilder<'a, G>
impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G>
Sourcepub fn new<M: Into<DiagnosticMessage>>(
dcx: &'a DiagCtxt,
level: Level,
msg: M,
) -> Self
pub fn new<M: Into<DiagnosticMessage>>( dcx: &'a DiagCtxt, level: Level, msg: M, ) -> Self
Creates a new DiagnosticBuilder
.
Sourcepub fn emit(self) -> G::EmitResult
pub fn emit(self) -> G::EmitResult
Emits the diagnostic.
Source§impl<G: EmissionGuarantee> DiagnosticBuilder<'_, G>
Forwarded methods to Diagnostic
.
impl<G: EmissionGuarantee> DiagnosticBuilder<'_, G>
Forwarded methods to Diagnostic
.
Sourcepub fn span(self, span: impl Into<MultiSpan>) -> Self
pub fn span(self, span: impl Into<MultiSpan>) -> Self
See Diagnostic::span()
.
Sourcepub fn code(self, code: impl Into<DiagnosticId>) -> Self
pub fn code(self, code: impl Into<DiagnosticId>) -> Self
See Diagnostic::code()
.
Sourcepub fn span_label(self, span: Span, label: impl Into<DiagnosticMessage>) -> Self
pub fn span_label(self, span: Span, label: impl Into<DiagnosticMessage>) -> Self
Sourcepub fn span_labels(
self,
spans: impl IntoIterator<Item = Span>,
label: impl Into<DiagnosticMessage>,
) -> Self
pub fn span_labels( self, spans: impl IntoIterator<Item = Span>, label: impl Into<DiagnosticMessage>, ) -> Self
Sourcepub fn warn(self, msg: impl Into<DiagnosticMessage>) -> Self
pub fn warn(self, msg: impl Into<DiagnosticMessage>) -> Self
See Diagnostic::warn()
.
Sourcepub fn span_warn(
self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>,
) -> Self
pub fn span_warn( self, span: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>, ) -> Self
Sourcepub fn note(self, msg: impl Into<DiagnosticMessage>) -> Self
pub fn note(self, msg: impl Into<DiagnosticMessage>) -> Self
See Diagnostic::note()
.
Sourcepub fn span_note(
self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>,
) -> Self
pub fn span_note( self, span: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>, ) -> Self
Sourcepub fn highlighted_note(
self,
messages: Vec<(impl Into<DiagnosticMessage>, Style)>,
) -> Self
pub fn highlighted_note( self, messages: Vec<(impl Into<DiagnosticMessage>, Style)>, ) -> Self
Sourcepub fn note_once(self, msg: impl Into<DiagnosticMessage>) -> Self
pub fn note_once(self, msg: impl Into<DiagnosticMessage>) -> Self
Sourcepub fn span_note_once(
self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>,
) -> Self
pub fn span_note_once( self, span: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>, ) -> Self
Sourcepub fn help(self, msg: impl Into<DiagnosticMessage>) -> Self
pub fn help(self, msg: impl Into<DiagnosticMessage>) -> Self
See Diagnostic::help()
.
Sourcepub fn help_once(self, msg: impl Into<DiagnosticMessage>) -> Self
pub fn help_once(self, msg: impl Into<DiagnosticMessage>) -> Self
Sourcepub fn highlighted_help(
self,
messages: Vec<(impl Into<DiagnosticMessage>, Style)>,
) -> Self
pub fn highlighted_help( self, messages: Vec<(impl Into<DiagnosticMessage>, Style)>, ) -> Self
Methods from Deref<Target = Diagnostic>§
Sourcepub fn messages(&self) -> &[(DiagnosticMessage, Style)]
pub fn messages(&self) -> &[(DiagnosticMessage, Style)]
Returns the messages of this diagnostic.
Sourcepub fn span(&mut self, span: impl Into<MultiSpan>) -> &mut Self
pub fn span(&mut self, span: impl Into<MultiSpan>) -> &mut Self
Sets the span of this diagnostic.
Sourcepub fn code(&mut self, code: impl Into<DiagnosticId>) -> &mut Self
pub fn code(&mut self, code: impl Into<DiagnosticId>) -> &mut Self
Sets the code of this diagnostic.
Sourcepub fn span_label(
&mut self,
span: Span,
label: impl Into<DiagnosticMessage>,
) -> &mut Self
pub fn span_label( &mut self, span: Span, label: impl Into<DiagnosticMessage>, ) -> &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 Into<DiagnosticMessage>,
) -> &mut Self
pub fn span_labels( &mut self, spans: impl IntoIterator<Item = Span>, label: impl Into<DiagnosticMessage>, ) -> &mut Self
Labels all the given spans with the provided label.
See Self::span_label()
for more information.
Sourcepub fn warn(&mut self, msg: impl Into<DiagnosticMessage>) -> &mut Self
pub fn warn(&mut self, msg: impl Into<DiagnosticMessage>) -> &mut Self
Add a warning attached to this diagnostic.
Sourcepub fn span_warn(
&mut self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>,
) -> &mut Self
pub fn span_warn( &mut self, span: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>, ) -> &mut Self
Prints the span with a warning above it.
This is like Diagnostic::warn()
, but it gets its own span.
Sourcepub fn note(&mut self, msg: impl Into<DiagnosticMessage>) -> &mut Self
pub fn note(&mut self, msg: impl Into<DiagnosticMessage>) -> &mut Self
Add a note to this diagnostic.
Sourcepub fn span_note(
&mut self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>,
) -> &mut Self
pub fn span_note( &mut self, span: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>, ) -> &mut Self
Prints the span with a note above it.
This is like Diagnostic::note()
, but it gets its own span.
pub fn highlighted_note( &mut self, messages: Vec<(impl Into<DiagnosticMessage>, Style)>, ) -> &mut Self
Sourcepub fn note_once(&mut self, msg: impl Into<DiagnosticMessage>) -> &mut Self
pub fn note_once(&mut self, msg: impl Into<DiagnosticMessage>) -> &mut Self
Prints the span with a note above it.
This is like Diagnostic::note()
, but it gets emitted only once.
Sourcepub fn span_note_once(
&mut self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>,
) -> &mut Self
pub fn span_note_once( &mut self, span: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>, ) -> &mut Self
Prints the span with a note above it.
This is like Diagnostic::note_once()
, but it gets its own span.
Sourcepub fn help(&mut self, msg: impl Into<DiagnosticMessage>) -> &mut Self
pub fn help(&mut self, msg: impl Into<DiagnosticMessage>) -> &mut Self
Add a help message attached to this diagnostic.
Sourcepub fn help_once(&mut self, msg: impl Into<DiagnosticMessage>) -> &mut Self
pub fn help_once(&mut self, msg: impl Into<DiagnosticMessage>) -> &mut Self
Prints the span with a help above it.
This is like Diagnostic::help()
, but it gets its own span.
Sourcepub fn highlighted_help(
&mut self,
msgs: Vec<(impl Into<DiagnosticMessage>, Style)>,
) -> &mut Self
pub fn highlighted_help( &mut self, msgs: Vec<(impl Into<DiagnosticMessage>, Style)>, ) -> &mut Self
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<DiagnosticMessage>,
) -> &mut Self
pub fn span_help( &mut self, span: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>, ) -> &mut Self
Prints the span with some help above it.
This is like Diagnostic::help()
, but it gets its own span.
Trait Implementations§
Source§impl<G: EmissionGuarantee> Clone for DiagnosticBuilder<'_, G>
impl<G: EmissionGuarantee> Clone for DiagnosticBuilder<'_, G>
Source§impl<G: EmissionGuarantee> Debug for DiagnosticBuilder<'_, G>
impl<G: EmissionGuarantee> Debug for DiagnosticBuilder<'_, G>
Source§impl<G: EmissionGuarantee> Deref for DiagnosticBuilder<'_, G>
impl<G: EmissionGuarantee> Deref for DiagnosticBuilder<'_, G>
Source§impl<G: EmissionGuarantee> DerefMut for DiagnosticBuilder<'_, G>
impl<G: EmissionGuarantee> DerefMut for DiagnosticBuilder<'_, G>
Source§impl<G: EmissionGuarantee> Drop for DiagnosticBuilder<'_, G>
impl<G: EmissionGuarantee> Drop for DiagnosticBuilder<'_, G>
Auto Trait Implementations§
impl<'a, G> Freeze for DiagnosticBuilder<'a, G>
impl<'a, G> !RefUnwindSafe for DiagnosticBuilder<'a, G>
impl<'a, G> Send for DiagnosticBuilder<'a, G>where
G: Send,
impl<'a, G> Sync for DiagnosticBuilder<'a, G>where
G: Sync,
impl<'a, G> Unpin for DiagnosticBuilder<'a, G>where
G: Unpin,
impl<'a, G> !UnwindSafe for DiagnosticBuilder<'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