Skip to content

Commit

Permalink
XXX: RangeSet
Browse files Browse the repository at this point in the history
  • Loading branch information
nnethercote committed Aug 23, 2024
1 parent bf5d07f commit 0ec00d1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2959,6 +2959,12 @@ dependencies = [
"rand_core",
]

[[package]]
name = "rangemap"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f60fcc7d6849342eff22c4350c8b9a989ee8ceabc4b481253e8946b9fe83d684"

[[package]]
name = "rayon"
version = "1.10.0"
Expand Down Expand Up @@ -4166,6 +4172,7 @@ name = "rustc_parse"
version = "0.0.0"
dependencies = [
"bitflags 2.6.0",
"rangemap",
"rustc_ast",
"rustc_ast_pretty",
"rustc_data_structures",
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_parse/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2021"
[dependencies]
# tidy-alphabetical-start
bitflags = "2.4.1"
rangemap = "1.5.1"
rustc_ast = { path = "../rustc_ast" }
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
rustc_data_structures = { path = "../rustc_data_structures" }
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_parse/src/parser/attr_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,10 @@ impl<'a> Parser<'a> {
// wrapping layer.
let mut seen_indices = FxHashSet::default();
for (i, attr) in ret.attrs().iter().enumerate() {
let is_unseen = self.capture_state.seen_attrs.insert(attr.id);
if !is_unseen {
if self.capture_state.seen_attrs.contains(&attr.id) {
seen_indices.insert(i);
} else {
self.capture_state.seen_attrs.insert(attr.id..attr.id + 1);
}
}
let ret_attrs: Cow<'_, [Attribute]> =
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_parse/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub(crate) use expr::ForbiddenLetReason;
pub(crate) use item::FnParseMode;
pub use pat::{CommaRecoveryMode, RecoverColon, RecoverComma};
use path::PathStyle;
use rangemap::RangeSet;
use rustc_ast::ptr::P;
use rustc_ast::token::{self, Delimiter, IdentIsRaw, Nonterminal, Token, TokenKind};
use rustc_ast::tokenstream::{
Expand All @@ -32,7 +33,7 @@ use rustc_ast::{
VisibilityKind, DUMMY_NODE_ID,
};
use rustc_ast_pretty::pprust;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sync::Lrc;
use rustc_errors::{Applicability, Diag, FatalError, MultiSpan, PResult};
use rustc_session::parse::ParseSess;
Expand Down Expand Up @@ -183,7 +184,7 @@ pub struct Parser<'a> {
// This type is used a lot, e.g. it's cloned when matching many declarative macro rules with nonterminals. Make sure
// it doesn't unintentionally get bigger.
#[cfg(target_pointer_width = "64")]
rustc_data_structures::static_assert_size!(Parser<'_>, 288);
rustc_data_structures::static_assert_size!(Parser<'_>, 280);

/// Stores span information about a closure.
#[derive(Clone, Debug)]
Expand Down Expand Up @@ -261,7 +262,7 @@ struct CaptureState {
capturing: Capturing,
parser_replacements: Vec<ParserReplacement>,
inner_attr_parser_ranges: FxHashMap<AttrId, ParserRange>,
seen_attrs: FxHashSet<AttrId>,
seen_attrs: RangeSet<AttrId>,
}

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

0 comments on commit 0ec00d1

Please sign in to comment.