Struct proc_macro_error2::Diagnostic

source ·
pub struct Diagnostic { /* private fields */ }
Expand description

Represents a single diagnostic message

Implementations§

source§

impl Diagnostic

source

pub fn new(level: Level, message: String) -> Self

Create a new diagnostic message that points to Span::call_site()

source

pub fn spanned(span: Span, level: Level, message: String) -> Self

Create a new diagnostic message that points to the span

source

pub fn span_error(self, span: Span, msg: String) -> Self

Add another error message to self such that it will be emitted right after the main message.

source

pub fn span_help(self, span: Span, msg: String) -> Self

Attach a “help” note to your main message, the note will have it’s own span on nightly.

§Span

The span is ignored on stable, the note effectively inherits its parent’s (main message) span

source

pub fn help(self, msg: String) -> Self

Attach a “help” note to your main message.

source

pub fn span_note(self, span: Span, msg: String) -> Self

Attach a note to your main message, the note will have it’s own span on nightly.

§Span

The span is ignored on stable, the note effectively inherits its parent’s (main message) span

source

pub fn note(self, msg: String) -> Self

Attach a note to your main message

source

pub fn message(&self) -> &str

The message of main warning/error (no notes attached)

source

pub fn abort(self) -> !

Abort the proc-macro’s execution and display the diagnostic.

§Warnings

Warnings are not emitted on stable and beta, but this function will abort anyway.

source

pub fn emit(self)

Display the diagnostic while not aborting macro execution.

§Warnings

Warnings are ignored on stable/beta

Trait Implementations§

source§

impl Debug for Diagnostic

source§

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

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

impl DiagnosticExt for Diagnostic

source§

fn spanned_range(span_range: SpanRange, level: Level, message: String) -> Self

Create a new diagnostic message that points to the span_range. Read more
source§

fn span_range_error(self, span_range: SpanRange, msg: String) -> Self

Add another error message to self such that it will be emitted right after the main message. Read more
source§

fn span_range_help(self, span_range: SpanRange, msg: String) -> Self

Attach a “help” note to your main message, the note will have it’s own span on nightly. Read more
source§

fn span_range_note(self, span_range: SpanRange, msg: String) -> Self

Attach a note to your main message, the note will have it’s own span on nightly. Read more
source§

impl From<Error> for Diagnostic

source§

fn from(err: Error) -> Self

Converts to this type from the input type.
source§

impl ToTokens for Diagnostic

source§

fn to_tokens(&self, ts: &mut TokenStream)

Write self to the given TokenStream. Read more
source§

fn to_token_stream(&self) -> TokenStream

Convert self directly into a TokenStream object. Read more
source§

fn into_token_stream(self) -> TokenStream
where Self: Sized,

Convert self directly into a TokenStream object. Read more

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Spanned for T
where T: Spanned + ?Sized,

source§

fn span(&self) -> Span

Returns a Span covering the complete contents of this syntax tree node, or Span::call_site() if this node is empty.
source§

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

source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.