Store macro parent module in ExpnData.

This commit is contained in:
Camille GILLOT 2021-06-28 19:29:55 +02:00
parent 969a6c2481
commit 3162c37b59
7 changed files with 32 additions and 40 deletions

View file

@ -5,9 +5,7 @@
//! expressions) that are mostly just leftovers.
pub use crate::def_id::DefPathHash;
use crate::def_id::{
CrateNum, DefId, DefIndex, LocalDefId, StableCrateId, CRATE_DEF_INDEX, LOCAL_CRATE,
};
use crate::def_id::{CrateNum, DefIndex, LocalDefId, StableCrateId, CRATE_DEF_INDEX, LOCAL_CRATE};
use crate::hir;
use rustc_data_structures::fx::FxHashMap;
@ -108,9 +106,6 @@ pub struct Definitions {
/// The reverse mapping of `def_id_to_hir_id`.
pub(super) hir_id_to_def_id: FxHashMap<hir::HirId, LocalDefId>,
/// If `ExpnId` is an ID of some macro expansion,
/// then `DefId` is the normal module (`mod`) in which the expanded macro was defined.
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>,
}
@ -353,7 +348,6 @@ impl Definitions {
def_id_to_hir_id: Default::default(),
hir_id_to_def_id: Default::default(),
expansions_that_defined: Default::default(),
parent_modules_of_macro_defs: Default::default(),
}
}
@ -420,14 +414,6 @@ impl Definitions {
self.expansions_that_defined.get(&id).copied().unwrap_or_else(ExpnId::root)
}
pub fn parent_module_of_macro_def(&self, expn_id: ExpnId) -> DefId {
self.parent_modules_of_macro_defs[&expn_id]
}
pub fn add_parent_module_of_macro_def(&mut self, expn_id: ExpnId, module: DefId) {
self.parent_modules_of_macro_defs.insert(expn_id, module);
}
pub fn iter_local_def_id(&self) -> impl Iterator<Item = LocalDefId> + '_ {
self.def_id_to_hir_id.iter_enumerated().map(|(k, _)| k)
}