@@ -154,7 +154,7 @@ type NamedMatchVec = SmallVec<[NamedMatch; 4]>;
154
154
/// lifetime. By separating `'tt` from `'root`, we can show that.
155
155
#[ derive( Clone ) ]
156
156
struct MatcherPos < ' root , ' tt > {
157
- /// The token or sequence of tokens that make up the matcher
157
+ /// The token or sequence of tokens that make up the matcher. `elts` is short for "elements".
158
158
top_elts : TokenTreeOrTokenTreeSlice < ' tt > ,
159
159
160
160
/// The position of the "dot" in this matcher
@@ -203,6 +203,33 @@ struct MatcherPos<'root, 'tt> {
203
203
rustc_data_structures:: static_assert_size!( MatcherPos <' _, ' _>, 192 ) ;
204
204
205
205
impl < ' root , ' tt > MatcherPos < ' root , ' tt > {
206
+ /// Generates the top-level matcher position in which the "dot" is before the first token of
207
+ /// the matcher `ms`.
208
+ fn new ( ms : & ' tt [ TokenTree ] ) -> Self {
209
+ let match_idx_hi = count_names ( ms) ;
210
+ MatcherPos {
211
+ // Start with the top level matcher given to us.
212
+ top_elts : TtSeq ( ms) ,
213
+
214
+ // The "dot" is before the first token of the matcher.
215
+ idx : 0 ,
216
+
217
+ // Initialize `matches` to a bunch of empty `Vec`s -- one for each metavar in
218
+ // `top_elts`. `match_lo` for `top_elts` is 0 and `match_hi` is `match_idx_hi`.
219
+ // `match_cur` is 0 since we haven't actually matched anything yet.
220
+ matches : create_matches ( match_idx_hi) ,
221
+ match_lo : 0 ,
222
+ match_cur : 0 ,
223
+ match_hi : match_idx_hi,
224
+
225
+ // Haven't descended into any delimiters, so this is empty.
226
+ stack : smallvec ! [ ] ,
227
+
228
+ // Haven't descended into any sequences, so this is `None`.
229
+ repetition : None ,
230
+ }
231
+ }
232
+
206
233
/// Adds `m` as a named match for the `idx`-th metavar.
207
234
fn push_match ( & mut self , idx : usize , m : NamedMatch ) {
208
235
let matches = Lrc :: make_mut ( & mut self . matches [ idx] ) ;
@@ -314,33 +341,6 @@ fn create_matches(len: usize) -> Box<[Lrc<NamedMatchVec>]> {
314
341
. into_boxed_slice ( )
315
342
}
316
343
317
- /// Generates the top-level matcher position in which the "dot" is before the first token of the
318
- /// matcher `ms`.
319
- fn initial_matcher_pos < ' root , ' tt > ( ms : & ' tt [ TokenTree ] ) -> MatcherPos < ' root , ' tt > {
320
- let match_idx_hi = count_names ( ms) ;
321
- let matches = create_matches ( match_idx_hi) ;
322
- MatcherPos {
323
- // Start with the top level matcher given to us
324
- top_elts : TtSeq ( ms) , // "elts" is an abbr. for "elements"
325
- // The "dot" is before the first token of the matcher
326
- idx : 0 ,
327
-
328
- // Initialize `matches` to a bunch of empty `Vec`s -- one for each metavar in `top_elts`.
329
- // `match_lo` for `top_elts` is 0 and `match_hi` is `matches.len()`. `match_cur` is 0 since
330
- // we haven't actually matched anything yet.
331
- matches,
332
- match_lo : 0 ,
333
- match_cur : 0 ,
334
- match_hi : match_idx_hi,
335
-
336
- // Haven't descended into any delimiters, so empty stack
337
- stack : smallvec ! [ ] ,
338
-
339
- // Haven't descended into any sequences, so this is `None`.
340
- repetition : None ,
341
- }
342
- }
343
-
344
344
/// `NamedMatch` is a pattern-match result for a single `token::MATCH_NONTERMINAL`:
345
345
/// so it is associated with a single ident in a parse, and all
346
346
/// `MatchedNonterminal`s in the `NamedMatch` have the same non-terminal type
@@ -642,7 +642,7 @@ pub(super) fn parse_tt(
642
642
//
643
643
// This MatcherPos instance is allocated on the stack. All others -- and
644
644
// there are frequently *no* others! -- are allocated on the heap.
645
- let mut initial = initial_matcher_pos ( ms) ;
645
+ let mut initial = MatcherPos :: new ( ms) ;
646
646
let mut cur_items = smallvec ! [ MatcherPosHandle :: Ref ( & mut initial) ] ;
647
647
let mut next_items = Vec :: new ( ) ;
648
648
0 commit comments