@@ -12,7 +12,6 @@ use smallvec::{smallvec, SmallVec};
12
12
use rustc_data_structures:: fx:: FxHashMap ;
13
13
use rustc_data_structures:: sync:: Lrc ;
14
14
use std:: mem;
15
- use std:: rc:: Rc ;
16
15
17
16
/// An iterator over the token trees in a delimited token tree (`{ ... }`) or a sequence (`$(...)`).
18
17
enum Frame {
@@ -65,9 +64,9 @@ impl Iterator for Frame {
65
64
/// `transcribe` would return a `TokenStream` containing `println!("{}", stringify!(bar));`.
66
65
///
67
66
/// Along the way, we do some additional error checking.
68
- pub fn transcribe (
67
+ pub ( super ) fn transcribe (
69
68
cx : & ExtCtxt < ' _ > ,
70
- interp : & FxHashMap < Ident , Rc < NamedMatch > > ,
69
+ interp : & FxHashMap < Ident , NamedMatch > ,
71
70
src : Vec < quoted:: TokenTree > ,
72
71
) -> TokenStream {
73
72
// Nothing for us to transcribe...
@@ -212,7 +211,7 @@ pub fn transcribe(
212
211
// Find the matched nonterminal from the macro invocation, and use it to replace
213
212
// the meta-var.
214
213
if let Some ( cur_matched) = lookup_cur_matched ( ident, interp, & repeats) {
215
- if let MatchedNonterminal ( ref nt) = * cur_matched {
214
+ if let MatchedNonterminal ( ref nt) = cur_matched {
216
215
// FIXME #2887: why do we apply a mark when matching a token tree meta-var
217
216
// (e.g. `$x:tt`), but not when we are matching any other type of token
218
217
// tree?
@@ -273,18 +272,17 @@ pub fn transcribe(
273
272
/// See the definition of `repeats` in the `transcribe` function. `repeats` is used to descend
274
273
/// into the right place in nested matchers. If we attempt to descend too far, the macro writer has
275
274
/// made a mistake, and we return `None`.
276
- fn lookup_cur_matched (
275
+ fn lookup_cur_matched < ' a > (
277
276
ident : Ident ,
278
- interpolations : & FxHashMap < Ident , Rc < NamedMatch > > ,
277
+ interpolations : & ' a FxHashMap < Ident , NamedMatch > ,
279
278
repeats : & [ ( usize , usize ) ] ,
280
- ) -> Option < Rc < NamedMatch > > {
279
+ ) -> Option < & ' a NamedMatch > {
281
280
interpolations. get ( & ident) . map ( |matched| {
282
- let mut matched = matched. clone ( ) ;
281
+ let mut matched = matched;
283
282
for & ( idx, _) in repeats {
284
- let m = matched. clone ( ) ;
285
- match * m {
283
+ match matched {
286
284
MatchedNonterminal ( _) => break ,
287
- MatchedSeq ( ref ads, _) => matched = Rc :: new ( ads[ idx ] . clone ( ) ) ,
285
+ MatchedSeq ( ref ads, _) => matched = ads. get ( idx ) . unwrap ( ) ,
288
286
}
289
287
}
290
288
@@ -343,7 +341,7 @@ impl LockstepIterSize {
343
341
/// multiple nested matcher sequences.
344
342
fn lockstep_iter_size (
345
343
tree : & quoted:: TokenTree ,
346
- interpolations : & FxHashMap < Ident , Rc < NamedMatch > > ,
344
+ interpolations : & FxHashMap < Ident , NamedMatch > ,
347
345
repeats : & [ ( usize , usize ) ] ,
348
346
) -> LockstepIterSize {
349
347
use quoted:: TokenTree ;
@@ -360,7 +358,7 @@ fn lockstep_iter_size(
360
358
}
361
359
TokenTree :: MetaVar ( _, name) | TokenTree :: MetaVarDecl ( _, name, _) => {
362
360
match lookup_cur_matched ( name, interpolations, repeats) {
363
- Some ( matched) => match * matched {
361
+ Some ( matched) => match matched {
364
362
MatchedNonterminal ( _) => LockstepIterSize :: Unconstrained ,
365
363
MatchedSeq ( ref ads, _) => LockstepIterSize :: Constraint ( ads. len ( ) , name) ,
366
364
} ,
0 commit comments