Move trait_map into hir::Crate
This commit is contained in:
parent
033013cab3
commit
936b6bfa64
6 changed files with 20 additions and 15 deletions
|
|
@ -205,6 +205,8 @@ pub trait Resolver {
|
|||
fn lint_buffer(&mut self) -> &mut LintBuffer;
|
||||
|
||||
fn next_node_id(&mut self) -> NodeId;
|
||||
|
||||
fn trait_map(&self) -> &NodeMap<Vec<hir::TraitCandidate>>;
|
||||
}
|
||||
|
||||
type NtToTokenstream = fn(&Nonterminal, &ParseSess, Span) -> TokenStream;
|
||||
|
|
@ -557,6 +559,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
let proc_macros =
|
||||
c.proc_macros.iter().map(|id| self.node_id_to_hir_id[*id].unwrap()).collect();
|
||||
|
||||
let trait_map = self
|
||||
.resolver
|
||||
.trait_map()
|
||||
.iter()
|
||||
.map(|(&k, v)| (self.node_id_to_hir_id[k].unwrap(), v.clone()))
|
||||
.collect();
|
||||
|
||||
self.resolver.definitions().init_node_id_to_hir_id_mapping(self.node_id_to_hir_id);
|
||||
|
||||
hir::Crate {
|
||||
|
|
@ -571,6 +580,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
trait_impls: self.trait_impls,
|
||||
modules: self.modules,
|
||||
proc_macros,
|
||||
trait_map,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -639,6 +639,8 @@ pub struct Crate<'hir> {
|
|||
/// A list of proc macro HirIds, written out in the order in which
|
||||
/// they are declared in the static array generated by proc_macro_harness.
|
||||
pub proc_macros: Vec<HirId>,
|
||||
|
||||
pub trait_map: BTreeMap<HirId, Vec<TraitCandidate>>,
|
||||
}
|
||||
|
||||
impl Crate<'hir> {
|
||||
|
|
@ -2651,7 +2653,7 @@ pub type CaptureModeMap = NodeMap<CaptureBy>;
|
|||
// The TraitCandidate's import_ids is empty if the trait is defined in the same module, and
|
||||
// has length > 0 if the trait is found through an chain of imports, starting with the
|
||||
// import/use statement in the scope where the trait is used.
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(RustcEncodable, RustcDecodable, Clone, Debug)]
|
||||
pub struct TraitCandidate {
|
||||
pub def_id: DefId,
|
||||
pub import_ids: SmallVec<[LocalDefId; 1]>,
|
||||
|
|
|
|||
|
|
@ -117,6 +117,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
|
|||
body_ids: _,
|
||||
modules: _,
|
||||
proc_macros: _,
|
||||
trait_map: _,
|
||||
} = *krate;
|
||||
|
||||
hash_body(&mut hcx, root_mod_def_path_hash, item, &mut hir_body_nodes)
|
||||
|
|
|
|||
|
|
@ -1101,9 +1101,9 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
};
|
||||
|
||||
let mut trait_map: FxHashMap<_, FxHashMap<_, _>> = FxHashMap::default();
|
||||
for (hir_id, v) in resolutions.trait_map.into_iter() {
|
||||
for (hir_id, v) in krate.trait_map.iter() {
|
||||
let map = trait_map.entry(hir_id.owner).or_default();
|
||||
map.insert(hir_id.local_id, StableVec::new(v));
|
||||
map.insert(hir_id.local_id, StableVec::new(v.to_vec()));
|
||||
}
|
||||
|
||||
GlobalCtxt {
|
||||
|
|
|
|||
|
|
@ -121,7 +121,6 @@ pub struct ResolverOutputs {
|
|||
pub definitions: rustc_hir::definitions::Definitions,
|
||||
pub cstore: Box<CrateStoreDyn>,
|
||||
pub extern_crate_map: FxHashMap<LocalDefId, CrateNum>,
|
||||
pub trait_map: FxHashMap<hir::HirId, Vec<hir::TraitCandidate>>,
|
||||
pub maybe_unused_trait_imports: FxHashSet<LocalDefId>,
|
||||
pub maybe_unused_extern_crates: Vec<(LocalDefId, Span)>,
|
||||
pub export_map: ExportMap<LocalDefId>,
|
||||
|
|
|
|||
|
|
@ -1109,6 +1109,10 @@ impl rustc_ast_lowering::Resolver for Resolver<'_> {
|
|||
fn next_node_id(&mut self) -> NodeId {
|
||||
self.next_node_id()
|
||||
}
|
||||
|
||||
fn trait_map(&self) -> &NodeMap<Vec<TraitCandidate>> {
|
||||
&self.trait_map
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Resolver<'a> {
|
||||
|
|
@ -1284,11 +1288,6 @@ impl<'a> Resolver<'a> {
|
|||
let definitions = self.definitions;
|
||||
let extern_crate_map = self.extern_crate_map;
|
||||
let export_map = self.export_map;
|
||||
let trait_map = self
|
||||
.trait_map
|
||||
.into_iter()
|
||||
.map(|(k, v)| (definitions.node_id_to_hir_id(k), v))
|
||||
.collect();
|
||||
let maybe_unused_trait_imports = self.maybe_unused_trait_imports;
|
||||
let maybe_unused_extern_crates = self.maybe_unused_extern_crates;
|
||||
let glob_map = self.glob_map;
|
||||
|
|
@ -1297,7 +1296,6 @@ impl<'a> Resolver<'a> {
|
|||
cstore: Box::new(self.crate_loader.into_cstore()),
|
||||
extern_crate_map,
|
||||
export_map,
|
||||
trait_map,
|
||||
glob_map,
|
||||
maybe_unused_trait_imports,
|
||||
maybe_unused_extern_crates,
|
||||
|
|
@ -1315,11 +1313,6 @@ impl<'a> Resolver<'a> {
|
|||
cstore: Box::new(self.cstore().clone()),
|
||||
extern_crate_map: self.extern_crate_map.clone(),
|
||||
export_map: self.export_map.clone(),
|
||||
trait_map: self
|
||||
.trait_map
|
||||
.iter()
|
||||
.map(|(&k, v)| (self.definitions.node_id_to_hir_id(k), v.clone()))
|
||||
.collect(),
|
||||
glob_map: self.glob_map.clone(),
|
||||
maybe_unused_trait_imports: self.maybe_unused_trait_imports.clone(),
|
||||
maybe_unused_extern_crates: self.maybe_unused_extern_crates.clone(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue