@@ -75,7 +75,6 @@ struct LazyTokenStreamImpl {
75
75
num_calls : u32 ,
76
76
desugar_doc_comments : bool ,
77
77
append_unglued_token : Option < ( Token , Spacing ) > ,
78
- start_calls : u32 ,
79
78
replace_ranges : Box < [ ReplaceRange ] > ,
80
79
}
81
80
@@ -116,9 +115,6 @@ impl CreateTokenStream for LazyTokenStreamImpl {
116
115
new_tokens
117
116
) ;
118
117
119
- let range_start = range. start - self . start_calls ;
120
- let range_end = range. end - self . start_calls ;
121
-
122
118
// Replace any removed tokens with `FlatToken::Empty`.
123
119
// This keeps the total length of `tokens` constant throughout the
124
120
// replacement process, allowing us to use all of the `ReplaceRanges` entries
@@ -127,7 +123,7 @@ impl CreateTokenStream for LazyTokenStreamImpl {
127
123
. take ( range. len ( ) - new_tokens. len ( ) ) ;
128
124
129
125
tokens. splice (
130
- ( range_start as usize ) ..( range_end as usize ) ,
126
+ ( range . start as usize ) ..( range . end as usize ) ,
131
127
new_tokens. clone ( ) . into_iter ( ) . chain ( filler) ,
132
128
) ;
133
129
}
@@ -270,12 +266,6 @@ impl<'a> Parser<'a> {
270
266
return Ok ( ret) ;
271
267
}
272
268
273
- // Handle previous replace ranges
274
- let replace_ranges = if ret. attrs ( ) . is_empty ( ) {
275
- vec ! [ ]
276
- } else {
277
- self . capture_state . replace_ranges [ replace_ranges_start..replace_ranges_end] . to_vec ( )
278
- } ;
279
269
280
270
let cursor_snapshot_next_calls = cursor_snapshot. num_next_calls ;
281
271
let mut end_pos = self . token_cursor . num_next_calls ;
@@ -295,14 +285,27 @@ impl<'a> Parser<'a> {
295
285
296
286
let num_calls = end_pos - cursor_snapshot_next_calls;
297
287
288
+ // Handle previous replace ranges
289
+ let replace_ranges: Box < [ ReplaceRange ] > = if ret. attrs ( ) . is_empty ( ) {
290
+ Box :: new ( [ ] )
291
+ } else {
292
+ let start_calls: u32 = cursor_snapshot_next_calls. try_into ( ) . unwrap ( ) ;
293
+ self . capture_state . replace_ranges [ replace_ranges_start..replace_ranges_end]
294
+ . iter ( )
295
+ . cloned ( )
296
+ . map ( |( range, tokens) | {
297
+ ( ( range. start - start_calls) ..( range. end - start_calls) , tokens)
298
+ } )
299
+ . collect ( )
300
+ } ;
301
+
298
302
let tokens = LazyTokenStream :: new ( LazyTokenStreamImpl {
299
303
start_token,
300
304
num_calls : num_calls. try_into ( ) . unwrap ( ) ,
301
305
cursor_snapshot,
302
306
desugar_doc_comments : self . desugar_doc_comments ,
303
307
append_unglued_token : self . token_cursor . append_unglued_token . clone ( ) ,
304
308
replace_ranges : replace_ranges. into ( ) ,
305
- start_calls : cursor_snapshot_next_calls. try_into ( ) . unwrap ( ) ,
306
309
} ) ;
307
310
308
311
let final_attrs: Option < AttributesData > = ret. finalize_tokens ( tokens) ;
0 commit comments