Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 757f73f

Browse files
committed
Simplify CaptureState::inner_attr_ranges.
The `Option`s within the `ReplaceRange`s within the hashmap are always `None`. This PR omits them and inserts them when they are extracted from the hashmap.
1 parent 3d68afc commit 757f73f

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

compiler/rustc_parse/src/parser/attr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,17 +303,17 @@ impl<'a> Parser<'a> {
303303
None
304304
};
305305
if let Some(attr) = attr {
306-
let end_pos = self.num_bump_calls;
307306
// If we are currently capturing tokens, mark the location of this inner attribute.
308307
// If capturing ends up creating a `LazyAttrTokenStream`, we will include
309308
// this replace range with it, removing the inner attribute from the final
310309
// `AttrTokenStream`. Inner attributes are stored in the parsed AST note.
311310
// During macro expansion, they are selectively inserted back into the
312311
// token stream (the first inner attribute is removed each time we invoke the
313312
// corresponding macro).
314-
let range = start_pos..end_pos;
315313
if let Capturing::Yes = self.capture_state.capturing {
316-
self.capture_state.inner_attr_ranges.insert(attr.id, (range, None));
314+
let end_pos = self.num_bump_calls;
315+
let range = start_pos..end_pos;
316+
self.capture_state.inner_attr_ranges.insert(attr.id, range);
317317
}
318318
attrs.push(attr);
319319
} else {

compiler/rustc_parse/src/parser/attr_wrapper.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ impl<'a> Parser<'a> {
260260
// Take the captured ranges for any inner attributes that we parsed.
261261
for inner_attr in ret.attrs().iter().filter(|a| a.style == ast::AttrStyle::Inner) {
262262
if let Some(attr_range) = self.capture_state.inner_attr_ranges.remove(&inner_attr.id) {
263-
inner_attr_replace_ranges.push(attr_range);
263+
inner_attr_replace_ranges.push((attr_range, None));
264264
} else {
265265
self.dcx().span_delayed_bug(inner_attr.span, "Missing token range for attribute");
266266
}

compiler/rustc_parse/src/parser/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ enum Capturing {
225225
struct CaptureState {
226226
capturing: Capturing,
227227
replace_ranges: Vec<ReplaceRange>,
228-
inner_attr_ranges: FxHashMap<AttrId, ReplaceRange>,
228+
inner_attr_ranges: FxHashMap<AttrId, Range<u32>>,
229229
}
230230

231231
/// Iterator over a `TokenStream` that produces `Token`s. It's a bit odd that

0 commit comments

Comments
 (0)