proc_macro_error

Struct 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 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, 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.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 88 bytes