Struct rustc_expand::mbe::macro_parser::MatcherPos[−][src]

struct MatcherPos<'root, 'tt> {
    top_elts: TokenTreeOrTokenTreeSlice<'tt>,
    idx: usize,
    matches: Box<[Lrc<SmallVec<[NamedMatch; 4]>>]>,
    match_lo: usize,
    match_cur: usize,
    match_hi: usize,
    seq_op: Option<KleeneOp>,
    sep: Option<Token>,
    up: Option<MatcherPosHandle<'root, 'tt>>,
    stack: SmallVec<[MatcherTtFrame<'tt>; 1]>,
}
Expand description

Represents a single “position” (aka “matcher position”, aka “item”), as described in the module documentation.

Here:

  • 'root represents the lifetime of the stack slot that holds the root MatcherPos. As described in MatcherPosHandle, the root MatcherPos structure is stored on the stack, but subsequent instances are put into the heap.
  • 'tt represents the lifetime of the token trees that this matcher position refers to.

It is important to distinguish these two lifetimes because we have a SmallVec<TokenTreeOrTokenTreeSlice<'tt>> below, and the destructor of that is considered to possibly access the data from its elements (it lacks a #[may_dangle] attribute). As a result, the compiler needs to know that all the elements in that SmallVec strictly outlive the root stack slot lifetime. By separating 'tt from 'root, we can show that.

Fields

top_elts: TokenTreeOrTokenTreeSlice<'tt>
Expand description

The token or sequence of tokens that make up the matcher

idx: usize
Expand description

The position of the “dot” in this matcher

matches: Box<[Lrc<SmallVec<[NamedMatch; 4]>>]>
Expand description

For each named metavar in the matcher, we keep track of token trees matched against the metavar by the black box parser. In particular, there may be more than one match per metavar if we are in a repetition (each repetition matches each of the variables). Moreover, matchers and repetitions can be nested; the matches field is shared (hence the Rc) among all “nested” matchers. match_lo, match_cur, and match_hi keep track of the current position of the self matcher position in the shared matches list.

Also, note that while we are descending into a sequence, matchers are given their own matches vector. Only once we reach the end of a full repetition of the sequence do we add all bound matches from the submatcher into the shared top-level matches vector. If sep and up are Some, then matches is not the shared top-level list. Instead, if one wants the shared matches, one should use up.matches.

match_lo: usize
Expand description

The position in matches corresponding to the first metavar in this matcher’s sequence of token trees. In other words, the first metavar in the first token of top_elts corresponds to matches[match_lo].

match_cur: usize
Expand description

The position in matches corresponding to the metavar we are currently trying to match against the source token stream. match_lo <= match_cur <= match_hi.

match_hi: usize
Expand description

Similar to match_lo except match_hi is the position in matches of the last metavar in this matcher.

seq_op: Option<KleeneOp>
Expand description

The KleeneOp of this sequence if we are in a repetition.

sep: Option<Token>
Expand description

The separator if we are in a repetition.

up: Option<MatcherPosHandle<'root, 'tt>>
Expand description

The “parent” matcher position if we are in a repetition. That is, the matcher position just before we enter the sequence.

stack: SmallVec<[MatcherTtFrame<'tt>; 1]>
Expand description

Specifically used to “unzip” token trees. By “unzip”, we mean to unwrap the delimiters from a delimited token tree (e.g., something wrapped in ( )) or to get the contents of a doc comment…

When matching against matchers with nested delimited submatchers (e.g., pat ( pat ( .. ) pat ) pat), we need to keep track of the matchers we are descending into. This stack does that where the bottom of the stack is the outermost matcher. Also, throughout the comments, this “descent” is often referred to as “unzipping”…

Implementations

impl<'root, 'tt> MatcherPos<'root, 'tt>[src]

fn push_match(&mut self, idx: usize, m: NamedMatch)[src]

Adds m as a named match for the idx-th metavar.

Trait Implementations

impl<'root, 'tt> Clone for MatcherPos<'root, 'tt>[src]

fn clone(&self) -> MatcherPos<'root, 'tt>[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

Auto Trait Implementations

impl<'root, 'tt> !RefUnwindSafe for MatcherPos<'root, 'tt>

impl<'root, 'tt> !Send for MatcherPos<'root, 'tt>

impl<'root, 'tt> !Sync for MatcherPos<'root, 'tt>

impl<'root, 'tt> Unpin for MatcherPos<'root, 'tt> where
    'tt: 'root, 

impl<'root, 'tt> !UnwindSafe for MatcherPos<'root, 'tt>

Blanket Implementations

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

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized, 
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized, 
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone, 
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

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

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.