Skip to content

Commit b352814

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 4bb2f27 commit b352814

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
@@ -258,7 +258,7 @@ impl<'a> Parser<'a> {
258258
// Take the captured ranges for any inner attributes that we parsed.
259259
for inner_attr in ret.attrs().iter().filter(|a| a.style == ast::AttrStyle::Inner) {
260260
if let Some(attr_range) = self.capture_state.inner_attr_ranges.remove(&inner_attr.id) {
261-
inner_attr_replace_ranges.push(attr_range);
261+
inner_attr_replace_ranges.push((attr_range, None));
262262
} else {
263263
self.dcx().span_delayed_bug(inner_attr.span, "Missing token range for attribute");
264264
}

compiler/rustc_parse/src/parser/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ enum Capturing {
235235
struct CaptureState {
236236
capturing: Capturing,
237237
replace_ranges: Vec<ReplaceRange>,
238-
inner_attr_ranges: FxHashMap<AttrId, ReplaceRange>,
238+
inner_attr_ranges: FxHashMap<AttrId, Range<u32>>,
239239
}
240240

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

0 commit comments

Comments
 (0)