mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-22 02:00:00 +03:00
Move next_disambiguator to Resolver
This commit is contained in:
@@ -87,7 +87,6 @@ pub struct Definitions {
|
||||
parent_modules_of_macro_defs: FxHashMap<ExpnId, DefId>,
|
||||
/// Item with a given `LocalDefId` was defined during macro expansion with ID `ExpnId`.
|
||||
expansions_that_defined: FxHashMap<LocalDefId, ExpnId>,
|
||||
next_disambiguator: FxHashMap<(LocalDefId, DefPathData), u32>,
|
||||
}
|
||||
|
||||
/// A unique identifier that we can use to lookup a definition
|
||||
@@ -350,7 +349,6 @@ pub fn new(crate_name: &str, crate_disambiguator: CrateDisambiguator) -> Definit
|
||||
def_id_to_hir_id: Default::default(),
|
||||
hir_id_to_def_id: Default::default(),
|
||||
expansions_that_defined: Default::default(),
|
||||
next_disambiguator: Default::default(),
|
||||
parent_modules_of_macro_defs: Default::default(),
|
||||
}
|
||||
}
|
||||
@@ -366,20 +364,14 @@ pub fn create_def(
|
||||
parent: LocalDefId,
|
||||
data: DefPathData,
|
||||
expn_id: ExpnId,
|
||||
mut next_disambiguator: impl FnMut(LocalDefId, DefPathData) -> u32,
|
||||
) -> LocalDefId {
|
||||
debug!("create_def(parent={:?}, data={:?}, expn_id={:?})", parent, data, expn_id);
|
||||
|
||||
// The root node must be created with `create_root_def()`.
|
||||
assert!(data != DefPathData::CrateRoot);
|
||||
|
||||
// Find the next free disambiguator for this key.
|
||||
let disambiguator = {
|
||||
let next_disamb = self.next_disambiguator.entry((parent, data)).or_insert(0);
|
||||
let disambiguator = *next_disamb;
|
||||
*next_disamb = next_disamb.checked_add(1).expect("disambiguator overflow");
|
||||
disambiguator
|
||||
};
|
||||
|
||||
let disambiguator = next_disambiguator(parent, data);
|
||||
let key = DefKey {
|
||||
parent: Some(parent.local_def_index),
|
||||
disambiguated_data: DisambiguatedDefPathData { data, disambiguator },
|
||||
|
||||
@@ -982,6 +982,8 @@ pub struct Resolver<'a> {
|
||||
/// When collecting definitions from an AST fragment produced by a macro invocation `ExpnId`
|
||||
/// we know what parent node that fragment should be attached to thanks to this table.
|
||||
invocation_parents: FxHashMap<ExpnId, LocalDefId>,
|
||||
|
||||
next_disambiguator: FxHashMap<(LocalDefId, DefPathData), u32>,
|
||||
}
|
||||
|
||||
/// Nothing really interesting here; it just provides memory for the rest of the crate.
|
||||
@@ -1142,7 +1144,16 @@ fn create_def(
|
||||
self.definitions.def_key(self.node_id_to_def_id[&node_id]),
|
||||
);
|
||||
|
||||
let def_id = self.definitions.create_def(parent, data, expn_id);
|
||||
// Find the next free disambiguator for this key.
|
||||
let next_disambiguator = &mut self.next_disambiguator;
|
||||
let next_disambiguator = |parent, data| {
|
||||
let next_disamb = next_disambiguator.entry((parent, data)).or_insert(0);
|
||||
let disambiguator = *next_disamb;
|
||||
*next_disamb = next_disamb.checked_add(1).expect("disambiguator overflow");
|
||||
disambiguator
|
||||
};
|
||||
|
||||
let def_id = self.definitions.create_def(parent, data, expn_id, next_disambiguator);
|
||||
|
||||
assert_eq!(self.def_id_to_span.push(span), def_id);
|
||||
|
||||
@@ -1322,6 +1333,7 @@ pub fn new(
|
||||
def_id_to_node_id,
|
||||
placeholder_field_indices: Default::default(),
|
||||
invocation_parents,
|
||||
next_disambiguator: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user