Skip to main content

SubDiagnostic

Struct SubDiagnostic 

Source
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

Source

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.

Source

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.

Source

pub fn annotations(&self) -> &[Annotation]

Source

pub fn secondary_annotations(&self) -> impl Iterator<Item = &Annotation>

Returns all annotations, skipping the first primary annotation.

Source

pub fn annotations_mut(&mut self) -> impl Iterator<Item = &mut Annotation>

Returns a mutable borrow of the annotations of this sub-diagnostic.

Source

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.

Source

pub fn primary_span_ref(&self) -> Option<&Span>

Returns a reference to the primary span of this sub-diagnostic.

Source

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.

Source

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.

Source

pub fn severity(&self) -> SubDiagnosticSeverity

Trait Implementations§

Source§

impl Clone for SubDiagnostic

Source§

fn clone(&self) -> SubDiagnostic

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SubDiagnostic

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for SubDiagnostic

Source§

impl GetSize for SubDiagnostic

Source§

fn get_heap_size(&self) -> usize

Determines how many bytes this object occupies inside the heap. Read more
Source§

fn get_heap_size_with_tracker<TRACKER: GetSizeTracker>( &self, tracker: TRACKER, ) -> (usize, TRACKER)

Determines how many bytes this object occupies inside the heap while using a tracker. Read more
Source§

fn get_stack_size() -> usize

Determines how may bytes this object occupies inside the stack. Read more
Source§

fn get_size(&self) -> usize

Determines the total size of the object. Read more
Source§

fn get_size_with_tracker<T>(&self, tracker: T) -> (usize, T)
where T: GetSizeTracker,

Determines the total size of the object while using a tracker. Read more
Source§

impl Hash for SubDiagnostic

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for SubDiagnostic

Source§

fn eq(&self, other: &SubDiagnostic) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for SubDiagnostic

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> HashEqLike<&T> for T
where T: Hash + Eq,

Source§

fn hash<H>(&self, h: &mut H)
where H: Hasher,

Source§

fn eq(&self, data: &&T) -> bool

Source§

impl<T> HashEqLike<Cow<'_, T>> for T
where T: Hash + Eq + Clone,

Source§

fn hash<H>(&self, h: &mut H)
where H: Hasher,

Source§

fn eq(&self, data: &Cow<'_, T>) -> bool

Source§

impl<T> HashEqLike<T> for T
where T: Hash + Eq,

Source§

fn hash<H>(&self, h: &mut H)
where H: Hasher,

Source§

fn eq(&self, data: &T) -> bool

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Lookup<T> for T

Source§

fn into_owned(self) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more