@@ -75,7 +75,6 @@ struct LazyTokenStreamImpl {
7575 num_calls : u32 ,
7676 desugar_doc_comments : bool ,
7777 append_unglued_token : Option < ( Token , Spacing ) > ,
78- start_calls : u32 ,
7978 replace_ranges : Box < [ ReplaceRange ] > ,
8079}
8180
@@ -116,9 +115,6 @@ impl CreateTokenStream for LazyTokenStreamImpl {
116115 new_tokens
117116 ) ;
118117
119- let range_start = range. start - self . start_calls ;
120- let range_end = range. end - self . start_calls ;
121-
122118 // Replace any removed tokens with `FlatToken::Empty`.
123119 // This keeps the total length of `tokens` constant throughout the
124120 // replacement process, allowing us to use all of the `ReplaceRanges` entries
@@ -127,7 +123,7 @@ impl CreateTokenStream for LazyTokenStreamImpl {
127123 . take ( range. len ( ) - new_tokens. len ( ) ) ;
128124
129125 tokens. splice (
130- ( range_start as usize ) ..( range_end as usize ) ,
126+ ( range . start as usize ) ..( range . end as usize ) ,
131127 new_tokens. clone ( ) . into_iter ( ) . chain ( filler) ,
132128 ) ;
133129 }
@@ -270,12 +266,6 @@ impl<'a> Parser<'a> {
270266 return Ok ( ret) ;
271267 }
272268
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- } ;
279269
280270 let cursor_snapshot_next_calls = cursor_snapshot. num_next_calls ;
281271 let mut end_pos = self . token_cursor . num_next_calls ;
@@ -295,14 +285,27 @@ impl<'a> Parser<'a> {
295285
296286 let num_calls = end_pos - cursor_snapshot_next_calls;
297287
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+
298302 let tokens = LazyTokenStream :: new ( LazyTokenStreamImpl {
299303 start_token,
300304 num_calls : num_calls. try_into ( ) . unwrap ( ) ,
301305 cursor_snapshot,
302306 desugar_doc_comments : self . desugar_doc_comments ,
303307 append_unglued_token : self . token_cursor . append_unglued_token . clone ( ) ,
304308 replace_ranges : replace_ranges. into ( ) ,
305- start_calls : cursor_snapshot_next_calls. try_into ( ) . unwrap ( ) ,
306309 } ) ;
307310
308311 let final_attrs: Option < AttributesData > = ret. finalize_tokens ( tokens) ;
0 commit comments