Enum Error

Source
#[non_exhaustive]
pub enum Error<Span> { ParsingFailed { what: Vec<MacroRuleNode>, where_: Span, }, UnexpectedEnd { last_token: Option<Span>, }, InvalidProducedAst { span: Span, expected: Vec<TokenDescription>, counter_example: Vec<(TokenDescription, Span)>, }, UnboundMetavariable { name: String, where_: Span, }, InvalidRepetitionNesting { metavariable_name: String, decl_span: Span, usage_span: Span, expected_nesting: Vec<RepetitionQuantifierKind>, got_nesting: Vec<RepetitionQuantifierKind>, }, }
Expand description

An error that is generated when checking an incorrect macro.

This enum allows crate users to handle and report errors detected by check_macro.

Everything in this enum in marked as non_exhaustive, in order to partially mitigate future variant additions.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

ParsingFailed

Generated when the macro definition itself doesn’t parse correctly.

The Rust compiler is likely to emit an error anyway. Below is an example of code that triggers this error:

macro_rules! blatant_error {
    () => =>;
    //    |
    //    error: macro rhs must be delimited.
}

This prevents us from doing any analyses.

Fields

This variant is marked as non-exhaustive
Non-exhaustive enum variants could have additional fields added in future. Therefore, non-exhaustive enum variants cannot be constructed in external crates and cannot be matched against.
§what: Vec<MacroRuleNode>

What was expected.

§where_: Span

Where it was expected.

§

UnexpectedEnd

An EOF was reached when it was not expected.

Fields

This variant is marked as non-exhaustive
Non-exhaustive enum variants could have additional fields added in future. Therefore, non-exhaustive enum variants cannot be constructed in external crates and cannot be matched against.
§last_token: Option<Span>

The position the parser was at when it reached EOF.

§

InvalidProducedAst

The macro may expand to invalid AST.

This variant is very minimal for now. We may add more information to it in the future. Please open an issue if you have opinions on what to add!

Fields

This variant is marked as non-exhaustive
Non-exhaustive enum variants could have additional fields added in future. Therefore, non-exhaustive enum variants cannot be constructed in external crates and cannot be matched against.
§span: Span

Where the error happens.

§expected: Vec<TokenDescription>

What tokens are expected here.

§counter_example: Vec<(TokenDescription, Span)>

A possible expansion of the macro that exhibits a parsing error.

The expansion may contain fragments.

§

UnboundMetavariable

A macro expansion refers to a metavariable that is not defined in the macro match arm.

If you ever hit this error on a macro that works, then please file an issue.

Fields

This variant is marked as non-exhaustive
Non-exhaustive enum variants could have additional fields added in future. Therefore, non-exhaustive enum variants cannot be constructed in external crates and cannot be matched against.
§name: String

The name of the metavariable that was used.

§where_: Span

Where it was used.

§

InvalidRepetitionNesting

A variable is being repeated with a sequence of operator that does not match the one used when the variable was declared.

§Example

macro_rules! subtraction {
    ( $( $first:literal $( - $then:literal )* )? ) => {
        $first $( - $then )*
    };
}

subtraction!(101 - 42);

In this example, the repetition nesting of the matched metavariable then is ?*, while the nesting of the metavariable indication then is *.

This variant represents both the case where the amount of repetitions does not match (which is an error) and the case where the repetition operators used do not match (which is allowed, but can lead to confusing errors).

Fields

§metavariable_name: String

The name of the metavariable.

§decl_span: Span

Where the metavariable was declared.

§usage_span: Span

Where the metavariable was used with an incorrect nesting.

§expected_nesting: Vec<RepetitionQuantifierKind>

The nesting used when the metavariable was declared.

§got_nesting: Vec<RepetitionQuantifierKind>

The nesting encountered when the metavariable was used.

Trait Implementations§

Source§

impl<Span: Debug> Debug for Error<Span>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<Span> Freeze for Error<Span>
where Span: Freeze,

§

impl<Span> RefUnwindSafe for Error<Span>
where Span: RefUnwindSafe,

§

impl<Span> Send for Error<Span>
where Span: Send,

§

impl<Span> Sync for Error<Span>
where Span: Sync,

§

impl<Span> Unpin for Error<Span>
where Span: Unpin,

§

impl<Span> UnwindSafe for Error<Span>
where Span: UnwindSafe,

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.