use crate::hir::{ModuleItems, Owner};
-use crate::ty::TyCtxt;
+use crate::ty::{DefIdTree, TyCtxt};
use rustc_ast as ast;
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
}
pub fn iter_local_def_id(self) -> impl Iterator<Item = LocalDefId> + 'hir {
- // Create a dependency to the crate to be sure we reexcute this when the amount of
+ // Create a dependency to the crate to be sure we re-execute this when the amount of
// definitions change.
self.tcx.ensure().hir_crate(());
self.tcx.untracked_resolutions.definitions.iter_local_def_id()
});
}
- pub fn ty_param_owner(self, id: HirId) -> LocalDefId {
- match self.get(id) {
- Node::Item(&Item { kind: ItemKind::Trait(..) | ItemKind::TraitAlias(..), .. }) => {
- id.expect_owner()
- }
- Node::GenericParam(_) => self.get_parent_item(id),
- _ => bug!("ty_param_owner: {} not a type parameter", self.node_to_string(id)),
+ pub fn ty_param_owner(self, def_id: LocalDefId) -> LocalDefId {
+ let def_kind = self.tcx.def_kind(def_id);
+ match def_kind {
+ DefKind::Trait | DefKind::TraitAlias => def_id,
+ DefKind::TyParam | DefKind::ConstParam => self.tcx.local_parent(def_id).unwrap(),
+ _ => bug!("ty_param_owner: {:?} is a {:?} not a type parameter", def_id, def_kind),
}
}
self.attrs(CRATE_HIR_ID)
}
+ pub fn rustc_coherence_is_core(self) -> bool {
+ self.krate_attrs().iter().any(|attr| attr.has_name(sym::rustc_coherence_is_core))
+ }
+
pub fn get_module(self, module: LocalDefId) -> (&'hir Mod<'hir>, Span, HirId) {
let hir_id = HirId::make_owner(module);
match self.tcx.hir_owner(module).map(|o| o.node) {