Skip to main content

Tok

Struct Tok 

Source
pub struct Tok {
    pub kind: PpTokenKind,
    pub flags: TokenFlags,
    pub value: Option<Symbol>,
    pub span: Span,
    pub expansion: Span,
    pub hides: HideSet,
    pub trace: TraceId,
    /* private fields */
}
Expand description

A token in flight through macro expansion.

Construct one from a lexed token with Tok::new. The fields are readable because everything downstream matches on them, but the placemarker flag is not settable from outside the crate, because a placemarker escaping the expander would be a token with no spelling and no meaning.

Fields§

§kind: PpTokenKind

What kind of token this is.

§flags: TokenFlags

Whitespace and origin flags, carried through from the lexer.

§value: Option<Symbol>

The interned spelling, or None for a punctuator, whose spelling is fixed.

§span: Span

Where the token is spelled: in a macro body for a token that came from one, in the user’s file for a token that did not.

§expansion: Span

Where the outermost macro invocation that produced this token was written, or Span::DUMMY for a token the user wrote directly.

This is the span a diagnostic points at, with span becoming a note, which is what makes an error three macros deep readable.

§hides: HideSet

The macro names that must not expand this token again.

§trace: TraceId

The chain of macros this token came out of, innermost first, or TraceId::NONE for a token the user wrote.

span says where the text is and expansion says where the user was standing. This says how one became the other, which is the part a reader cannot reconstruct by hand once there is more than one macro involved.

Implementations§

Source§

impl Tok

Source

pub fn new(pp: PpToken) -> Tok

A token straight from the lexer, with an empty hide set and no expansion point.

Source

pub fn punct(self) -> Option<Punct>

The punctuator this token is, if it is one.

Source

pub fn is(self, p: Punct) -> bool

Whether this token is the punctuator p.

Source

pub fn ident(self) -> Option<Symbol>

The identifier this token is, if it is one.

Source

pub fn is_placemarker(self) -> bool

Whether this is the empty token ## uses for an absent argument.

Source

pub fn report_span(self) -> Span

The span to report a diagnostic about this token at.

The invocation point when there is one, because a user reading an error wants the line they wrote, not a line in a header they have never opened.

Trait Implementations§

Source§

impl Clone for Tok

Source§

fn clone(&self) -> Tok

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 Copy for Tok

Source§

impl Debug for Tok

Source§

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

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

impl Eq for Tok

Source§

impl PartialEq for Tok

Source§

fn eq(&self, other: &Tok) -> 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 Tok

Auto Trait Implementations§

§

impl Freeze for Tok

§

impl RefUnwindSafe for Tok

§

impl Send for Tok

§

impl Sync for Tok

§

impl Unpin for Tok

§

impl UnsafeUnpin for Tok

§

impl UnwindSafe for Tok

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