Skip to content

Commit a560810

Browse files
committed
Don't include inner attribute ranges in CaptureState.
The current code is this: ``` self.capture_state.replace_ranges.push((start_pos..end_pos, Some(target))); self.capture_state.replace_ranges.extend(inner_attr_replace_ranges); ``` What's not obvious is that every range in `inner_attr_replace_ranges` must be a strict sub-range of `start_pos..end_pos`. Which means, in `LazyAttrTokenStreamImpl::to_attr_token_stream`, they will be done first, and then the `start_pos..end_pos` replacement will just overwrite them. So they aren't needed.
1 parent 6106b05 commit a560810

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

compiler/rustc_parse/src/parser/attr_wrapper.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,7 @@ impl<'a> Parser<'a> {
337337
// When parsing `m`:
338338
// - `start_pos..end_pos` is `0..34` (`mod m`, excluding the `#[cfg_eval]` attribute).
339339
// - `inner_attr_replace_ranges` is empty.
340-
// - `replace_range_start..replace_ranges_end` has two entries.
341-
// - One to delete the inner attribute (`17..27`), obtained when parsing `g` (see above).
340+
// - `replace_range_start..replace_ranges_end` has one entry.
342341
// - One `AttrsTarget` (added below when parsing `g`) to replace all of `g` (`3..33`,
343342
// including its outer attribute), with:
344343
// - `attrs`: includes the outer and the inner attr.
@@ -369,12 +368,10 @@ impl<'a> Parser<'a> {
369368

370369
// What is the status here when parsing the example code at the top of this method?
371370
//
372-
// When parsing `g`, we add two entries:
371+
// When parsing `g`, we add one entry:
373372
// - The `start_pos..end_pos` (`3..33`) entry has a new `AttrsTarget` with:
374373
// - `attrs`: includes the outer and the inner attr.
375374
// - `tokens`: lazy tokens for `g` (with its inner attr deleted).
376-
// - `inner_attr_replace_ranges` contains the one entry to delete the inner attr's
377-
// tokens (`17..27`).
378375
//
379376
// When parsing `m`, we do nothing here.
380377

@@ -384,7 +381,6 @@ impl<'a> Parser<'a> {
384381
let start_pos = if has_outer_attrs { attrs.start_pos } else { start_pos };
385382
let target = AttrsTarget { attrs: ret.attrs().iter().cloned().collect(), tokens };
386383
self.capture_state.replace_ranges.push((start_pos..end_pos, Some(target)));
387-
self.capture_state.replace_ranges.extend(inner_attr_replace_ranges);
388384
} else if matches!(self.capture_state.capturing, Capturing::No) {
389385
// Only clear the ranges once we've finished capturing entirely, i.e. we've finished
390386
// the outermost call to this method.

0 commit comments

Comments
 (0)