@@ -151,43 +151,34 @@ fn lockstep_iter_size(t: &TokenTree, r: &TtReader) -> LockstepIterSize {
151
151
/// EFFECT: advances the reader's token field
152
152
fn tt_next_token ( r : & mut TtReader , prev_span : Span ) -> Option < TokenTree > {
153
153
loop {
154
- let should_pop = if let Some ( frame) = r. stack . last ( ) {
155
- if frame. idx < frame. forest . len ( ) {
156
- break ;
157
- }
158
- !frame. dotdotdoted || * r. repeat_idx . last ( ) . unwrap ( ) == * r. repeat_len . last ( ) . unwrap ( ) - 1
159
- } else {
160
- return None ;
154
+ let frame = match r. stack . last ( ) {
155
+ Some ( frame) => frame. clone ( ) ,
156
+ None => return None ,
161
157
} ;
162
158
163
- /* done with this set; pop or repeat? */
164
- if should_pop {
165
- let prev = r. stack . pop ( ) . unwrap ( ) ;
166
- if let Some ( frame) = r. stack . last_mut ( ) {
167
- frame. idx += 1 ;
159
+ if frame. idx == frame. forest . len ( ) {
160
+ if frame. dotdotdoted &&
161
+ * r. repeat_idx . last ( ) . unwrap ( ) == * r. repeat_len . last ( ) . unwrap ( ) - 1 {
162
+ * r. repeat_idx . last_mut ( ) . unwrap ( ) += 1 ;
163
+ r. stack . last_mut ( ) . unwrap ( ) . idx = 0 ;
164
+ if let Some ( tk) = r. stack . last ( ) . unwrap ( ) . sep . clone ( ) {
165
+ return Some ( TokenTree :: Token ( prev_span, tk) ) ; // repeat same span, I guess
166
+ }
168
167
} else {
169
- return None ;
170
- }
171
- if prev. dotdotdoted {
172
- r. repeat_idx . pop ( ) ;
173
- r. repeat_len . pop ( ) ;
174
- }
175
- } else { /* repeat */
176
- * r. repeat_idx . last_mut ( ) . unwrap ( ) += 1 ;
177
- r. stack . last_mut ( ) . unwrap ( ) . idx = 0 ;
178
- if let Some ( tk) = r. stack . last ( ) . unwrap ( ) . sep . clone ( ) {
179
- return Some ( TokenTree :: Token ( prev_span, tk) ) ; // repeat same span, I guess
168
+ r. stack . pop ( ) ;
169
+ match r. stack . last_mut ( ) {
170
+ Some ( frame) => frame. idx += 1 ,
171
+ None => return None ,
172
+ }
173
+ if frame. dotdotdoted {
174
+ r. repeat_idx . pop ( ) ;
175
+ r. repeat_len . pop ( ) ;
176
+ }
180
177
}
178
+ continue
181
179
}
182
- }
183
- loop { /* because it's easiest, this handles `TokenTree::Delimited` not starting
184
- with a `TokenTree::Token`, even though it won't happen */
185
- let t = {
186
- let frame = r. stack . last ( ) . unwrap ( ) ;
187
- // FIXME(pcwalton): Bad copy.
188
- frame. forest . get_tt ( frame. idx )
189
- } ;
190
- match t {
180
+
181
+ match frame. forest . get_tt ( frame. idx ) {
191
182
TokenTree :: Sequence ( sp, seq) => {
192
183
// FIXME(pcwalton): Bad copy.
193
184
match lockstep_iter_size ( & TokenTree :: Sequence ( sp, seq. clone ( ) ) ,
0 commit comments