Use HirId as key for ResolverOutputs::trait_map instead of NodeId

This commit is contained in:
marmeladema 2020-05-20 18:35:58 +01:00
parent 06c9fef822
commit 5728c5371d
4 changed files with 23 additions and 7 deletions

View File

@ -327,7 +327,9 @@ impl Definitions {
#[inline]
pub fn local_def_id(&self, node: ast::NodeId) -> LocalDefId {
self.opt_local_def_id(node).unwrap()
self.opt_local_def_id(node).unwrap_or_else(|| {
panic!("no entry for node id: `{:?}` / `{:?}`", node, self.opt_node_id_to_hir_id(node))
})
}
#[inline]

View File

@ -1113,8 +1113,7 @@ impl<'tcx> TyCtxt<'tcx> {
};
let mut trait_map: FxHashMap<_, FxHashMap<_, _>> = FxHashMap::default();
for (k, v) in resolutions.trait_map {
let hir_id = definitions.node_id_to_hir_id(k);
for (hir_id, v) in resolutions.trait_map.into_iter() {
let map = trait_map.entry(hir_id.owner).or_default();
let v = v
.into_iter()

View File

@ -31,7 +31,7 @@ use rustc_hir as hir;
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Namespace, Res};
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, CRATE_DEF_INDEX};
use rustc_hir::lang_items::{FnMutTraitLangItem, FnOnceTraitLangItem, FnTraitLangItem};
use rustc_hir::{Constness, GlobMap, Node, TraitMap};
use rustc_hir::{Constness, GlobMap, Node};
use rustc_index::vec::{Idx, IndexVec};
use rustc_macros::HashStable;
use rustc_serialize::{self, Encodable, Encoder};
@ -121,7 +121,7 @@ pub struct ResolverOutputs {
pub definitions: rustc_hir::definitions::Definitions,
pub cstore: Box<CrateStoreDyn>,
pub extern_crate_map: NodeMap<CrateNum>,
pub trait_map: TraitMap<NodeId>,
pub trait_map: FxHashMap<hir::HirId, Vec<hir::TraitCandidate<NodeId>>>,
pub maybe_unused_trait_imports: NodeSet,
pub maybe_unused_extern_crates: Vec<(NodeId, Span)>,
pub export_map: ExportMap<NodeId>,

View File

@ -1,3 +1,5 @@
// ignore-tidy-filelength
//! This crate is responsible for the part of name resolution that doesn't require type checker.
//!
//! Module structure of the crate is built here.
@ -1271,12 +1273,19 @@ impl<'a> Resolver<'a> {
}
pub fn into_outputs(self) -> ResolverOutputs {
let trait_map = {
let mut map = FxHashMap::default();
for (k, v) in self.trait_map.into_iter() {
map.insert(self.definitions.node_id_to_hir_id(k), v);
}
map
};
ResolverOutputs {
definitions: self.definitions,
cstore: Box::new(self.crate_loader.into_cstore()),
extern_crate_map: self.extern_crate_map,
export_map: self.export_map,
trait_map: self.trait_map,
trait_map,
glob_map: self.glob_map,
maybe_unused_trait_imports: self.maybe_unused_trait_imports,
maybe_unused_extern_crates: self.maybe_unused_extern_crates,
@ -1294,7 +1303,13 @@ 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.clone(),
trait_map: {
let mut map = FxHashMap::default();
for (k, v) in self.trait_map.iter() {
map.insert(self.definitions.node_id_to_hir_id(k.clone()), v.clone());
}
map
},
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(),