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.
This commit is contained in:
Nicholas Nethercote 2024-07-12 15:47:16 +10:00
parent 3d68afc9e8
commit 757f73f506
3 changed files with 5 additions and 5 deletions

View File

@ -303,7 +303,6 @@ impl<'a> Parser<'a> {
None
};
if let Some(attr) = attr {
let end_pos = self.num_bump_calls;
// If we are currently capturing tokens, mark the location of this inner attribute.
// If capturing ends up creating a `LazyAttrTokenStream`, we will include
// this replace range with it, removing the inner attribute from the final
@ -311,9 +310,10 @@ impl<'a> Parser<'a> {
// During macro expansion, they are selectively inserted back into the
// token stream (the first inner attribute is removed each time we invoke the
// corresponding macro).
let range = start_pos..end_pos;
if let Capturing::Yes = self.capture_state.capturing {
self.capture_state.inner_attr_ranges.insert(attr.id, (range, None));
let end_pos = self.num_bump_calls;
let range = start_pos..end_pos;
self.capture_state.inner_attr_ranges.insert(attr.id, range);
}
attrs.push(attr);
} else {

View File

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

View File

@ -225,7 +225,7 @@ enum Capturing {
struct CaptureState {
capturing: Capturing,
replace_ranges: Vec<ReplaceRange>,
inner_attr_ranges: FxHashMap<AttrId, ReplaceRange>,
inner_attr_ranges: FxHashMap<AttrId, Range<u32>>,
}
/// Iterator over a `TokenStream` that produces `Token`s. It's a bit odd that