Trait impls are Items, therefore HIR owners.
This commit is contained in:
parent
f395f2ea12
commit
7dd1e8cfdf
@ -396,8 +396,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
self_ty: ref ty,
|
||||
items: ref impl_items,
|
||||
}) => {
|
||||
let def_id = self.resolver.local_def_id(id);
|
||||
|
||||
// Lower the "impl header" first. This ordering is important
|
||||
// for in-band lifetimes! Consider `'a` here:
|
||||
//
|
||||
@ -411,10 +409,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
// method, it will not be considered an in-band
|
||||
// lifetime to be added, but rather a reference to a
|
||||
// parent lifetime.
|
||||
let lowered_trait_impl_id = self.lower_node_id(id);
|
||||
let lowered_trait_def_id = self.lower_node_id(id).expect_owner();
|
||||
let (generics, (trait_ref, lowered_ty)) = self.add_in_band_defs(
|
||||
ast_generics,
|
||||
def_id,
|
||||
lowered_trait_def_id,
|
||||
AnonymousLifetimeMode::CreateParameter,
|
||||
|this, _| {
|
||||
let trait_ref = trait_ref.as_ref().map(|trait_ref| {
|
||||
@ -426,7 +424,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
this.trait_impls
|
||||
.entry(def_id)
|
||||
.or_default()
|
||||
.push(lowered_trait_impl_id);
|
||||
.push(lowered_trait_def_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,7 +108,7 @@ struct LoweringContext<'a, 'hir: 'a> {
|
||||
exported_macros: Vec<hir::MacroDef<'hir>>,
|
||||
non_exported_macro_attrs: Vec<ast::Attribute>,
|
||||
|
||||
trait_impls: BTreeMap<DefId, Vec<hir::HirId>>,
|
||||
trait_impls: BTreeMap<DefId, Vec<LocalDefId>>,
|
||||
|
||||
modules: BTreeMap<LocalDefId, hir::ModuleItems>,
|
||||
|
||||
|
@ -658,7 +658,7 @@ pub struct Crate<'hir> {
|
||||
pub impl_items: BTreeMap<ImplItemId, ImplItem<'hir>>,
|
||||
pub foreign_items: BTreeMap<ForeignItemId, ForeignItem<'hir>>,
|
||||
pub bodies: BTreeMap<BodyId, Body<'hir>>,
|
||||
pub trait_impls: BTreeMap<DefId, Vec<HirId>>,
|
||||
pub trait_impls: BTreeMap<DefId, Vec<LocalDefId>>,
|
||||
|
||||
/// A list of the body ids written out in the order in which they
|
||||
/// appear in the crate. If you're going to process all the bodies
|
||||
|
@ -361,8 +361,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
||||
.hir()
|
||||
.trait_impls(trait_did)
|
||||
.iter()
|
||||
.filter_map(|impl_node| {
|
||||
let impl_did = tcx.hir().local_def_id(*impl_node);
|
||||
.filter_map(|&impl_did| {
|
||||
match tcx.hir().get_if_local(impl_did.to_def_id()) {
|
||||
Some(Node::Item(Item {
|
||||
kind: ItemKind::Impl(hir::Impl { self_ty, .. }),
|
||||
|
@ -449,7 +449,7 @@ impl<'hir> Map<'hir> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn trait_impls(&self, trait_did: DefId) -> &'hir [HirId] {
|
||||
pub fn trait_impls(&self, trait_did: DefId) -> &'hir [LocalDefId] {
|
||||
self.tcx.all_local_trait_impls(LOCAL_CRATE).get(&trait_did).map_or(&[], |xs| &xs[..])
|
||||
}
|
||||
|
||||
|
@ -956,7 +956,7 @@ rustc_queries! {
|
||||
/// Passing in any other crate will cause an ICE.
|
||||
///
|
||||
/// [`LOCAL_CRATE`]: rustc_hir::def_id::LOCAL_CRATE
|
||||
query all_local_trait_impls(local_crate: CrateNum) -> &'tcx BTreeMap<DefId, Vec<hir::HirId>> {
|
||||
query all_local_trait_impls(local_crate: CrateNum) -> &'tcx BTreeMap<DefId, Vec<LocalDefId>> {
|
||||
desc { "local trait impls" }
|
||||
}
|
||||
|
||||
|
@ -4,9 +4,8 @@ use crate::ty::fast_reject;
|
||||
use crate::ty::fold::TypeFoldable;
|
||||
use crate::ty::{Ty, TyCtxt};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::{CrateNum, DefId};
|
||||
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId};
|
||||
use rustc_hir::definitions::DefPathHash;
|
||||
use rustc_hir::HirId;
|
||||
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
@ -201,7 +200,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
pub(super) fn all_local_trait_impls<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
krate: CrateNum,
|
||||
) -> &'tcx BTreeMap<DefId, Vec<HirId>> {
|
||||
) -> &'tcx BTreeMap<DefId, Vec<LocalDefId>> {
|
||||
&tcx.hir_crate(krate).trait_impls
|
||||
}
|
||||
|
||||
@ -229,8 +228,8 @@ pub(super) fn trait_impls_of_provider(tcx: TyCtxt<'_>, trait_id: DefId) -> Trait
|
||||
}
|
||||
}
|
||||
|
||||
for &hir_id in tcx.hir().trait_impls(trait_id) {
|
||||
let impl_def_id = tcx.hir().local_def_id(hir_id).to_def_id();
|
||||
for &impl_def_id in tcx.hir().trait_impls(trait_id) {
|
||||
let impl_def_id = impl_def_id.to_def_id();
|
||||
|
||||
let impl_self_ty = tcx.type_of(impl_def_id);
|
||||
if impl_self_ty.references_error() {
|
||||
|
@ -38,8 +38,7 @@ impl<'tcx> Checker<'tcx> {
|
||||
F: FnMut(TyCtxt<'tcx>, LocalDefId),
|
||||
{
|
||||
if Some(self.trait_def_id) == trait_def_id {
|
||||
for &impl_id in self.tcx.hir().trait_impls(self.trait_def_id) {
|
||||
let impl_def_id = self.tcx.hir().local_def_id(impl_id);
|
||||
for &impl_def_id in self.tcx.hir().trait_impls(self.trait_def_id) {
|
||||
f(self.tcx, impl_def_id);
|
||||
}
|
||||
}
|
||||
|
@ -172,8 +172,7 @@ fn coherent_trait(tcx: TyCtxt<'_>, def_id: DefId) {
|
||||
tcx.ensure().specialization_graph_of(def_id);
|
||||
|
||||
let impls = tcx.hir().trait_impls(def_id);
|
||||
for &hir_id in impls {
|
||||
let impl_def_id = tcx.hir().local_def_id(hir_id);
|
||||
for &impl_def_id in impls {
|
||||
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
|
||||
|
||||
check_impl(tcx, impl_def_id, trait_ref);
|
||||
|
@ -58,8 +58,8 @@ crate fn collect_trait_impls(krate: Crate, cx: &DocContext<'_>) -> Crate {
|
||||
// doesn't work with it anyway, so pull them from the HIR map instead
|
||||
let mut extra_attrs = Vec::new();
|
||||
for &trait_did in cx.tcx.all_traits(LOCAL_CRATE).iter() {
|
||||
for &impl_node in cx.tcx.hir().trait_impls(trait_did) {
|
||||
let impl_did = cx.tcx.hir().local_def_id(impl_node).to_def_id();
|
||||
for &impl_did in cx.tcx.hir().trait_impls(trait_did) {
|
||||
let impl_did = impl_did.to_def_id();
|
||||
cx.tcx.sess.prof.generic_activity("build_local_trait_impl").run(|| {
|
||||
let mut parent = cx.tcx.parent(impl_did);
|
||||
while let Some(did) = parent {
|
||||
|
Loading…
Reference in New Issue
Block a user