diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index 1a763e43d557d..eadc9ddeee6fc 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -270,7 +270,6 @@ impl<'a> ToStableHashKey> for hir::TraitCandidate { let import_keys = import_ids .iter() - .map(|node_id| hcx.node_to_hir_id(*node_id)) .map(|hir_id| (hcx.local_def_path_hash(hir_id.owner), hir_id.local_id)) .collect(); (hcx.def_path_hash(*def_id), import_keys) diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 2adf708641798..b2eb122bfeead 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -1161,6 +1161,10 @@ impl<'tcx> TyCtxt<'tcx> { for (k, v) in resolutions.trait_map { let hir_id = hir.node_to_hir_id(k); let map = trait_map.entry(hir_id.owner).or_default(); + let v = v + .into_iter() + .map(|tc| tc.map_import_ids(|id| hir.definitions().node_to_hir_id(id))) + .collect(); map.insert(hir_id.local_id, StableVec::new(v)); } diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 2bda99e6d20fc..ad51c60ab0178 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -126,7 +126,7 @@ pub struct ResolverOutputs { pub definitions: hir_map::Definitions, pub cstore: Box, pub extern_crate_map: NodeMap, - pub trait_map: TraitMap, + pub trait_map: TraitMap, pub maybe_unused_trait_imports: NodeSet, pub maybe_unused_extern_crates: Vec<(NodeId, Span)>, pub export_map: ExportMap, diff --git a/src/librustc_hir/hir.rs b/src/librustc_hir/hir.rs index c2ddaf7df316a..80b379218a5d5 100644 --- a/src/librustc_hir/hir.rs +++ b/src/librustc_hir/hir.rs @@ -16,7 +16,7 @@ use rustc_span::source_map::{SourceMap, Spanned}; use rustc_span::symbol::{kw, sym, Symbol}; use rustc_span::{MultiSpan, Span, DUMMY_SP}; use rustc_target::spec::abi::Abi; -use syntax::ast::{self, AsmDialect, CrateSugar, Ident, Name, NodeId}; +use syntax::ast::{self, AsmDialect, CrateSugar, Ident, Name}; use syntax::ast::{AttrVec, Attribute, FloatTy, IntTy, Label, LitKind, StrStyle, UintTy}; pub use syntax::ast::{BorrowKind, ImplPolarity, IsAuto}; pub use syntax::ast::{CaptureBy, Movability, Mutability}; @@ -2608,13 +2608,24 @@ pub type CaptureModeMap = NodeMap; // 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)] -pub struct TraitCandidate { +pub struct TraitCandidate { pub def_id: DefId, - pub import_ids: SmallVec<[NodeId; 1]>, + pub import_ids: SmallVec<[ID; 1]>, +} + +impl TraitCandidate { + pub fn map_import_ids(self, f: F) -> TraitCandidate + where + F: Fn(ID) -> T, + { + let TraitCandidate { def_id, import_ids } = self; + let import_ids = import_ids.into_iter().map(f).collect(); + TraitCandidate { def_id, import_ids } + } } // Trait method resolution -pub type TraitMap = NodeMap>; +pub type TraitMap = NodeMap>>; // Map from the NodeId of a glob import to a list of items which are actually // imported. diff --git a/src/librustc_resolve/late.rs b/src/librustc_resolve/late.rs index 58ff7f447890c..bcf558d1563ed 100644 --- a/src/librustc_resolve/late.rs +++ b/src/librustc_resolve/late.rs @@ -2078,7 +2078,7 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { &mut self, mut ident: Ident, ns: Namespace, - ) -> Vec { + ) -> Vec> { debug!("(getting traits containing item) looking for '{}'", ident.name); let mut found_traits = Vec::new(); @@ -2123,7 +2123,7 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { ident: Ident, ns: Namespace, module: Module<'a>, - found_traits: &mut Vec, + found_traits: &mut Vec>, ) { assert!(ns == TypeNS || ns == ValueNS); let mut traits = module.traits.borrow_mut(); diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 2e63c3e170605..4278bf867f305 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -865,7 +865,7 @@ pub struct Resolver<'a> { /// `CrateNum` resolutions of `extern crate` items. extern_crate_map: NodeMap, export_map: ExportMap, - trait_map: TraitMap, + trait_map: TraitMap, /// A map from nodes to anonymous modules. /// Anonymous modules are pseudo-modules that are implicitly created around items diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index 760b6487045d8..8f0fbc2d60c9f 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -902,13 +902,10 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { for trait_candidate in applicable_traits.iter() { let trait_did = trait_candidate.def_id; if duplicates.insert(trait_did) { - let import_ids = trait_candidate - .import_ids - .iter() - .map(|node_id| self.fcx.tcx.hir().node_to_hir_id(*node_id)) - .collect(); - let result = - self.assemble_extension_candidates_for_trait(import_ids, trait_did); + let result = self.assemble_extension_candidates_for_trait( + &trait_candidate.import_ids, + trait_did, + ); result?; } } @@ -920,7 +917,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { let mut duplicates = FxHashSet::default(); for trait_info in suggest::all_traits(self.tcx) { if duplicates.insert(trait_info.def_id) { - self.assemble_extension_candidates_for_trait(smallvec![], trait_info.def_id)?; + self.assemble_extension_candidates_for_trait(&smallvec![], trait_info.def_id)?; } } Ok(()) @@ -959,7 +956,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { fn assemble_extension_candidates_for_trait( &mut self, - import_ids: SmallVec<[hir::HirId; 1]>, + import_ids: &SmallVec<[hir::HirId; 1]>, trait_def_id: DefId, ) -> Result<(), MethodError<'tcx>> { debug!("assemble_extension_candidates_for_trait(trait_def_id={:?})", trait_def_id);