diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-07-12 15:47:16 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-07-19 15:25:54 +1000 |
| commit | 757f73f506a48ff96de54c0cb8c79a25ffbc70d9 (patch) | |
| tree | f92ed5e6ac886abff68e4bd18955dc3dc918c5b7 /compiler/rustc_parse/src | |
| parent | 3d68afc9e821b00d59058abc9bda670b07639955 (diff) | |
| download | rust-757f73f506a48ff96de54c0cb8c79a25ffbc70d9.tar.gz rust-757f73f506a48ff96de54c0cb8c79a25ffbc70d9.zip | |
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.
Diffstat (limited to 'compiler/rustc_parse/src')
| -rw-r--r-- | compiler/rustc_parse/src/parser/attr.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/attr_wrapper.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/mod.rs | 2 |
3 files changed, 5 insertions, 5 deletions
diff --git a/compiler/rustc_parse/src/parser/attr.rs b/compiler/rustc_parse/src/parser/attr.rs index a8fe35f45b3..aeef6e62fda 100644 --- a/compiler/rustc_parse/src/parser/attr.rs +++ b/compiler/rustc_parse/src/parser/attr.rs @@ -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 { diff --git a/compiler/rustc_parse/src/parser/attr_wrapper.rs b/compiler/rustc_parse/src/parser/attr_wrapper.rs index 7e56e92f87b..efe9c55f523 100644 --- a/compiler/rustc_parse/src/parser/attr_wrapper.rs +++ b/compiler/rustc_parse/src/parser/attr_wrapper.rs @@ -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"); } diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index c03527acb2c..9a63a205242 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -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 |
