pub struct SubDiagnostic { /* private fields */ }Expand description
A collection of information subservient to a diagnostic.
A sub-diagnostic is always rendered after the parent diagnostic it is attached to. A parent diagnostic may have many sub-diagnostics, and it is guaranteed that they will not interleave with one another in rendering.
Currently, the order in which sub-diagnostics are rendered relative to one another (for a single parent diagnostic) is the order in which they were attached to the diagnostic.
Implementations§
Source§impl SubDiagnostic
impl SubDiagnostic
Sourcepub fn new<'a>(
severity: SubDiagnosticSeverity,
message: impl IntoDiagnosticMessage + 'a,
) -> SubDiagnostic
pub fn new<'a>( severity: SubDiagnosticSeverity, message: impl IntoDiagnosticMessage + 'a, ) -> SubDiagnostic
Create a new sub-diagnostic with the given severity and message.
The severity should describe the assumed level of importance to an end user.
The message is meant to be read by end users. The primary message is meant to be a single terse description (usually a short phrase) describing the group of related characteristics that the sub-diagnostic describes. Stated differently, if only one thing from a diagnostic can be shown to an end user in a particular context, it is the primary message.
§Types implementing IntoDiagnosticMessage
Callers can pass anything that implements std::fmt::Display
directly. If callers want or need to avoid cloning the diagnostic
message, then they can also pass a DiagnosticMessage directly.
Sourcepub fn annotate(&mut self, ann: Annotation)
pub fn annotate(&mut self, ann: Annotation)
Add an annotation to this sub-diagnostic.
Annotations for a sub-diagnostic, like for a diagnostic, are optional.
If any are added, callers should strive to make at least one of them
primary. That is, it should be constructed via Annotation::primary.
A diagnostic with no primary annotations is allowed, but its rendering
may be sub-optimal.
Note that it is expected to be somewhat more common for sub-diagnostics to have no annotations (e.g., a simple note) than for a diagnostic to have no annotations.
pub fn annotations(&self) -> &[Annotation]
Sourcepub fn secondary_annotations(&self) -> impl Iterator<Item = &Annotation>
pub fn secondary_annotations(&self) -> impl Iterator<Item = &Annotation>
Returns all annotations, skipping the first primary annotation.
Sourcepub fn annotations_mut(&mut self) -> impl Iterator<Item = &mut Annotation>
pub fn annotations_mut(&mut self) -> impl Iterator<Item = &mut Annotation>
Returns a mutable borrow of the annotations of this sub-diagnostic.
Sourcepub fn primary_annotation(&self) -> Option<&Annotation>
pub fn primary_annotation(&self) -> Option<&Annotation>
Returns a shared borrow of the “primary” annotation of this diagnostic if one exists.
When there are multiple primary annotations, then the first one that was added to this diagnostic is returned.
Sourcepub fn primary_span_ref(&self) -> Option<&Span>
pub fn primary_span_ref(&self) -> Option<&Span>
Returns a reference to the primary span of this sub-diagnostic.
Sourcepub fn headline_message(&self) -> &str
pub fn headline_message(&self) -> &str
Returns the headline message for this sub-diagnostic.
A sub-diagnostic always has a message, but it may be empty.
Sourcepub fn concise_message(&self) -> ConciseMessage<'_>
pub fn concise_message(&self) -> ConciseMessage<'_>
Introspects this sub-diagnostic and returns its message for concise formatting.
When we concisely format diagnostics, we likely want to not only include the headline message but also the message attached to the primary annotation. In particular, the primary annotation often contains essential information or context for understanding the diagnostic.
The type returned implements the std::fmt::Display trait. In most
cases, just converting it to a string (or printing it) will do what
you want.
pub fn severity(&self) -> SubDiagnosticSeverity
Trait Implementations§
Source§impl Clone for SubDiagnostic
impl Clone for SubDiagnostic
Source§fn clone(&self) -> SubDiagnostic
fn clone(&self) -> SubDiagnostic
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SubDiagnostic
impl Debug for SubDiagnostic
impl Eq for SubDiagnostic
Source§impl GetSize for SubDiagnostic
impl GetSize for SubDiagnostic
Source§fn get_heap_size(&self) -> usize
fn get_heap_size(&self) -> usize
Source§fn get_heap_size_with_tracker<TRACKER: GetSizeTracker>(
&self,
tracker: TRACKER,
) -> (usize, TRACKER)
fn get_heap_size_with_tracker<TRACKER: GetSizeTracker>( &self, tracker: TRACKER, ) -> (usize, TRACKER)
tracker. Read moreSource§fn get_stack_size() -> usize
fn get_stack_size() -> usize
Source§fn get_size_with_tracker<T>(&self, tracker: T) -> (usize, T)where
T: GetSizeTracker,
fn get_size_with_tracker<T>(&self, tracker: T) -> (usize, T)where
T: GetSizeTracker,
tracker. Read moreSource§impl Hash for SubDiagnostic
impl Hash for SubDiagnostic
Source§impl PartialEq for SubDiagnostic
impl PartialEq for SubDiagnostic
impl StructuralPartialEq for SubDiagnostic
Auto Trait Implementations§
impl Freeze for SubDiagnostic
impl RefUnwindSafe for SubDiagnostic
impl Send for SubDiagnostic
impl Sync for SubDiagnostic
impl Unpin for SubDiagnostic
impl UnsafeUnpin for SubDiagnostic
impl UnwindSafe for SubDiagnostic
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> HashEqLike<&T> for T
impl<T> HashEqLike<&T> for T
Source§impl<T> HashEqLike<Cow<'_, T>> for T
impl<T> HashEqLike<Cow<'_, T>> for T
Source§impl<T> HashEqLike<T> for T
impl<T> HashEqLike<T> 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