@@ -12,7 +12,6 @@ use smallvec::{smallvec, SmallVec};
1212use rustc_data_structures:: fx:: FxHashMap ;
1313use rustc_data_structures:: sync:: Lrc ;
1414use std:: mem;
15- use std:: rc:: Rc ;
1615
1716/// An iterator over the token trees in a delimited token tree (`{ ... }`) or a sequence (`$(...)`).
1817enum Frame {
@@ -65,9 +64,9 @@ impl Iterator for Frame {
6564/// `transcribe` would return a `TokenStream` containing `println!("{}", stringify!(bar));`.
6665///
6766/// Along the way, we do some additional error checking.
68- pub fn transcribe (
67+ pub ( super ) fn transcribe (
6968 cx : & ExtCtxt < ' _ > ,
70- interp : & FxHashMap < Ident , Rc < NamedMatch > > ,
69+ interp : & FxHashMap < Ident , NamedMatch > ,
7170 src : Vec < quoted:: TokenTree > ,
7271) -> TokenStream {
7372 // Nothing for us to transcribe...
@@ -212,7 +211,7 @@ pub fn transcribe(
212211 // Find the matched nonterminal from the macro invocation, and use it to replace
213212 // the meta-var.
214213 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 {
216215 // FIXME #2887: why do we apply a mark when matching a token tree meta-var
217216 // (e.g. `$x:tt`), but not when we are matching any other type of token
218217 // tree?
@@ -273,18 +272,17 @@ pub fn transcribe(
273272/// See the definition of `repeats` in the `transcribe` function. `repeats` is used to descend
274273/// into the right place in nested matchers. If we attempt to descend too far, the macro writer has
275274/// made a mistake, and we return `None`.
276- fn lookup_cur_matched (
275+ fn lookup_cur_matched < ' a > (
277276 ident : Ident ,
278- interpolations : & FxHashMap < Ident , Rc < NamedMatch > > ,
277+ interpolations : & ' a FxHashMap < Ident , NamedMatch > ,
279278 repeats : & [ ( usize , usize ) ] ,
280- ) -> Option < Rc < NamedMatch > > {
279+ ) -> Option < & ' a NamedMatch > {
281280 interpolations. get ( & ident) . map ( |matched| {
282- let mut matched = matched. clone ( ) ;
281+ let mut matched = matched;
283282 for & ( idx, _) in repeats {
284- let m = matched. clone ( ) ;
285- match * m {
283+ match matched {
286284 MatchedNonterminal ( _) => break ,
287- MatchedSeq ( ref ads, _) => matched = Rc :: new ( ads[ idx ] . clone ( ) ) ,
285+ MatchedSeq ( ref ads, _) => matched = ads. get ( idx ) . unwrap ( ) ,
288286 }
289287 }
290288
@@ -343,7 +341,7 @@ impl LockstepIterSize {
343341/// multiple nested matcher sequences.
344342fn lockstep_iter_size (
345343 tree : & quoted:: TokenTree ,
346- interpolations : & FxHashMap < Ident , Rc < NamedMatch > > ,
344+ interpolations : & FxHashMap < Ident , NamedMatch > ,
347345 repeats : & [ ( usize , usize ) ] ,
348346) -> LockstepIterSize {
349347 use quoted:: TokenTree ;
@@ -360,7 +358,7 @@ fn lockstep_iter_size(
360358 }
361359 TokenTree :: MetaVar ( _, name) | TokenTree :: MetaVarDecl ( _, name, _) => {
362360 match lookup_cur_matched ( name, interpolations, repeats) {
363- Some ( matched) => match * matched {
361+ Some ( matched) => match matched {
364362 MatchedNonterminal ( _) => LockstepIterSize :: Unconstrained ,
365363 MatchedSeq ( ref ads, _) => LockstepIterSize :: Constraint ( ads. len ( ) , name) ,
366364 } ,
0 commit comments