@@ -69,8 +69,7 @@ pub fn transcribe(sp_diag: &Handler,
69
69
-> Vec < TokenTree > {
70
70
let mut stack = SmallVector :: one ( Frame :: new ( src) ) ;
71
71
let interpolations = interp. unwrap_or_else ( HashMap :: new) ; /* just a convenience */
72
- let mut repeat_idx = Vec :: new ( ) ;
73
- let mut repeat_len = Vec :: new ( ) ;
72
+ let mut repeats = Vec :: new ( ) ;
74
73
let mut result = Vec :: new ( ) ;
75
74
let mut result_stack = Vec :: new ( ) ;
76
75
@@ -79,8 +78,9 @@ pub fn transcribe(sp_diag: &Handler,
79
78
tree
80
79
} else {
81
80
if let Frame :: Sequence { ref mut idx, ref sep, .. } = * stack. last_mut ( ) . unwrap ( ) {
82
- if * repeat_idx. last ( ) . unwrap ( ) < * repeat_len. last ( ) . unwrap ( ) - 1 {
83
- * repeat_idx. last_mut ( ) . unwrap ( ) += 1 ;
81
+ let ( ref mut repeat_idx, repeat_len) = * repeats. last_mut ( ) . unwrap ( ) ;
82
+ * repeat_idx += 1 ;
83
+ if * repeat_idx < repeat_len {
84
84
* idx = 0 ;
85
85
if let Some ( sep) = sep. clone ( ) {
86
86
// repeat same span, I guess
@@ -93,8 +93,7 @@ pub fn transcribe(sp_diag: &Handler,
93
93
94
94
match stack. pop ( ) . unwrap ( ) {
95
95
Frame :: Sequence { .. } => {
96
- repeat_idx. pop ( ) ;
97
- repeat_len. pop ( ) ;
96
+ repeats. pop ( ) ;
98
97
}
99
98
Frame :: Delimited { forest, span, .. } => {
100
99
if result_stack. is_empty ( ) {
@@ -116,7 +115,7 @@ pub fn transcribe(sp_diag: &Handler,
116
115
// FIXME(pcwalton): Bad copy.
117
116
match lockstep_iter_size ( & quoted:: TokenTree :: Sequence ( sp, seq. clone ( ) ) ,
118
117
& interpolations,
119
- & repeat_idx ) {
118
+ & repeats ) {
120
119
LockstepIterSize :: Unconstrained => {
121
120
panic ! ( sp_diag. span_fatal(
122
121
sp. clone( ) , /* blame macro writer */
@@ -136,8 +135,7 @@ pub fn transcribe(sp_diag: &Handler,
136
135
"this must repeat at least once" ) ) ;
137
136
}
138
137
} else {
139
- repeat_len. push ( len) ;
140
- repeat_idx. push ( 0 ) ;
138
+ repeats. push ( ( 0 , len) ) ;
141
139
stack. push ( Frame :: Sequence {
142
140
idx : 0 ,
143
141
sep : seq. separator . clone ( ) ,
@@ -149,7 +147,7 @@ pub fn transcribe(sp_diag: &Handler,
149
147
}
150
148
// FIXME #2887: think about span stuff here
151
149
quoted:: TokenTree :: Token ( sp, SubstNt ( ident) ) => {
152
- match lookup_cur_matched ( ident, & interpolations, & repeat_idx ) {
150
+ match lookup_cur_matched ( ident, & interpolations, & repeats ) {
153
151
None => result. push ( TokenTree :: Token ( sp, SubstNt ( ident) ) ) ,
154
152
Some ( cur_matched) => if let MatchedNonterminal ( ref nt) = * cur_matched {
155
153
match * * nt {
@@ -184,16 +182,16 @@ pub fn transcribe(sp_diag: &Handler,
184
182
185
183
fn lookup_cur_matched ( ident : Ident ,
186
184
interpolations : & HashMap < Ident , Rc < NamedMatch > > ,
187
- repeat_idx : & [ usize ] )
185
+ repeats : & [ ( usize , usize ) ] )
188
186
-> Option < Rc < NamedMatch > > {
189
187
interpolations. get ( & ident) . map ( |matched| {
190
- repeat_idx . iter ( ) . fold ( matched. clone ( ) , |ad, idx| {
188
+ repeats . iter ( ) . fold ( matched. clone ( ) , |ad, & ( idx, _ ) | {
191
189
match * ad {
192
190
MatchedNonterminal ( _) => {
193
191
// end of the line; duplicate henceforth
194
192
ad. clone ( )
195
193
}
196
- MatchedSeq ( ref ads, _) => ads[ * idx] . clone ( )
194
+ MatchedSeq ( ref ads, _) => ads[ idx] . clone ( )
197
195
}
198
196
} )
199
197
} )
@@ -230,22 +228,22 @@ impl Add for LockstepIterSize {
230
228
231
229
fn lockstep_iter_size ( tree : & quoted:: TokenTree ,
232
230
interpolations : & HashMap < Ident , Rc < NamedMatch > > ,
233
- repeat_idx : & [ usize ] )
231
+ repeats : & [ ( usize , usize ) ] )
234
232
-> LockstepIterSize {
235
233
use self :: quoted:: TokenTree ;
236
234
match * tree {
237
235
TokenTree :: Delimited ( _, ref delimed) => {
238
236
delimed. tts . iter ( ) . fold ( LockstepIterSize :: Unconstrained , |size, tt| {
239
- size + lockstep_iter_size ( tt, interpolations, repeat_idx )
237
+ size + lockstep_iter_size ( tt, interpolations, repeats )
240
238
} )
241
239
} ,
242
240
TokenTree :: Sequence ( _, ref seq) => {
243
241
seq. tts . iter ( ) . fold ( LockstepIterSize :: Unconstrained , |size, tt| {
244
- size + lockstep_iter_size ( tt, interpolations, repeat_idx )
242
+ size + lockstep_iter_size ( tt, interpolations, repeats )
245
243
} )
246
244
} ,
247
245
TokenTree :: Token ( _, SubstNt ( name) ) | TokenTree :: MetaVarDecl ( _, name, _) =>
248
- match lookup_cur_matched ( name, interpolations, repeat_idx ) {
246
+ match lookup_cur_matched ( name, interpolations, repeats ) {
249
247
Some ( matched) => match * matched {
250
248
MatchedNonterminal ( _) => LockstepIterSize :: Unconstrained ,
251
249
MatchedSeq ( ref ads, _) => LockstepIterSize :: Constraint ( ads. len ( ) , name) ,
0 commit comments