1
Fork 0

Auto merge of #81611 - cjgillot:meowner, r=estebank

Only store a LocalDefId in some HIR nodes

Some HIR nodes are guaranteed to be HIR owners: Item, TraitItem, ImplItem, ForeignItem and MacroDef.
As a consequence, we do not need to store the `HirId`'s `local_id`, and we can directly store a `LocalDefId`.

This allows to avoid a bit of the dance with `tcx.hir().local_def_id` and `tcx.hir().local_def_id_to_hir_id` mappings.
This commit is contained in:
bors 2021-02-16 22:14:32 +00:00
commit 8fe989dd76
117 changed files with 1127 additions and 1191 deletions

View file

@ -35,10 +35,10 @@ impl ItemLowerer<'_, '_, '_> {
impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> { impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> {
fn visit_mod(&mut self, m: &'a Mod, _s: Span, _attrs: &[Attribute], n: NodeId) { fn visit_mod(&mut self, m: &'a Mod, _s: Span, _attrs: &[Attribute], n: NodeId) {
let hir_id = self.lctx.lower_node_id(n); let def_id = self.lctx.lower_node_id(n).expect_owner();
self.lctx.modules.insert( self.lctx.modules.insert(
hir_id, def_id,
hir::ModuleItems { hir::ModuleItems {
items: BTreeSet::new(), items: BTreeSet::new(),
trait_items: BTreeSet::new(), trait_items: BTreeSet::new(),
@ -48,7 +48,7 @@ impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> {
); );
let old = self.lctx.current_module; let old = self.lctx.current_module;
self.lctx.current_module = hir_id; self.lctx.current_module = def_id;
visit::walk_mod(self, m); visit::walk_mod(self, m);
self.lctx.current_module = old; self.lctx.current_module = old;
} }
@ -58,8 +58,8 @@ impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> {
self.lctx.with_hir_id_owner(item.id, |lctx| { self.lctx.with_hir_id_owner(item.id, |lctx| {
lctx.without_in_scope_lifetime_defs(|lctx| { lctx.without_in_scope_lifetime_defs(|lctx| {
if let Some(hir_item) = lctx.lower_item(item) { if let Some(hir_item) = lctx.lower_item(item) {
item_hir_id = Some(hir_item.hir_id); let id = lctx.insert_item(hir_item);
lctx.insert_item(hir_item); item_hir_id = Some(id);
} }
}) })
}); });
@ -92,13 +92,13 @@ impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> {
self.lctx.with_hir_id_owner(item.id, |lctx| match ctxt { self.lctx.with_hir_id_owner(item.id, |lctx| match ctxt {
AssocCtxt::Trait => { AssocCtxt::Trait => {
let hir_item = lctx.lower_trait_item(item); let hir_item = lctx.lower_trait_item(item);
let id = hir::TraitItemId { hir_id: hir_item.hir_id }; let id = hir_item.trait_item_id();
lctx.trait_items.insert(id, hir_item); lctx.trait_items.insert(id, hir_item);
lctx.modules.get_mut(&lctx.current_module).unwrap().trait_items.insert(id); lctx.modules.get_mut(&lctx.current_module).unwrap().trait_items.insert(id);
} }
AssocCtxt::Impl => { AssocCtxt::Impl => {
let hir_item = lctx.lower_impl_item(item); let hir_item = lctx.lower_impl_item(item);
let id = hir::ImplItemId { hir_id: hir_item.hir_id }; let id = hir_item.impl_item_id();
lctx.impl_items.insert(id, hir_item); lctx.impl_items.insert(id, hir_item);
lctx.modules.get_mut(&lctx.current_module).unwrap().impl_items.insert(id); lctx.modules.get_mut(&lctx.current_module).unwrap().impl_items.insert(id);
} }
@ -111,7 +111,7 @@ impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> {
self.lctx.allocate_hir_id_counter(item.id); self.lctx.allocate_hir_id_counter(item.id);
self.lctx.with_hir_id_owner(item.id, |lctx| { self.lctx.with_hir_id_owner(item.id, |lctx| {
let hir_item = lctx.lower_foreign_item(item); let hir_item = lctx.lower_foreign_item(item);
let id = hir::ForeignItemId { hir_id: hir_item.hir_id }; let id = hir_item.foreign_item_id();
lctx.foreign_items.insert(id, hir_item); lctx.foreign_items.insert(id, hir_item);
lctx.modules.get_mut(&lctx.current_module).unwrap().foreign_items.insert(id); lctx.modules.get_mut(&lctx.current_module).unwrap().foreign_items.insert(id);
}); });
@ -128,7 +128,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
// only used when lowering a child item of a trait or impl. // only used when lowering a child item of a trait or impl.
fn with_parent_item_lifetime_defs<T>( fn with_parent_item_lifetime_defs<T>(
&mut self, &mut self,
parent_hir_id: hir::HirId, parent_hir_id: hir::ItemId,
f: impl FnOnce(&mut LoweringContext<'_, '_>) -> T, f: impl FnOnce(&mut LoweringContext<'_, '_>) -> T,
) -> T { ) -> T {
let old_len = self.in_scope_lifetimes.len(); let old_len = self.in_scope_lifetimes.len();
@ -197,7 +197,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
node_ids node_ids
.into_iter() .into_iter()
.map(|node_id| hir::ItemId { id: self.allocate_hir_id_counter(node_id) }) .map(|node_id| hir::ItemId {
def_id: self.allocate_hir_id_counter(node_id).expect_owner(),
})
.collect() .collect()
} }
@ -232,13 +234,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
if let ItemKind::MacroDef(MacroDef { ref body, macro_rules }) = i.kind { if let ItemKind::MacroDef(MacroDef { ref body, macro_rules }) = i.kind {
if !macro_rules || self.sess.contains_name(&i.attrs, sym::macro_export) { if !macro_rules || self.sess.contains_name(&i.attrs, sym::macro_export) {
let hir_id = self.lower_node_id(i.id); let def_id = self.lower_node_id(i.id).expect_owner();
let body = P(self.lower_mac_args(body)); let body = P(self.lower_mac_args(body));
self.exported_macros.push(hir::MacroDef { self.exported_macros.push(hir::MacroDef {
ident, ident,
vis, vis,
attrs, attrs,
hir_id, def_id,
span: i.span, span: i.span,
ast: MacroDef { body, macro_rules }, ast: MacroDef { body, macro_rules },
}); });
@ -250,7 +252,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
let kind = self.lower_item_kind(i.span, i.id, &mut ident, attrs, &mut vis, &i.kind); let kind = self.lower_item_kind(i.span, i.id, &mut ident, attrs, &mut vis, &i.kind);
Some(hir::Item { hir_id: self.lower_node_id(i.id), ident, attrs, kind, vis, span: i.span }) Some(hir::Item {
def_id: self.lower_node_id(i.id).expect_owner(),
ident,
attrs,
kind,
vis,
span: i.span,
})
} }
fn lower_item_kind( fn lower_item_kind(
@ -387,8 +396,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
self_ty: ref ty, self_ty: ref ty,
items: ref impl_items, items: ref impl_items,
}) => { }) => {
let def_id = self.resolver.local_def_id(id);
// Lower the "impl header" first. This ordering is important // Lower the "impl header" first. This ordering is important
// for in-band lifetimes! Consider `'a` here: // for in-band lifetimes! Consider `'a` here:
// //
@ -402,10 +409,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
// method, it will not be considered an in-band // method, it will not be considered an in-band
// lifetime to be added, but rather a reference to a // lifetime to be added, but rather a reference to a
// parent lifetime. // 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( let (generics, (trait_ref, lowered_ty)) = self.add_in_band_defs(
ast_generics, ast_generics,
def_id, lowered_trait_def_id,
AnonymousLifetimeMode::CreateParameter, AnonymousLifetimeMode::CreateParameter,
|this, _| { |this, _| {
let trait_ref = trait_ref.as_ref().map(|trait_ref| { let trait_ref = trait_ref.as_ref().map(|trait_ref| {
@ -417,7 +424,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
this.trait_impls this.trait_impls
.entry(def_id) .entry(def_id)
.or_default() .or_default()
.push(lowered_trait_impl_id); .push(lowered_trait_def_id);
} }
} }
@ -557,7 +564,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let vis = this.rebuild_vis(&vis); let vis = this.rebuild_vis(&vis);
this.insert_item(hir::Item { this.insert_item(hir::Item {
hir_id: new_id, def_id: new_id.expect_owner(),
ident, ident,
attrs, attrs,
kind, kind,
@ -629,7 +636,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
this.lower_use_tree(use_tree, &prefix, id, &mut vis, &mut ident, attrs); this.lower_use_tree(use_tree, &prefix, id, &mut vis, &mut ident, attrs);
this.insert_item(hir::Item { this.insert_item(hir::Item {
hir_id: new_hir_id, def_id: new_hir_id.expect_owner(),
ident, ident,
attrs, attrs,
kind, kind,
@ -702,7 +709,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
fn lower_foreign_item(&mut self, i: &ForeignItem) -> hir::ForeignItem<'hir> { fn lower_foreign_item(&mut self, i: &ForeignItem) -> hir::ForeignItem<'hir> {
let def_id = self.resolver.local_def_id(i.id); let def_id = self.resolver.local_def_id(i.id);
hir::ForeignItem { hir::ForeignItem {
hir_id: self.lower_node_id(i.id), def_id,
ident: i.ident, ident: i.ident,
attrs: self.lower_attrs(&i.attrs), attrs: self.lower_attrs(&i.attrs),
kind: match i.kind { kind: match i.kind {
@ -737,7 +744,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
fn lower_foreign_item_ref(&mut self, i: &ForeignItem) -> hir::ForeignItemRef<'hir> { fn lower_foreign_item_ref(&mut self, i: &ForeignItem) -> hir::ForeignItemRef<'hir> {
hir::ForeignItemRef { hir::ForeignItemRef {
id: hir::ForeignItemId { hir_id: self.lower_node_id(i.id) }, id: hir::ForeignItemId { def_id: self.lower_node_id(i.id).expect_owner() },
ident: i.ident, ident: i.ident,
span: i.span, span: i.span,
vis: self.lower_visibility(&i.vis, Some(i.id)), vis: self.lower_visibility(&i.vis, Some(i.id)),
@ -837,7 +844,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}; };
hir::TraitItem { hir::TraitItem {
hir_id: self.lower_node_id(i.id), def_id: trait_item_def_id,
ident: i.ident, ident: i.ident,
attrs: self.lower_attrs(&i.attrs), attrs: self.lower_attrs(&i.attrs),
generics, generics,
@ -857,7 +864,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
} }
AssocItemKind::MacCall(..) => unimplemented!(), AssocItemKind::MacCall(..) => unimplemented!(),
}; };
let id = hir::TraitItemId { hir_id: self.lower_node_id(i.id) }; let id = hir::TraitItemId { def_id: self.lower_node_id(i.id).expect_owner() };
let defaultness = hir::Defaultness::Default { has_value: has_default }; let defaultness = hir::Defaultness::Default { has_value: has_default };
hir::TraitItemRef { id, ident: i.ident, span: i.span, defaultness, kind } hir::TraitItemRef { id, ident: i.ident, span: i.span, defaultness, kind }
} }
@ -922,7 +929,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let has_value = true; let has_value = true;
let (defaultness, _) = self.lower_defaultness(i.kind.defaultness(), has_value); let (defaultness, _) = self.lower_defaultness(i.kind.defaultness(), has_value);
hir::ImplItem { hir::ImplItem {
hir_id: self.lower_node_id(i.id), def_id: self.lower_node_id(i.id).expect_owner(),
ident: i.ident, ident: i.ident,
attrs: self.lower_attrs(&i.attrs), attrs: self.lower_attrs(&i.attrs),
generics, generics,
@ -938,7 +945,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let has_value = true; let has_value = true;
let (defaultness, _) = self.lower_defaultness(i.kind.defaultness(), has_value); let (defaultness, _) = self.lower_defaultness(i.kind.defaultness(), has_value);
hir::ImplItemRef { hir::ImplItemRef {
id: hir::ImplItemId { hir_id: self.lower_node_id(i.id) }, id: hir::ImplItemId { def_id: self.lower_node_id(i.id).expect_owner() },
ident: i.ident, ident: i.ident,
span: i.span, span: i.span,
vis: self.lower_visibility(&i.vis, Some(i.id)), vis: self.lower_visibility(&i.vis, Some(i.id)),

View file

@ -48,7 +48,7 @@ use rustc_data_structures::sync::Lrc;
use rustc_errors::struct_span_err; use rustc_errors::struct_span_err;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::{DefKind, Namespace, PartialRes, PerNS, Res}; use rustc_hir::def::{DefKind, Namespace, PartialRes, PerNS, Res};
use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId, CRATE_DEF_INDEX}; use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId, CRATE_DEF_ID};
use rustc_hir::definitions::{DefKey, DefPathData, Definitions}; use rustc_hir::definitions::{DefKey, DefPathData, Definitions};
use rustc_hir::intravisit; use rustc_hir::intravisit;
use rustc_hir::{ConstArg, GenericArg, ParamName}; use rustc_hir::{ConstArg, GenericArg, ParamName};
@ -99,7 +99,7 @@ struct LoweringContext<'a, 'hir: 'a> {
arena: &'hir Arena<'hir>, arena: &'hir Arena<'hir>,
/// The items being lowered are collected here. /// The items being lowered are collected here.
items: BTreeMap<hir::HirId, hir::Item<'hir>>, items: BTreeMap<hir::ItemId, hir::Item<'hir>>,
trait_items: BTreeMap<hir::TraitItemId, hir::TraitItem<'hir>>, trait_items: BTreeMap<hir::TraitItemId, hir::TraitItem<'hir>>,
impl_items: BTreeMap<hir::ImplItemId, hir::ImplItem<'hir>>, impl_items: BTreeMap<hir::ImplItemId, hir::ImplItem<'hir>>,
@ -108,9 +108,9 @@ struct LoweringContext<'a, 'hir: 'a> {
exported_macros: Vec<hir::MacroDef<'hir>>, exported_macros: Vec<hir::MacroDef<'hir>>,
non_exported_macro_attrs: Vec<ast::Attribute>, non_exported_macro_attrs: Vec<ast::Attribute>,
trait_impls: BTreeMap<DefId, Vec<hir::HirId>>, trait_impls: BTreeMap<DefId, Vec<LocalDefId>>,
modules: BTreeMap<hir::HirId, hir::ModuleItems>, modules: BTreeMap<LocalDefId, hir::ModuleItems>,
generator_kind: Option<hir::GeneratorKind>, generator_kind: Option<hir::GeneratorKind>,
@ -158,7 +158,7 @@ struct LoweringContext<'a, 'hir: 'a> {
/// vector. /// vector.
in_scope_lifetimes: Vec<ParamName>, in_scope_lifetimes: Vec<ParamName>,
current_module: hir::HirId, current_module: LocalDefId,
type_def_lifetime_params: DefIdMap<usize>, type_def_lifetime_params: DefIdMap<usize>,
@ -314,8 +314,8 @@ pub fn lower_crate<'a, 'hir>(
is_in_dyn_type: false, is_in_dyn_type: false,
anonymous_lifetime_mode: AnonymousLifetimeMode::PassThrough, anonymous_lifetime_mode: AnonymousLifetimeMode::PassThrough,
type_def_lifetime_params: Default::default(), type_def_lifetime_params: Default::default(),
current_module: hir::CRATE_HIR_ID, current_module: CRATE_DEF_ID,
current_hir_id_owner: vec![(LocalDefId { local_def_index: CRATE_DEF_INDEX }, 0)], current_hir_id_owner: vec![(CRATE_DEF_ID, 0)],
item_local_id_counters: Default::default(), item_local_id_counters: Default::default(),
node_id_to_hir_id: IndexVec::new(), node_id_to_hir_id: IndexVec::new(),
generator_kind: None, generator_kind: None,
@ -605,12 +605,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
} }
} }
fn insert_item(&mut self, item: hir::Item<'hir>) { fn insert_item(&mut self, item: hir::Item<'hir>) -> hir::ItemId {
let id = item.hir_id; let id = hir::ItemId { def_id: item.def_id };
// FIXME: Use `debug_asset-rt`.
assert_eq!(id.local_id, hir::ItemLocalId::from_u32(0));
self.items.insert(id, item); self.items.insert(id, item);
self.modules.get_mut(&self.current_module).unwrap().items.insert(id); self.modules.get_mut(&self.current_module).unwrap().items.insert(id);
id
} }
fn allocate_hir_id_counter(&mut self, owner: NodeId) -> hir::HirId { fn allocate_hir_id_counter(&mut self, owner: NodeId) -> hir::HirId {
@ -1547,11 +1546,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}; };
trace!("lower_opaque_impl_trait: {:#?}", opaque_ty_def_id); trace!("lower_opaque_impl_trait: {:#?}", opaque_ty_def_id);
let opaque_ty_id = lctx.generate_opaque_type(opaque_ty_def_id, opaque_ty_item, span, opaque_ty_span);
lctx.generate_opaque_type(opaque_ty_node_id, opaque_ty_item, span, opaque_ty_span);
// `impl Trait` now just becomes `Foo<'a, 'b, ..>`. // `impl Trait` now just becomes `Foo<'a, 'b, ..>`.
hir::TyKind::OpaqueDef(hir::ItemId { id: opaque_ty_id }, lifetimes) hir::TyKind::OpaqueDef(hir::ItemId { def_id: opaque_ty_def_id }, lifetimes)
}) })
} }
@ -1559,17 +1557,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
/// returns the lowered node-ID for the opaque type. /// returns the lowered node-ID for the opaque type.
fn generate_opaque_type( fn generate_opaque_type(
&mut self, &mut self,
opaque_ty_node_id: NodeId, opaque_ty_id: LocalDefId,
opaque_ty_item: hir::OpaqueTy<'hir>, opaque_ty_item: hir::OpaqueTy<'hir>,
span: Span, span: Span,
opaque_ty_span: Span, opaque_ty_span: Span,
) -> hir::HirId { ) {
let opaque_ty_item_kind = hir::ItemKind::OpaqueTy(opaque_ty_item); let opaque_ty_item_kind = hir::ItemKind::OpaqueTy(opaque_ty_item);
let opaque_ty_id = self.lower_node_id(opaque_ty_node_id);
// Generate an `type Foo = impl Trait;` declaration. // Generate an `type Foo = impl Trait;` declaration.
trace!("registering opaque type with id {:#?}", opaque_ty_id); trace!("registering opaque type with id {:#?}", opaque_ty_id);
let opaque_ty_item = hir::Item { let opaque_ty_item = hir::Item {
hir_id: opaque_ty_id, def_id: opaque_ty_id,
ident: Ident::invalid(), ident: Ident::invalid(),
attrs: Default::default(), attrs: Default::default(),
kind: opaque_ty_item_kind, kind: opaque_ty_item_kind,
@ -1581,7 +1578,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// automatically for all AST items. But this opaque type item // automatically for all AST items. But this opaque type item
// does not actually exist in the AST. // does not actually exist in the AST.
self.insert_item(opaque_ty_item); self.insert_item(opaque_ty_item);
opaque_ty_id
} }
fn lifetimes_from_impl_trait_bounds( fn lifetimes_from_impl_trait_bounds(
@ -2010,7 +2006,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// grow. // grow.
let input_lifetimes_count = self.in_scope_lifetimes.len() + self.lifetimes_to_define.len(); let input_lifetimes_count = self.in_scope_lifetimes.len() + self.lifetimes_to_define.len();
let (opaque_ty_id, lifetime_params) = self.with_hir_id_owner(opaque_ty_node_id, |this| { let lifetime_params = self.with_hir_id_owner(opaque_ty_node_id, |this| {
// We have to be careful to get elision right here. The // We have to be careful to get elision right here. The
// idea is that we create a lifetime parameter for each // idea is that we create a lifetime parameter for each
// lifetime in the return type. So, given a return type // lifetime in the return type. So, given a return type
@ -2061,10 +2057,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}; };
trace!("exist ty from async fn def id: {:#?}", opaque_ty_def_id); trace!("exist ty from async fn def id: {:#?}", opaque_ty_def_id);
let opaque_ty_id = this.generate_opaque_type(opaque_ty_def_id, opaque_ty_item, span, opaque_ty_span);
this.generate_opaque_type(opaque_ty_node_id, opaque_ty_item, span, opaque_ty_span);
(opaque_ty_id, lifetime_params) lifetime_params
}); });
// As documented above on the variable // As documented above on the variable
@ -2107,7 +2102,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// Foo = impl Trait` is, internally, created as a child of the // Foo = impl Trait` is, internally, created as a child of the
// async fn, so the *type parameters* are inherited. It's // async fn, so the *type parameters* are inherited. It's
// only the lifetime parameters that we must supply. // only the lifetime parameters that we must supply.
let opaque_ty_ref = hir::TyKind::OpaqueDef(hir::ItemId { id: opaque_ty_id }, generic_args); let opaque_ty_ref =
hir::TyKind::OpaqueDef(hir::ItemId { def_id: opaque_ty_def_id }, generic_args);
let opaque_ty = self.ty(opaque_ty_span, opaque_ty_ref); let opaque_ty = self.ty(opaque_ty_span, opaque_ty_ref);
hir::FnRetTy::Return(self.arena.alloc(opaque_ty)) hir::FnRetTy::Return(self.arena.alloc(opaque_ty))
} }
@ -2432,7 +2428,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let mut ids: SmallVec<[hir::Stmt<'hir>; 1]> = item_ids let mut ids: SmallVec<[hir::Stmt<'hir>; 1]> = item_ids
.into_iter() .into_iter()
.map(|item_id| { .map(|item_id| {
let item_id = hir::ItemId { id: self.lower_node_id(item_id) }; let item_id = hir::ItemId {
// All the items that `lower_local` finds are `impl Trait` types.
def_id: self.lower_node_id(item_id).expect_owner(),
};
self.stmt(s.span, hir::StmtKind::Item(item_id)) self.stmt(s.span, hir::StmtKind::Item(item_id))
}) })
.collect(); .collect();

View file

@ -164,8 +164,8 @@ fn module_codegen(tcx: TyCtxt<'_>, cgu_name: rustc_span::Symbol) -> ModuleCodege
MonoItem::Static(def_id) => { MonoItem::Static(def_id) => {
crate::constant::codegen_static(&mut cx.constants_cx, def_id) crate::constant::codegen_static(&mut cx.constants_cx, def_id)
} }
MonoItem::GlobalAsm(hir_id) => { MonoItem::GlobalAsm(item_id) => {
let item = cx.tcx.hir().expect_item(hir_id); let item = cx.tcx.hir().item(item_id);
if let rustc_hir::ItemKind::GlobalAsm(rustc_hir::GlobalAsm { asm }) = item.kind { if let rustc_hir::ItemKind::GlobalAsm(rustc_hir::GlobalAsm { asm }) = item.kind {
cx.global_asm.push_str(&*asm.as_str()); cx.global_asm.push_str(&*asm.as_str());
cx.global_asm.push_str("\n\n"); cx.global_asm.push_str("\n\n");

View file

@ -93,10 +93,9 @@ pub(super) fn run_jit(tcx: TyCtxt<'_>, codegen_mode: CodegenMode) -> ! {
MonoItem::Static(def_id) => { MonoItem::Static(def_id) => {
crate::constant::codegen_static(&mut cx.constants_cx, def_id); crate::constant::codegen_static(&mut cx.constants_cx, def_id);
} }
MonoItem::GlobalAsm(hir_id) => { MonoItem::GlobalAsm(item_id) => {
let item = cx.tcx.hir().expect_item(hir_id); let item = cx.tcx.hir().item(item_id);
tcx.sess tcx.sess.span_fatal(item.span, "Global asm is not supported in JIT mode");
.span_fatal(item.span, "Global asm is not supported in JIT mode");
} }
} }
} }

View file

@ -30,8 +30,8 @@ impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> {
MonoItem::Static(def_id) => { MonoItem::Static(def_id) => {
cx.codegen_static(def_id, cx.tcx().is_mutable_static(def_id)); cx.codegen_static(def_id, cx.tcx().is_mutable_static(def_id));
} }
MonoItem::GlobalAsm(hir_id) => { MonoItem::GlobalAsm(item_id) => {
let item = cx.tcx().hir().expect_item(hir_id); let item = cx.tcx().hir().item(item_id);
if let hir::ItemKind::GlobalAsm(ref ga) = item.kind { if let hir::ItemKind::GlobalAsm(ref ga) = item.kind {
cx.codegen_global_asm(ga); cx.codegen_global_asm(ga);
} else { } else {

View file

@ -237,7 +237,7 @@ impl<'hir> pprust_hir::PpAnn for IdentifiedAnnotation<'hir> {
pprust_hir::AnnNode::Name(_) => {} pprust_hir::AnnNode::Name(_) => {}
pprust_hir::AnnNode::Item(item) => { pprust_hir::AnnNode::Item(item) => {
s.s.space(); s.s.space();
s.synth_comment(format!("hir_id: {}", item.hir_id)); s.synth_comment(format!("hir_id: {}", item.hir_id()));
} }
pprust_hir::AnnNode::SubItem(id) => { pprust_hir::AnnNode::SubItem(id) => {
s.s.space(); s.s.space();

View file

@ -619,7 +619,7 @@ pub struct WhereEqPredicate<'hir> {
pub struct ModuleItems { pub struct ModuleItems {
// Use BTreeSets here so items are in the same order as in the // Use BTreeSets here so items are in the same order as in the
// list of all items in Crate // list of all items in Crate
pub items: BTreeSet<HirId>, pub items: BTreeSet<ItemId>,
pub trait_items: BTreeSet<TraitItemId>, pub trait_items: BTreeSet<TraitItemId>,
pub impl_items: BTreeSet<ImplItemId>, pub impl_items: BTreeSet<ImplItemId>,
pub foreign_items: BTreeSet<ForeignItemId>, pub foreign_items: BTreeSet<ForeignItemId>,
@ -652,13 +652,13 @@ pub struct Crate<'hir> {
// does, because it can affect the order in which errors are // does, because it can affect the order in which errors are
// detected, which in turn can make UI tests yield // detected, which in turn can make UI tests yield
// slightly different results. // slightly different results.
pub items: BTreeMap<HirId, Item<'hir>>, pub items: BTreeMap<ItemId, Item<'hir>>,
pub trait_items: BTreeMap<TraitItemId, TraitItem<'hir>>, pub trait_items: BTreeMap<TraitItemId, TraitItem<'hir>>,
pub impl_items: BTreeMap<ImplItemId, ImplItem<'hir>>, pub impl_items: BTreeMap<ImplItemId, ImplItem<'hir>>,
pub foreign_items: BTreeMap<ForeignItemId, ForeignItem<'hir>>, pub foreign_items: BTreeMap<ForeignItemId, ForeignItem<'hir>>,
pub bodies: BTreeMap<BodyId, Body<'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 /// 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 /// appear in the crate. If you're going to process all the bodies
@ -668,7 +668,7 @@ pub struct Crate<'hir> {
/// A list of modules written out in the order in which they /// A list of modules written out in the order in which they
/// appear in the crate. This includes the main crate module. /// appear in the crate. This includes the main crate module.
pub modules: BTreeMap<HirId, ModuleItems>, pub modules: BTreeMap<LocalDefId, ModuleItems>,
/// A list of proc macro HirIds, written out in the order in which /// 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. /// they are declared in the static array generated by proc_macro_harness.
pub proc_macros: Vec<HirId>, pub proc_macros: Vec<HirId>,
@ -677,7 +677,7 @@ pub struct Crate<'hir> {
} }
impl Crate<'hir> { impl Crate<'hir> {
pub fn item(&self, id: HirId) -> &Item<'hir> { pub fn item(&self, id: ItemId) -> &Item<'hir> {
&self.items[&id] &self.items[&id]
} }
@ -761,16 +761,22 @@ impl Crate<'_> {
/// A macro definition, in this crate or imported from another. /// A macro definition, in this crate or imported from another.
/// ///
/// Not parsed directly, but created on macro import or `macro_rules!` expansion. /// Not parsed directly, but created on macro import or `macro_rules!` expansion.
#[derive(Debug, HashStable_Generic)] #[derive(Debug)]
pub struct MacroDef<'hir> { pub struct MacroDef<'hir> {
pub ident: Ident, pub ident: Ident,
pub vis: Visibility<'hir>, pub vis: Visibility<'hir>,
pub attrs: &'hir [Attribute], pub attrs: &'hir [Attribute],
pub hir_id: HirId, pub def_id: LocalDefId,
pub span: Span, pub span: Span,
pub ast: ast::MacroDef, pub ast: ast::MacroDef,
} }
impl MacroDef<'_> {
pub fn hir_id(&self) -> HirId {
HirId::make_owner(self.def_id)
}
}
/// A block of statements `{ .. }`, which may have a label (in this case the /// A block of statements `{ .. }`, which may have a label (in this case the
/// `targeted_by_break` field will be `true`) and may be `unsafe` by means of /// `targeted_by_break` field will be `true`) and may be `unsafe` by means of
/// the `rules` being anything but `DefaultBlock`. /// the `rules` being anything but `DefaultBlock`.
@ -1413,10 +1419,6 @@ pub struct Expr<'hir> {
pub span: Span, pub span: Span,
} }
// `Expr` is used a lot. Make sure it doesn't unintentionally get bigger.
#[cfg(target_arch = "x86_64")]
rustc_data_structures::static_assert_size!(Expr<'static>, 72);
impl Expr<'_> { impl Expr<'_> {
pub fn precedence(&self) -> ExprPrecedence { pub fn precedence(&self) -> ExprPrecedence {
match self.kind { match self.kind {
@ -1911,7 +1913,14 @@ pub struct FnSig<'hir> {
// so it can fetched later. // so it can fetched later.
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Encodable, Debug)] #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Encodable, Debug)]
pub struct TraitItemId { pub struct TraitItemId {
pub hir_id: HirId, pub def_id: LocalDefId,
}
impl TraitItemId {
pub fn hir_id(&self) -> HirId {
// Items are always HIR owners.
HirId::make_owner(self.def_id)
}
} }
/// Represents an item declaration within a trait declaration, /// Represents an item declaration within a trait declaration,
@ -1921,13 +1930,24 @@ pub struct TraitItemId {
#[derive(Debug)] #[derive(Debug)]
pub struct TraitItem<'hir> { pub struct TraitItem<'hir> {
pub ident: Ident, pub ident: Ident,
pub hir_id: HirId, pub def_id: LocalDefId,
pub attrs: &'hir [Attribute], pub attrs: &'hir [Attribute],
pub generics: Generics<'hir>, pub generics: Generics<'hir>,
pub kind: TraitItemKind<'hir>, pub kind: TraitItemKind<'hir>,
pub span: Span, pub span: Span,
} }
impl TraitItem<'_> {
pub fn hir_id(&self) -> HirId {
// Items are always HIR owners.
HirId::make_owner(self.def_id)
}
pub fn trait_item_id(&self) -> TraitItemId {
TraitItemId { def_id: self.def_id }
}
}
/// Represents a trait method's body (or just argument names). /// Represents a trait method's body (or just argument names).
#[derive(Encodable, Debug, HashStable_Generic)] #[derive(Encodable, Debug, HashStable_Generic)]
pub enum TraitFn<'hir> { pub enum TraitFn<'hir> {
@ -1955,14 +1975,21 @@ pub enum TraitItemKind<'hir> {
// so it can fetched later. // so it can fetched later.
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Encodable, Debug)] #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Encodable, Debug)]
pub struct ImplItemId { pub struct ImplItemId {
pub hir_id: HirId, pub def_id: LocalDefId,
}
impl ImplItemId {
pub fn hir_id(&self) -> HirId {
// Items are always HIR owners.
HirId::make_owner(self.def_id)
}
} }
/// Represents anything within an `impl` block. /// Represents anything within an `impl` block.
#[derive(Debug)] #[derive(Debug)]
pub struct ImplItem<'hir> { pub struct ImplItem<'hir> {
pub ident: Ident, pub ident: Ident,
pub hir_id: HirId, pub def_id: LocalDefId,
pub vis: Visibility<'hir>, pub vis: Visibility<'hir>,
pub defaultness: Defaultness, pub defaultness: Defaultness,
pub attrs: &'hir [Attribute], pub attrs: &'hir [Attribute],
@ -1971,6 +1998,17 @@ pub struct ImplItem<'hir> {
pub span: Span, pub span: Span,
} }
impl ImplItem<'_> {
pub fn hir_id(&self) -> HirId {
// Items are always HIR owners.
HirId::make_owner(self.def_id)
}
pub fn impl_item_id(&self) -> ImplItemId {
ImplItemId { def_id: self.def_id }
}
}
/// Represents various kinds of content within an `impl`. /// Represents various kinds of content within an `impl`.
#[derive(Debug, HashStable_Generic)] #[derive(Debug, HashStable_Generic)]
pub enum ImplItemKind<'hir> { pub enum ImplItemKind<'hir> {
@ -2545,9 +2583,16 @@ impl VariantData<'hir> {
// The bodies for items are stored "out of line", in a separate // The bodies for items are stored "out of line", in a separate
// hashmap in the `Crate`. Here we just record the hir-id of the item // hashmap in the `Crate`. Here we just record the hir-id of the item
// so it can fetched later. // so it can fetched later.
#[derive(Copy, Clone, Encodable, Debug)] #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Encodable, Debug, Hash)]
pub struct ItemId { pub struct ItemId {
pub id: HirId, pub def_id: LocalDefId,
}
impl ItemId {
pub fn hir_id(&self) -> HirId {
// Items are always HIR owners.
HirId::make_owner(self.def_id)
}
} }
/// An item /// An item
@ -2556,13 +2601,24 @@ pub struct ItemId {
#[derive(Debug)] #[derive(Debug)]
pub struct Item<'hir> { pub struct Item<'hir> {
pub ident: Ident, pub ident: Ident,
pub hir_id: HirId, pub def_id: LocalDefId,
pub attrs: &'hir [Attribute], pub attrs: &'hir [Attribute],
pub kind: ItemKind<'hir>, pub kind: ItemKind<'hir>,
pub vis: Visibility<'hir>, pub vis: Visibility<'hir>,
pub span: Span, pub span: Span,
} }
impl Item<'_> {
pub fn hir_id(&self) -> HirId {
// Items are always HIR owners.
HirId::make_owner(self.def_id)
}
pub fn item_id(&self) -> ItemId {
ItemId { def_id: self.def_id }
}
}
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[derive(Encodable, Decodable, HashStable_Generic)] #[derive(Encodable, Decodable, HashStable_Generic)]
pub enum Unsafety { pub enum Unsafety {
@ -2733,7 +2789,14 @@ pub enum AssocItemKind {
// so it can fetched later. // so it can fetched later.
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Encodable, Debug)] #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Encodable, Debug)]
pub struct ForeignItemId { pub struct ForeignItemId {
pub hir_id: HirId, pub def_id: LocalDefId,
}
impl ForeignItemId {
pub fn hir_id(&self) -> HirId {
// Items are always HIR owners.
HirId::make_owner(self.def_id)
}
} }
/// A reference from a foreign block to one of its items. This /// A reference from a foreign block to one of its items. This
@ -2751,17 +2814,27 @@ pub struct ForeignItemRef<'hir> {
pub vis: Visibility<'hir>, pub vis: Visibility<'hir>,
} }
#[derive(Debug, HashStable_Generic)] #[derive(Debug)]
pub struct ForeignItem<'hir> { pub struct ForeignItem<'hir> {
#[stable_hasher(project(name))]
pub ident: Ident, pub ident: Ident,
pub attrs: &'hir [Attribute], pub attrs: &'hir [Attribute],
pub kind: ForeignItemKind<'hir>, pub kind: ForeignItemKind<'hir>,
pub hir_id: HirId, pub def_id: LocalDefId,
pub span: Span, pub span: Span,
pub vis: Visibility<'hir>, pub vis: Visibility<'hir>,
} }
impl ForeignItem<'_> {
pub fn hir_id(&self) -> HirId {
// Items are always HIR owners.
HirId::make_owner(self.def_id)
}
pub fn foreign_item_id(&self) -> ForeignItemId {
ForeignItemId { def_id: self.def_id }
}
}
/// An item within an `extern` block. /// An item within an `extern` block.
#[derive(Debug, HashStable_Generic)] #[derive(Debug, HashStable_Generic)]
pub enum ForeignItemKind<'hir> { pub enum ForeignItemKind<'hir> {
@ -2871,11 +2944,12 @@ impl<'hir> Node<'hir> {
pub fn hir_id(&self) -> Option<HirId> { pub fn hir_id(&self) -> Option<HirId> {
match self { match self {
Node::Item(Item { hir_id, .. }) Node::Item(Item { def_id, .. })
| Node::ForeignItem(ForeignItem { hir_id, .. }) | Node::TraitItem(TraitItem { def_id, .. })
| Node::TraitItem(TraitItem { hir_id, .. }) | Node::ImplItem(ImplItem { def_id, .. })
| Node::ImplItem(ImplItem { hir_id, .. }) | Node::ForeignItem(ForeignItem { def_id, .. })
| Node::Field(StructField { hir_id, .. }) | Node::MacroDef(MacroDef { def_id, .. }) => Some(HirId::make_owner(*def_id)),
Node::Field(StructField { hir_id, .. })
| Node::AnonConst(AnonConst { hir_id, .. }) | Node::AnonConst(AnonConst { hir_id, .. })
| Node::Expr(Expr { hir_id, .. }) | Node::Expr(Expr { hir_id, .. })
| Node::Stmt(Stmt { hir_id, .. }) | Node::Stmt(Stmt { hir_id, .. })
@ -2885,7 +2959,6 @@ impl<'hir> Node<'hir> {
| Node::Arm(Arm { hir_id, .. }) | Node::Arm(Arm { hir_id, .. })
| Node::Block(Block { hir_id, .. }) | Node::Block(Block { hir_id, .. })
| Node::Local(Local { hir_id, .. }) | Node::Local(Local { hir_id, .. })
| Node::MacroDef(MacroDef { hir_id, .. })
| Node::Lifetime(Lifetime { hir_id, .. }) | Node::Lifetime(Lifetime { hir_id, .. })
| Node::Param(Param { hir_id, .. }) | Node::Param(Param { hir_id, .. })
| Node::GenericParam(GenericParam { hir_id, .. }) => Some(*hir_id), | Node::GenericParam(GenericParam { hir_id, .. }) => Some(*hir_id),
@ -2897,3 +2970,18 @@ impl<'hir> Node<'hir> {
} }
} }
} }
// Some nodes are used a lot. Make sure they don't unintentionally get bigger.
#[cfg(target_arch = "x86_64")]
mod size_asserts {
rustc_data_structures::static_assert_size!(super::Block<'static>, 48);
rustc_data_structures::static_assert_size!(super::Expr<'static>, 72);
rustc_data_structures::static_assert_size!(super::Pat<'static>, 88);
rustc_data_structures::static_assert_size!(super::QPath<'static>, 24);
rustc_data_structures::static_assert_size!(super::Ty<'static>, 72);
rustc_data_structures::static_assert_size!(super::Item<'static>, 200);
rustc_data_structures::static_assert_size!(super::TraitItem<'static>, 144);
rustc_data_structures::static_assert_size!(super::ImplItem<'static>, 168);
rustc_data_structures::static_assert_size!(super::ForeignItem<'static>, 152);
}

View file

@ -18,6 +18,21 @@ pub struct HirId {
pub local_id: ItemLocalId, pub local_id: ItemLocalId,
} }
impl HirId {
pub fn expect_owner(self) -> LocalDefId {
assert_eq!(self.local_id.index(), 0);
self.owner
}
pub fn as_owner(self) -> Option<LocalDefId> {
if self.local_id.index() == 0 { Some(self.owner) } else { None }
}
pub fn make_owner(owner: LocalDefId) -> Self {
Self { owner, local_id: ItemLocalId::from_u32(0) }
}
}
impl fmt::Display for HirId { impl fmt::Display for HirId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self) write!(f, "{:?}", self)

View file

@ -133,7 +133,7 @@ pub trait Map<'hir> {
/// Retrieves the `Node` corresponding to `id`, returning `None` if cannot be found. /// Retrieves the `Node` corresponding to `id`, returning `None` if cannot be found.
fn find(&self, hir_id: HirId) -> Option<Node<'hir>>; fn find(&self, hir_id: HirId) -> Option<Node<'hir>>;
fn body(&self, id: BodyId) -> &'hir Body<'hir>; fn body(&self, id: BodyId) -> &'hir Body<'hir>;
fn item(&self, id: HirId) -> &'hir Item<'hir>; fn item(&self, id: ItemId) -> &'hir Item<'hir>;
fn trait_item(&self, id: TraitItemId) -> &'hir TraitItem<'hir>; fn trait_item(&self, id: TraitItemId) -> &'hir TraitItem<'hir>;
fn impl_item(&self, id: ImplItemId) -> &'hir ImplItem<'hir>; fn impl_item(&self, id: ImplItemId) -> &'hir ImplItem<'hir>;
fn foreign_item(&self, id: ForeignItemId) -> &'hir ForeignItem<'hir>; fn foreign_item(&self, id: ForeignItemId) -> &'hir ForeignItem<'hir>;
@ -150,7 +150,7 @@ impl<'hir> Map<'hir> for ErasedMap<'hir> {
fn body(&self, id: BodyId) -> &'hir Body<'hir> { fn body(&self, id: BodyId) -> &'hir Body<'hir> {
self.0.body(id) self.0.body(id)
} }
fn item(&self, id: HirId) -> &'hir Item<'hir> { fn item(&self, id: ItemId) -> &'hir Item<'hir> {
self.0.item(id) self.0.item(id)
} }
fn trait_item(&self, id: TraitItemId) -> &'hir TraitItem<'hir> { fn trait_item(&self, id: TraitItemId) -> &'hir TraitItem<'hir> {
@ -269,7 +269,7 @@ pub trait Visitor<'v>: Sized {
/// reason to override this method is if you want a nested pattern /// reason to override this method is if you want a nested pattern
/// but cannot supply a `Map`; see `nested_visit_map` for advice. /// but cannot supply a `Map`; see `nested_visit_map` for advice.
fn visit_nested_item(&mut self, id: ItemId) { fn visit_nested_item(&mut self, id: ItemId) {
let opt_item = self.nested_visit_map().inter().map(|map| map.item(id.id)); let opt_item = self.nested_visit_map().inter().map(|map| map.item(id));
walk_list!(self, visit_item, opt_item); walk_list!(self, visit_item, opt_item);
} }
@ -489,7 +489,7 @@ pub fn walk_crate<'v, V: Visitor<'v>>(visitor: &mut V, krate: &'v Crate<'v>) {
} }
pub fn walk_macro_def<'v, V: Visitor<'v>>(visitor: &mut V, macro_def: &'v MacroDef<'v>) { pub fn walk_macro_def<'v, V: Visitor<'v>>(visitor: &mut V, macro_def: &'v MacroDef<'v>) {
visitor.visit_id(macro_def.hir_id); visitor.visit_id(macro_def.hir_id());
visitor.visit_ident(macro_def.ident); visitor.visit_ident(macro_def.ident);
walk_list!(visitor, visit_attribute, macro_def.attrs); walk_list!(visitor, visit_attribute, macro_def.attrs);
} }
@ -565,16 +565,16 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
visitor.visit_ident(item.ident); visitor.visit_ident(item.ident);
match item.kind { match item.kind {
ItemKind::ExternCrate(orig_name) => { ItemKind::ExternCrate(orig_name) => {
visitor.visit_id(item.hir_id); visitor.visit_id(item.hir_id());
if let Some(orig_name) = orig_name { if let Some(orig_name) = orig_name {
visitor.visit_name(item.span, orig_name); visitor.visit_name(item.span, orig_name);
} }
} }
ItemKind::Use(ref path, _) => { ItemKind::Use(ref path, _) => {
visitor.visit_use(path, item.hir_id); visitor.visit_use(path, item.hir_id());
} }
ItemKind::Static(ref typ, _, body) | ItemKind::Const(ref typ, body) => { ItemKind::Static(ref typ, _, body) | ItemKind::Const(ref typ, body) => {
visitor.visit_id(item.hir_id); visitor.visit_id(item.hir_id());
visitor.visit_ty(typ); visitor.visit_ty(typ);
visitor.visit_nested_body(body); visitor.visit_nested_body(body);
} }
@ -583,33 +583,33 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
&sig.decl, &sig.decl,
body_id, body_id,
item.span, item.span,
item.hir_id, item.hir_id(),
), ),
ItemKind::Mod(ref module) => { ItemKind::Mod(ref module) => {
// `visit_mod()` takes care of visiting the `Item`'s `HirId`. // `visit_mod()` takes care of visiting the `Item`'s `HirId`.
visitor.visit_mod(module, item.span, item.hir_id) visitor.visit_mod(module, item.span, item.hir_id())
} }
ItemKind::ForeignMod { abi: _, items } => { ItemKind::ForeignMod { abi: _, items } => {
visitor.visit_id(item.hir_id); visitor.visit_id(item.hir_id());
walk_list!(visitor, visit_foreign_item_ref, items); walk_list!(visitor, visit_foreign_item_ref, items);
} }
ItemKind::GlobalAsm(_) => { ItemKind::GlobalAsm(_) => {
visitor.visit_id(item.hir_id); visitor.visit_id(item.hir_id());
} }
ItemKind::TyAlias(ref ty, ref generics) => { ItemKind::TyAlias(ref ty, ref generics) => {
visitor.visit_id(item.hir_id); visitor.visit_id(item.hir_id());
visitor.visit_ty(ty); visitor.visit_ty(ty);
visitor.visit_generics(generics) visitor.visit_generics(generics)
} }
ItemKind::OpaqueTy(OpaqueTy { ref generics, bounds, .. }) => { ItemKind::OpaqueTy(OpaqueTy { ref generics, bounds, .. }) => {
visitor.visit_id(item.hir_id); visitor.visit_id(item.hir_id());
walk_generics(visitor, generics); walk_generics(visitor, generics);
walk_list!(visitor, visit_param_bound, bounds); walk_list!(visitor, visit_param_bound, bounds);
} }
ItemKind::Enum(ref enum_definition, ref generics) => { ItemKind::Enum(ref enum_definition, ref generics) => {
visitor.visit_generics(generics); visitor.visit_generics(generics);
// `visit_enum_def()` takes care of visiting the `Item`'s `HirId`. // `visit_enum_def()` takes care of visiting the `Item`'s `HirId`.
visitor.visit_enum_def(enum_definition, generics, item.hir_id, item.span) visitor.visit_enum_def(enum_definition, generics, item.hir_id(), item.span)
} }
ItemKind::Impl(Impl { ItemKind::Impl(Impl {
unsafety: _, unsafety: _,
@ -622,7 +622,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
ref self_ty, ref self_ty,
items, items,
}) => { }) => {
visitor.visit_id(item.hir_id); visitor.visit_id(item.hir_id());
visitor.visit_generics(generics); visitor.visit_generics(generics);
walk_list!(visitor, visit_trait_ref, of_trait); walk_list!(visitor, visit_trait_ref, of_trait);
visitor.visit_ty(self_ty); visitor.visit_ty(self_ty);
@ -631,23 +631,23 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
ItemKind::Struct(ref struct_definition, ref generics) ItemKind::Struct(ref struct_definition, ref generics)
| ItemKind::Union(ref struct_definition, ref generics) => { | ItemKind::Union(ref struct_definition, ref generics) => {
visitor.visit_generics(generics); visitor.visit_generics(generics);
visitor.visit_id(item.hir_id); visitor.visit_id(item.hir_id());
visitor.visit_variant_data( visitor.visit_variant_data(
struct_definition, struct_definition,
item.ident.name, item.ident.name,
generics, generics,
item.hir_id, item.hir_id(),
item.span, item.span,
); );
} }
ItemKind::Trait(.., ref generics, bounds, trait_item_refs) => { ItemKind::Trait(.., ref generics, bounds, trait_item_refs) => {
visitor.visit_id(item.hir_id); visitor.visit_id(item.hir_id());
visitor.visit_generics(generics); visitor.visit_generics(generics);
walk_list!(visitor, visit_param_bound, bounds); walk_list!(visitor, visit_param_bound, bounds);
walk_list!(visitor, visit_trait_item_ref, trait_item_refs); walk_list!(visitor, visit_trait_item_ref, trait_item_refs);
} }
ItemKind::TraitAlias(ref generics, bounds) => { ItemKind::TraitAlias(ref generics, bounds) => {
visitor.visit_id(item.hir_id); visitor.visit_id(item.hir_id());
visitor.visit_generics(generics); visitor.visit_generics(generics);
walk_list!(visitor, visit_param_bound, bounds); walk_list!(visitor, visit_param_bound, bounds);
} }
@ -836,7 +836,7 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat<'v>) {
} }
pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V, foreign_item: &'v ForeignItem<'v>) { pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V, foreign_item: &'v ForeignItem<'v>) {
visitor.visit_id(foreign_item.hir_id); visitor.visit_id(foreign_item.hir_id());
visitor.visit_vis(&foreign_item.vis); visitor.visit_vis(&foreign_item.vis);
visitor.visit_ident(foreign_item.ident); visitor.visit_ident(foreign_item.ident);
@ -964,12 +964,12 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai
visitor.visit_generics(&trait_item.generics); visitor.visit_generics(&trait_item.generics);
match trait_item.kind { match trait_item.kind {
TraitItemKind::Const(ref ty, default) => { TraitItemKind::Const(ref ty, default) => {
visitor.visit_id(trait_item.hir_id); visitor.visit_id(trait_item.hir_id());
visitor.visit_ty(ty); visitor.visit_ty(ty);
walk_list!(visitor, visit_nested_body, default); walk_list!(visitor, visit_nested_body, default);
} }
TraitItemKind::Fn(ref sig, TraitFn::Required(param_names)) => { TraitItemKind::Fn(ref sig, TraitFn::Required(param_names)) => {
visitor.visit_id(trait_item.hir_id); visitor.visit_id(trait_item.hir_id());
visitor.visit_fn_decl(&sig.decl); visitor.visit_fn_decl(&sig.decl);
for &param_name in param_names { for &param_name in param_names {
visitor.visit_ident(param_name); visitor.visit_ident(param_name);
@ -981,11 +981,11 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai
&sig.decl, &sig.decl,
body_id, body_id,
trait_item.span, trait_item.span,
trait_item.hir_id, trait_item.hir_id(),
); );
} }
TraitItemKind::Type(bounds, ref default) => { TraitItemKind::Type(bounds, ref default) => {
visitor.visit_id(trait_item.hir_id); visitor.visit_id(trait_item.hir_id());
walk_list!(visitor, visit_param_bound, bounds); walk_list!(visitor, visit_param_bound, bounds);
walk_list!(visitor, visit_ty, default); walk_list!(visitor, visit_ty, default);
} }
@ -1004,7 +1004,7 @@ pub fn walk_trait_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_item_ref:
pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplItem<'v>) { pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplItem<'v>) {
// N.B., deliberately force a compilation error if/when new fields are added. // N.B., deliberately force a compilation error if/when new fields are added.
let ImplItem { let ImplItem {
hir_id: _, def_id: _,
ident, ident,
ref vis, ref vis,
ref defaultness, ref defaultness,
@ -1021,7 +1021,7 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt
visitor.visit_generics(generics); visitor.visit_generics(generics);
match *kind { match *kind {
ImplItemKind::Const(ref ty, body) => { ImplItemKind::Const(ref ty, body) => {
visitor.visit_id(impl_item.hir_id); visitor.visit_id(impl_item.hir_id());
visitor.visit_ty(ty); visitor.visit_ty(ty);
visitor.visit_nested_body(body); visitor.visit_nested_body(body);
} }
@ -1031,11 +1031,11 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt
&sig.decl, &sig.decl,
body_id, body_id,
impl_item.span, impl_item.span,
impl_item.hir_id, impl_item.hir_id(),
); );
} }
ImplItemKind::TyAlias(ref ty) => { ImplItemKind::TyAlias(ref ty) => {
visitor.visit_id(impl_item.hir_id); visitor.visit_id(impl_item.hir_id());
visitor.visit_ty(ty); visitor.visit_ty(ty);
} }
} }

View file

@ -1,8 +1,8 @@
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
use crate::hir::{ use crate::hir::{
BodyId, Expr, ForeignItemId, ImplItem, ImplItemId, Item, ItemId, Mod, TraitItem, TraitItemId, BodyId, Expr, ForeignItem, ForeignItemId, ImplItem, ImplItemId, Item, ItemId, MacroDef, Mod,
Ty, VisibilityKind, TraitItem, TraitItemId, Ty, VisibilityKind,
}; };
use crate::hir_id::{HirId, ItemLocalId}; use crate::hir_id::{HirId, ItemLocalId};
use rustc_span::def_id::{DefPathHash, LocalDefId}; use rustc_span::def_id::{DefPathHash, LocalDefId};
@ -34,30 +34,39 @@ impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for HirId {
} }
} }
impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for TraitItemId { impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ItemId {
type KeyType = (DefPathHash, ItemLocalId); type KeyType = DefPathHash;
#[inline] #[inline]
fn to_stable_hash_key(&self, hcx: &HirCtx) -> (DefPathHash, ItemLocalId) { fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash {
self.hir_id.to_stable_hash_key(hcx) hcx.local_def_path_hash(self.def_id)
}
}
impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for TraitItemId {
type KeyType = DefPathHash;
#[inline]
fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash {
hcx.local_def_path_hash(self.def_id)
} }
} }
impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ImplItemId { impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ImplItemId {
type KeyType = (DefPathHash, ItemLocalId); type KeyType = DefPathHash;
#[inline] #[inline]
fn to_stable_hash_key(&self, hcx: &HirCtx) -> (DefPathHash, ItemLocalId) { fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash {
self.hir_id.to_stable_hash_key(hcx) hcx.local_def_path_hash(self.def_id)
} }
} }
impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ForeignItemId { impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ForeignItemId {
type KeyType = (DefPathHash, ItemLocalId); type KeyType = DefPathHash;
#[inline] #[inline]
fn to_stable_hash_key(&self, hcx: &HirCtx) -> (DefPathHash, ItemLocalId) { fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash {
self.hir_id.to_stable_hash_key(hcx) hcx.local_def_path_hash(self.def_id)
} }
} }
@ -82,25 +91,25 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for BodyId {
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ItemId { impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ItemId {
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) { fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
hcx.hash_reference_to_item(self.id, hasher) hcx.hash_reference_to_item(self.hir_id(), hasher)
} }
} }
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ForeignItemId { impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ForeignItemId {
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) { fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
hcx.hash_reference_to_item(self.hir_id, hasher) hcx.hash_reference_to_item(self.hir_id(), hasher)
} }
} }
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ImplItemId { impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ImplItemId {
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) { fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
hcx.hash_reference_to_item(self.hir_id, hasher) hcx.hash_reference_to_item(self.hir_id(), hasher)
} }
} }
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for TraitItemId { impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for TraitItemId {
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) { fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
hcx.hash_reference_to_item(self.hir_id, hasher) hcx.hash_reference_to_item(self.hir_id(), hasher)
} }
} }
@ -130,7 +139,7 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for VisibilityKind<'_>
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for TraitItem<'_> { impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for TraitItem<'_> {
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) { fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
let TraitItem { hir_id: _, ident, ref attrs, ref generics, ref kind, span } = *self; let TraitItem { def_id: _, ident, ref attrs, ref generics, ref kind, span } = *self;
hcx.hash_hir_item_like(|hcx| { hcx.hash_hir_item_like(|hcx| {
ident.name.hash_stable(hcx, hasher); ident.name.hash_stable(hcx, hasher);
@ -145,7 +154,7 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for TraitItem<'_> {
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ImplItem<'_> { impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ImplItem<'_> {
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) { fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
let ImplItem { let ImplItem {
hir_id: _, def_id: _,
ident, ident,
ref vis, ref vis,
defaultness, defaultness,
@ -167,9 +176,23 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ImplItem<'_> {
} }
} }
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ForeignItem<'_> {
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
let ForeignItem { def_id: _, ident, ref attrs, ref kind, span, ref vis } = *self;
hcx.hash_hir_item_like(|hcx| {
ident.name.hash_stable(hcx, hasher);
attrs.hash_stable(hcx, hasher);
kind.hash_stable(hcx, hasher);
span.hash_stable(hcx, hasher);
vis.hash_stable(hcx, hasher);
});
}
}
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for Item<'_> { impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for Item<'_> {
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) { fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
let Item { ident, ref attrs, hir_id: _, ref kind, ref vis, span } = *self; let Item { ident, ref attrs, def_id: _, ref kind, ref vis, span } = *self;
hcx.hash_hir_item_like(|hcx| { hcx.hash_hir_item_like(|hcx| {
ident.name.hash_stable(hcx, hasher); ident.name.hash_stable(hcx, hasher);
@ -180,3 +203,17 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for Item<'_> {
}); });
} }
} }
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for MacroDef<'_> {
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
let MacroDef { ident, ref attrs, def_id: _, ref ast, ref vis, span } = *self;
hcx.hash_hir_item_like(|hcx| {
ident.name.hash_stable(hcx, hasher);
attrs.hash_stable(hcx, hasher);
ast.hash_stable(hcx, hasher);
vis.hash_stable(hcx, hasher);
span.hash_stable(hcx, hasher);
});
}
}

View file

@ -54,7 +54,7 @@ pub const NO_ANN: &dyn PpAnn = &NoAnn;
impl PpAnn for hir::Crate<'_> { impl PpAnn for hir::Crate<'_> {
fn nested(&self, state: &mut State<'_>, nested: Nested) { fn nested(&self, state: &mut State<'_>, nested: Nested) {
match nested { match nested {
Nested::Item(id) => state.print_item(self.item(id.id)), Nested::Item(id) => state.print_item(self.item(id)),
Nested::TraitItem(id) => state.print_trait_item(self.trait_item(id)), Nested::TraitItem(id) => state.print_trait_item(self.trait_item(id)),
Nested::ImplItem(id) => state.print_impl_item(self.impl_item(id)), Nested::ImplItem(id) => state.print_impl_item(self.impl_item(id)),
Nested::ForeignItem(id) => state.print_foreign_item(self.foreign_item(id)), Nested::ForeignItem(id) => state.print_foreign_item(self.foreign_item(id)),
@ -69,7 +69,7 @@ impl PpAnn for hir::Crate<'_> {
impl PpAnn for &dyn rustc_hir::intravisit::Map<'_> { impl PpAnn for &dyn rustc_hir::intravisit::Map<'_> {
fn nested(&self, state: &mut State<'_>, nested: Nested) { fn nested(&self, state: &mut State<'_>, nested: Nested) {
match nested { match nested {
Nested::Item(id) => state.print_item(self.item(id.id)), Nested::Item(id) => state.print_item(self.item(id)),
Nested::TraitItem(id) => state.print_trait_item(self.trait_item(id)), Nested::TraitItem(id) => state.print_trait_item(self.trait_item(id)),
Nested::ImplItem(id) => state.print_impl_item(self.impl_item(id)), Nested::ImplItem(id) => state.print_impl_item(self.impl_item(id)),
Nested::ForeignItem(id) => state.print_foreign_item(self.foreign_item(id)), Nested::ForeignItem(id) => state.print_foreign_item(self.foreign_item(id)),
@ -934,7 +934,7 @@ impl<'a> State<'a> {
} }
pub fn print_trait_item(&mut self, ti: &hir::TraitItem<'_>) { pub fn print_trait_item(&mut self, ti: &hir::TraitItem<'_>) {
self.ann.pre(self, AnnNode::SubItem(ti.hir_id)); self.ann.pre(self, AnnNode::SubItem(ti.hir_id()));
self.hardbreak_if_not_bol(); self.hardbreak_if_not_bol();
self.maybe_print_comment(ti.span.lo()); self.maybe_print_comment(ti.span.lo());
self.print_outer_attributes(&ti.attrs); self.print_outer_attributes(&ti.attrs);
@ -969,11 +969,11 @@ impl<'a> State<'a> {
); );
} }
} }
self.ann.post(self, AnnNode::SubItem(ti.hir_id)) self.ann.post(self, AnnNode::SubItem(ti.hir_id()))
} }
pub fn print_impl_item(&mut self, ii: &hir::ImplItem<'_>) { pub fn print_impl_item(&mut self, ii: &hir::ImplItem<'_>) {
self.ann.pre(self, AnnNode::SubItem(ii.hir_id)); self.ann.pre(self, AnnNode::SubItem(ii.hir_id()));
self.hardbreak_if_not_bol(); self.hardbreak_if_not_bol();
self.maybe_print_comment(ii.span.lo()); self.maybe_print_comment(ii.span.lo());
self.print_outer_attributes(&ii.attrs); self.print_outer_attributes(&ii.attrs);
@ -995,7 +995,7 @@ impl<'a> State<'a> {
self.print_associated_type(ii.ident, &ii.generics, None, Some(ty)); self.print_associated_type(ii.ident, &ii.generics, None, Some(ty));
} }
} }
self.ann.post(self, AnnNode::SubItem(ii.hir_id)) self.ann.post(self, AnnNode::SubItem(ii.hir_id()))
} }
pub fn print_local(&mut self, init: Option<&hir::Expr<'_>>, decl: impl Fn(&mut Self)) { pub fn print_local(&mut self, init: Option<&hir::Expr<'_>>, decl: impl Fn(&mut Self)) {

View file

@ -167,17 +167,17 @@ impl Visitor<'tcx> for IfThisChanged<'tcx> {
} }
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
self.process_attrs(item.hir_id, &item.attrs); self.process_attrs(item.hir_id(), &item.attrs);
intravisit::walk_item(self, item); intravisit::walk_item(self, item);
} }
fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) { fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) {
self.process_attrs(trait_item.hir_id, &trait_item.attrs); self.process_attrs(trait_item.hir_id(), &trait_item.attrs);
intravisit::walk_trait_item(self, trait_item); intravisit::walk_trait_item(self, trait_item);
} }
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) { fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
self.process_attrs(impl_item.hir_id, &impl_item.attrs); self.process_attrs(impl_item.hir_id(), &impl_item.attrs);
intravisit::walk_impl_item(self, impl_item); intravisit::walk_impl_item(self, impl_item);
} }

View file

@ -17,7 +17,7 @@ use rustc_ast::{self as ast, Attribute, NestedMetaItem};
use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxHashSet;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::intravisit; use rustc_hir::intravisit;
use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::itemlikevisit::ItemLikeVisitor;
use rustc_hir::Node as HirNode; use rustc_hir::Node as HirNode;
@ -179,7 +179,7 @@ pub struct DirtyCleanVisitor<'tcx> {
impl DirtyCleanVisitor<'tcx> { impl DirtyCleanVisitor<'tcx> {
/// Possibly "deserialize" the attribute into a clean/dirty assertion /// Possibly "deserialize" the attribute into a clean/dirty assertion
fn assertion_maybe(&mut self, item_id: hir::HirId, attr: &Attribute) -> Option<Assertion> { fn assertion_maybe(&mut self, item_id: LocalDefId, attr: &Attribute) -> Option<Assertion> {
let is_clean = if self.tcx.sess.check_name(attr, sym::rustc_dirty) { let is_clean = if self.tcx.sess.check_name(attr, sym::rustc_dirty) {
false false
} else if self.tcx.sess.check_name(attr, sym::rustc_clean) { } else if self.tcx.sess.check_name(attr, sym::rustc_clean) {
@ -207,7 +207,7 @@ impl DirtyCleanVisitor<'tcx> {
/// Gets the "auto" assertion on pre-validated attr, along with the `except` labels. /// Gets the "auto" assertion on pre-validated attr, along with the `except` labels.
fn assertion_auto( fn assertion_auto(
&mut self, &mut self,
item_id: hir::HirId, item_id: LocalDefId,
attr: &Attribute, attr: &Attribute,
is_clean: bool, is_clean: bool,
) -> Assertion { ) -> Assertion {
@ -253,8 +253,9 @@ impl DirtyCleanVisitor<'tcx> {
/// Return all DepNode labels that should be asserted for this item. /// Return all DepNode labels that should be asserted for this item.
/// index=0 is the "name" used for error messages /// index=0 is the "name" used for error messages
fn auto_labels(&mut self, item_id: hir::HirId, attr: &Attribute) -> (&'static str, Labels) { fn auto_labels(&mut self, item_id: LocalDefId, attr: &Attribute) -> (&'static str, Labels) {
let node = self.tcx.hir().get(item_id); let hir_id = self.tcx.hir().local_def_id_to_hir_id(item_id);
let node = self.tcx.hir().get(hir_id);
let (name, labels) = match node { let (name, labels) = match node {
HirNode::Item(item) => { HirNode::Item(item) => {
match item.kind { match item.kind {
@ -430,18 +431,17 @@ impl DirtyCleanVisitor<'tcx> {
} }
} }
fn check_item(&mut self, item_id: hir::HirId, item_span: Span) { fn check_item(&mut self, item_id: LocalDefId, item_span: Span) {
let def_id = self.tcx.hir().local_def_id(item_id); for attr in self.tcx.get_attrs(item_id.to_def_id()).iter() {
for attr in self.tcx.get_attrs(def_id.to_def_id()).iter() {
let assertion = match self.assertion_maybe(item_id, attr) { let assertion = match self.assertion_maybe(item_id, attr) {
Some(a) => a, Some(a) => a,
None => continue, None => continue,
}; };
self.checked_attrs.insert(attr.id); self.checked_attrs.insert(attr.id);
for dep_node in self.dep_nodes(&assertion.clean, def_id.to_def_id()) { for dep_node in self.dep_nodes(&assertion.clean, item_id.to_def_id()) {
self.assert_clean(item_span, dep_node); self.assert_clean(item_span, dep_node);
} }
for dep_node in self.dep_nodes(&assertion.dirty, def_id.to_def_id()) { for dep_node in self.dep_nodes(&assertion.dirty, item_id.to_def_id()) {
self.assert_dirty(item_span, dep_node); self.assert_dirty(item_span, dep_node);
} }
} }
@ -450,19 +450,19 @@ impl DirtyCleanVisitor<'tcx> {
impl ItemLikeVisitor<'tcx> for DirtyCleanVisitor<'tcx> { impl ItemLikeVisitor<'tcx> for DirtyCleanVisitor<'tcx> {
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
self.check_item(item.hir_id, item.span); self.check_item(item.def_id, item.span);
} }
fn visit_trait_item(&mut self, item: &hir::TraitItem<'_>) { fn visit_trait_item(&mut self, item: &hir::TraitItem<'_>) {
self.check_item(item.hir_id, item.span); self.check_item(item.def_id, item.span);
} }
fn visit_impl_item(&mut self, item: &hir::ImplItem<'_>) { fn visit_impl_item(&mut self, item: &hir::ImplItem<'_>) {
self.check_item(item.hir_id, item.span); self.check_item(item.def_id, item.span);
} }
fn visit_foreign_item(&mut self, item: &hir::ForeignItem<'_>) { fn visit_foreign_item(&mut self, item: &hir::ForeignItem<'_>) {
self.check_item(item.hir_id, item.span); self.check_item(item.def_id, item.span);
} }
} }

View file

@ -7,10 +7,7 @@ use crate::traits::{ObligationCauseCode, UnifyReceiverContext};
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorReported}; use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorReported};
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_hir::intravisit::{walk_ty, ErasedMap, NestedVisitorMap, Visitor}; use rustc_hir::intravisit::{walk_ty, ErasedMap, NestedVisitorMap, Visitor};
use rustc_hir::{ use rustc_hir::{self as hir, GenericBound, Item, ItemKind, Lifetime, LifetimeName, Node, TyKind};
self as hir, GenericBound, ImplItem, Item, ItemKind, Lifetime, LifetimeName, Node, TraitItem,
TyKind,
};
use rustc_middle::ty::{self, AssocItemContainer, RegionKind, Ty, TypeFoldable, TypeVisitor}; use rustc_middle::ty::{self, AssocItemContainer, RegionKind, Ty, TypeFoldable, TypeVisitor};
use rustc_span::symbol::Ident; use rustc_span::symbol::Ident;
use rustc_span::{MultiSpan, Span}; use rustc_span::{MultiSpan, Span};
@ -234,7 +231,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
} }
match fn_return.kind { match fn_return.kind {
TyKind::OpaqueDef(item_id, _) => { TyKind::OpaqueDef(item_id, _) => {
let item = tcx.hir().item(item_id.id); let item = tcx.hir().item(item_id);
let opaque = if let ItemKind::OpaqueTy(opaque) = &item.kind { let opaque = if let ItemKind::OpaqueTy(opaque) = &item.kind {
opaque opaque
} else { } else {
@ -343,17 +340,17 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
) -> Option<(Ident, &'tcx hir::Ty<'tcx>)> { ) -> Option<(Ident, &'tcx hir::Ty<'tcx>)> {
let tcx = self.tcx(); let tcx = self.tcx();
match tcx.hir().get_if_local(def_id) { match tcx.hir().get_if_local(def_id) {
Some(Node::ImplItem(ImplItem { ident, hir_id, .. })) => { Some(Node::ImplItem(impl_item)) => {
match tcx.hir().find(tcx.hir().get_parent_item(*hir_id)) { match tcx.hir().find(tcx.hir().get_parent_item(impl_item.hir_id())) {
Some(Node::Item(Item { Some(Node::Item(Item {
kind: ItemKind::Impl(hir::Impl { self_ty, .. }), kind: ItemKind::Impl(hir::Impl { self_ty, .. }),
.. ..
})) => Some((*ident, self_ty)), })) => Some((impl_item.ident, self_ty)),
_ => None, _ => None,
} }
} }
Some(Node::TraitItem(TraitItem { ident, hir_id, .. })) => { Some(Node::TraitItem(trait_item)) => {
let parent_id = tcx.hir().get_parent_item(*hir_id); let parent_id = tcx.hir().get_parent_item(trait_item.hir_id());
match tcx.hir().find(parent_id) { match tcx.hir().find(parent_id) {
Some(Node::Item(Item { kind: ItemKind::Trait(..), .. })) => { Some(Node::Item(Item { kind: ItemKind::Trait(..), .. })) => {
// The method being called is defined in the `trait`, but the `'static` // The method being called is defined in the `trait`, but the `'static`
@ -364,8 +361,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
.hir() .hir()
.trait_impls(trait_did) .trait_impls(trait_did)
.iter() .iter()
.filter_map(|impl_node| { .filter_map(|&impl_did| {
let impl_did = tcx.hir().local_def_id(*impl_node);
match tcx.hir().get_if_local(impl_did.to_def_id()) { match tcx.hir().get_if_local(impl_did.to_def_id()) {
Some(Node::Item(Item { Some(Node::Item(Item {
kind: ItemKind::Impl(hir::Impl { self_ty, .. }), kind: ItemKind::Impl(hir::Impl { self_ty, .. }),
@ -389,7 +385,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
}) })
.next() .next()
{ {
Some(self_ty) => Some((*ident, self_ty)), Some(self_ty) => Some((trait_item.ident, self_ty)),
_ => None, _ => None,
} }
} }

View file

@ -831,12 +831,11 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
}, },
{ {
par_iter(&tcx.hir().krate().modules).for_each(|(&module, _)| { par_iter(&tcx.hir().krate().modules).for_each(|(&module, _)| {
let local_def_id = tcx.hir().local_def_id(module); tcx.ensure().check_mod_loops(module);
tcx.ensure().check_mod_loops(local_def_id); tcx.ensure().check_mod_attrs(module);
tcx.ensure().check_mod_attrs(local_def_id); tcx.ensure().check_mod_naked_functions(module);
tcx.ensure().check_mod_naked_functions(local_def_id); tcx.ensure().check_mod_unstable_api_usage(module);
tcx.ensure().check_mod_unstable_api_usage(local_def_id); tcx.ensure().check_mod_const_bodies(module);
tcx.ensure().check_mod_const_bodies(local_def_id);
}); });
} }
); );
@ -861,10 +860,8 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
// "not all control paths return a value" is reported here. // "not all control paths return a value" is reported here.
// //
// maybe move the check to a MIR pass? // maybe move the check to a MIR pass?
let local_def_id = tcx.hir().local_def_id(module); tcx.ensure().check_mod_liveness(module);
tcx.ensure().check_mod_intrinsics(module);
tcx.ensure().check_mod_liveness(local_def_id);
tcx.ensure().check_mod_intrinsics(local_def_id);
}); });
}); });
} }
@ -926,7 +923,7 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
{ {
sess.time("privacy_checking_modules", || { sess.time("privacy_checking_modules", || {
par_iter(&tcx.hir().krate().modules).for_each(|(&module, _)| { par_iter(&tcx.hir().krate().modules).for_each(|(&module, _)| {
tcx.ensure().check_mod_privacy(tcx.hir().local_def_id(module)); tcx.ensure().check_mod_privacy(module);
}); });
}); });
} }

View file

@ -26,7 +26,7 @@ struct Finder<'tcx> {
impl<'v> ItemLikeVisitor<'v> for Finder<'_> { impl<'v> ItemLikeVisitor<'v> for Finder<'_> {
fn visit_item(&mut self, item: &hir::Item<'_>) { fn visit_item(&mut self, item: &hir::Item<'_>) {
if self.tcx.sess.contains_name(&item.attrs, sym::rustc_proc_macro_decls) { if self.tcx.sess.contains_name(&item.attrs, sym::rustc_proc_macro_decls) {
self.decls = Some(item.hir_id); self.decls = Some(item.hir_id());
} }
} }

View file

@ -36,9 +36,9 @@ use rustc_feature::{deprecated_attributes, AttributeGate, AttributeTemplate, Att
use rustc_feature::{GateIssue, Stability}; use rustc_feature::{GateIssue, Stability};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::DefId; use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdSet};
use rustc_hir::{ForeignItemKind, GenericParamKind, PatKind}; use rustc_hir::{ForeignItemKind, GenericParamKind, PatKind};
use rustc_hir::{HirId, HirIdSet, Node}; use rustc_hir::{HirId, Node};
use rustc_index::vec::Idx; use rustc_index::vec::Idx;
use rustc_middle::lint::LintDiagnosticBuilder; use rustc_middle::lint::LintDiagnosticBuilder;
use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::print::with_no_trimmed_paths;
@ -173,8 +173,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxPointers {
| hir::ItemKind::Enum(..) | hir::ItemKind::Enum(..)
| hir::ItemKind::Struct(..) | hir::ItemKind::Struct(..)
| hir::ItemKind::Union(..) => { | hir::ItemKind::Union(..) => {
let def_id = cx.tcx.hir().local_def_id(it.hir_id); self.check_heap_type(cx, it.span, cx.tcx.type_of(it.def_id))
self.check_heap_type(cx, it.span, cx.tcx.type_of(def_id))
} }
_ => (), _ => (),
} }
@ -585,9 +584,9 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
hir::ItemKind::Trait(.., trait_item_refs) => { hir::ItemKind::Trait(.., trait_item_refs) => {
// Issue #11592: traits are always considered exported, even when private. // Issue #11592: traits are always considered exported, even when private.
if let hir::VisibilityKind::Inherited = it.vis.node { if let hir::VisibilityKind::Inherited = it.vis.node {
self.private_traits.insert(it.hir_id); self.private_traits.insert(it.hir_id());
for trait_item_ref in trait_item_refs { for trait_item_ref in trait_item_refs {
self.private_traits.insert(trait_item_ref.id.hir_id); self.private_traits.insert(trait_item_ref.id.hir_id());
} }
return; return;
} }
@ -601,7 +600,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
if let Some(Node::Item(item)) = cx.tcx.hir().find(hir_id) { if let Some(Node::Item(item)) = cx.tcx.hir().find(hir_id) {
if let hir::VisibilityKind::Inherited = item.vis.node { if let hir::VisibilityKind::Inherited = item.vis.node {
for impl_item_ref in items { for impl_item_ref in items {
self.private_traits.insert(impl_item_ref.id.hir_id); self.private_traits.insert(impl_item_ref.id.hir_id());
} }
} }
} }
@ -621,23 +620,21 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
_ => return, _ => return,
}; };
let def_id = cx.tcx.hir().local_def_id(it.hir_id); let (article, desc) = cx.tcx.article_and_description(it.def_id.to_def_id());
let (article, desc) = cx.tcx.article_and_description(def_id.to_def_id());
self.check_missing_docs_attrs(cx, Some(it.hir_id), &it.attrs, it.span, article, desc); self.check_missing_docs_attrs(cx, Some(it.hir_id()), &it.attrs, it.span, article, desc);
} }
fn check_trait_item(&mut self, cx: &LateContext<'_>, trait_item: &hir::TraitItem<'_>) { fn check_trait_item(&mut self, cx: &LateContext<'_>, trait_item: &hir::TraitItem<'_>) {
if self.private_traits.contains(&trait_item.hir_id) { if self.private_traits.contains(&trait_item.hir_id()) {
return; return;
} }
let def_id = cx.tcx.hir().local_def_id(trait_item.hir_id); let (article, desc) = cx.tcx.article_and_description(trait_item.def_id.to_def_id());
let (article, desc) = cx.tcx.article_and_description(def_id.to_def_id());
self.check_missing_docs_attrs( self.check_missing_docs_attrs(
cx, cx,
Some(trait_item.hir_id), Some(trait_item.hir_id()),
&trait_item.attrs, &trait_item.attrs,
trait_item.span, trait_item.span,
article, article,
@ -647,15 +644,14 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
fn check_impl_item(&mut self, cx: &LateContext<'_>, impl_item: &hir::ImplItem<'_>) { fn check_impl_item(&mut self, cx: &LateContext<'_>, impl_item: &hir::ImplItem<'_>) {
// If the method is an impl for a trait, don't doc. // If the method is an impl for a trait, don't doc.
if method_context(cx, impl_item.hir_id) == MethodLateContext::TraitImpl { if method_context(cx, impl_item.hir_id()) == MethodLateContext::TraitImpl {
return; return;
} }
let def_id = cx.tcx.hir().local_def_id(impl_item.hir_id); let (article, desc) = cx.tcx.article_and_description(impl_item.def_id.to_def_id());
let (article, desc) = cx.tcx.article_and_description(def_id.to_def_id());
self.check_missing_docs_attrs( self.check_missing_docs_attrs(
cx, cx,
Some(impl_item.hir_id), Some(impl_item.hir_id()),
&impl_item.attrs, &impl_item.attrs,
impl_item.span, impl_item.span,
article, article,
@ -664,11 +660,10 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
} }
fn check_foreign_item(&mut self, cx: &LateContext<'_>, foreign_item: &hir::ForeignItem<'_>) { fn check_foreign_item(&mut self, cx: &LateContext<'_>, foreign_item: &hir::ForeignItem<'_>) {
let def_id = cx.tcx.hir().local_def_id(foreign_item.hir_id); let (article, desc) = cx.tcx.article_and_description(foreign_item.def_id.to_def_id());
let (article, desc) = cx.tcx.article_and_description(def_id.to_def_id());
self.check_missing_docs_attrs( self.check_missing_docs_attrs(
cx, cx,
Some(foreign_item.hir_id), Some(foreign_item.hir_id()),
&foreign_item.attrs, &foreign_item.attrs,
foreign_item.span, foreign_item.span,
article, article,
@ -732,7 +727,7 @@ declare_lint_pass!(MissingCopyImplementations => [MISSING_COPY_IMPLEMENTATIONS])
impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations { impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations {
fn check_item(&mut self, cx: &LateContext<'_>, item: &hir::Item<'_>) { fn check_item(&mut self, cx: &LateContext<'_>, item: &hir::Item<'_>) {
if !cx.access_levels.is_reachable(item.hir_id) { if !cx.access_levels.is_reachable(item.hir_id()) {
return; return;
} }
let (def, ty) = match item.kind { let (def, ty) = match item.kind {
@ -740,21 +735,21 @@ impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations {
if !ast_generics.params.is_empty() { if !ast_generics.params.is_empty() {
return; return;
} }
let def = cx.tcx.adt_def(cx.tcx.hir().local_def_id(item.hir_id)); let def = cx.tcx.adt_def(item.def_id);
(def, cx.tcx.mk_adt(def, cx.tcx.intern_substs(&[]))) (def, cx.tcx.mk_adt(def, cx.tcx.intern_substs(&[])))
} }
hir::ItemKind::Union(_, ref ast_generics) => { hir::ItemKind::Union(_, ref ast_generics) => {
if !ast_generics.params.is_empty() { if !ast_generics.params.is_empty() {
return; return;
} }
let def = cx.tcx.adt_def(cx.tcx.hir().local_def_id(item.hir_id)); let def = cx.tcx.adt_def(item.def_id);
(def, cx.tcx.mk_adt(def, cx.tcx.intern_substs(&[]))) (def, cx.tcx.mk_adt(def, cx.tcx.intern_substs(&[])))
} }
hir::ItemKind::Enum(_, ref ast_generics) => { hir::ItemKind::Enum(_, ref ast_generics) => {
if !ast_generics.params.is_empty() { if !ast_generics.params.is_empty() {
return; return;
} }
let def = cx.tcx.adt_def(cx.tcx.hir().local_def_id(item.hir_id)); let def = cx.tcx.adt_def(item.def_id);
(def, cx.tcx.mk_adt(def, cx.tcx.intern_substs(&[]))) (def, cx.tcx.mk_adt(def, cx.tcx.intern_substs(&[])))
} }
_ => return, _ => return,
@ -812,14 +807,14 @@ declare_lint! {
#[derive(Default)] #[derive(Default)]
pub struct MissingDebugImplementations { pub struct MissingDebugImplementations {
impling_types: Option<HirIdSet>, impling_types: Option<LocalDefIdSet>,
} }
impl_lint_pass!(MissingDebugImplementations => [MISSING_DEBUG_IMPLEMENTATIONS]); impl_lint_pass!(MissingDebugImplementations => [MISSING_DEBUG_IMPLEMENTATIONS]);
impl<'tcx> LateLintPass<'tcx> for MissingDebugImplementations { impl<'tcx> LateLintPass<'tcx> for MissingDebugImplementations {
fn check_item(&mut self, cx: &LateContext<'_>, item: &hir::Item<'_>) { fn check_item(&mut self, cx: &LateContext<'_>, item: &hir::Item<'_>) {
if !cx.access_levels.is_reachable(item.hir_id) { if !cx.access_levels.is_reachable(item.hir_id()) {
return; return;
} }
@ -834,11 +829,11 @@ impl<'tcx> LateLintPass<'tcx> for MissingDebugImplementations {
}; };
if self.impling_types.is_none() { if self.impling_types.is_none() {
let mut impls = HirIdSet::default(); let mut impls = LocalDefIdSet::default();
cx.tcx.for_each_impl(debug, |d| { cx.tcx.for_each_impl(debug, |d| {
if let Some(ty_def) = cx.tcx.type_of(d).ty_adt_def() { if let Some(ty_def) = cx.tcx.type_of(d).ty_adt_def() {
if let Some(def_id) = ty_def.did.as_local() { if let Some(def_id) = ty_def.did.as_local() {
impls.insert(cx.tcx.hir().local_def_id_to_hir_id(def_id)); impls.insert(def_id);
} }
} }
}); });
@ -847,7 +842,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDebugImplementations {
debug!("{:?}", self.impling_types); debug!("{:?}", self.impling_types);
} }
if !self.impling_types.as_ref().unwrap().contains(&item.hir_id) { if !self.impling_types.as_ref().unwrap().contains(&item.def_id) {
cx.struct_span_lint(MISSING_DEBUG_IMPLEMENTATIONS, item.span, |lint| { cx.struct_span_lint(MISSING_DEBUG_IMPLEMENTATIONS, item.span, |lint| {
lint.build(&format!( lint.build(&format!(
"type does not implement `{}`; consider adding `#[derive(Debug)]` \ "type does not implement `{}`; consider adding `#[derive(Debug)]` \
@ -1362,14 +1357,14 @@ impl UnreachablePub {
impl<'tcx> LateLintPass<'tcx> for UnreachablePub { impl<'tcx> LateLintPass<'tcx> for UnreachablePub {
fn check_item(&mut self, cx: &LateContext<'_>, item: &hir::Item<'_>) { fn check_item(&mut self, cx: &LateContext<'_>, item: &hir::Item<'_>) {
self.perform_lint(cx, "item", item.hir_id, &item.vis, item.span, true); self.perform_lint(cx, "item", item.hir_id(), &item.vis, item.span, true);
} }
fn check_foreign_item(&mut self, cx: &LateContext<'_>, foreign_item: &hir::ForeignItem<'tcx>) { fn check_foreign_item(&mut self, cx: &LateContext<'_>, foreign_item: &hir::ForeignItem<'tcx>) {
self.perform_lint( self.perform_lint(
cx, cx,
"item", "item",
foreign_item.hir_id, foreign_item.hir_id(),
&foreign_item.vis, &foreign_item.vis,
foreign_item.span, foreign_item.span,
true, true,
@ -1381,7 +1376,7 @@ impl<'tcx> LateLintPass<'tcx> for UnreachablePub {
} }
fn check_impl_item(&mut self, cx: &LateContext<'_>, impl_item: &hir::ImplItem<'_>) { fn check_impl_item(&mut self, cx: &LateContext<'_>, impl_item: &hir::ImplItem<'_>) {
self.perform_lint(cx, "item", impl_item.hir_id, &impl_item.vis, impl_item.span, false); self.perform_lint(cx, "item", impl_item.hir_id(), &impl_item.vis, impl_item.span, false);
} }
} }
@ -1603,8 +1598,7 @@ impl<'tcx> LateLintPass<'tcx> for TrivialConstraints {
use rustc_middle::ty::PredicateKind::*; use rustc_middle::ty::PredicateKind::*;
if cx.tcx.features().trivial_bounds { if cx.tcx.features().trivial_bounds {
let def_id = cx.tcx.hir().local_def_id(item.hir_id); let predicates = cx.tcx.predicates_of(item.def_id);
let predicates = cx.tcx.predicates_of(def_id);
for &(predicate, span) in predicates.predicates { for &(predicate, span) in predicates.predicates {
let predicate_kind_name = match predicate.kind().skip_binder() { let predicate_kind_name = match predicate.kind().skip_binder() {
Trait(..) => "Trait", Trait(..) => "Trait",
@ -1810,7 +1804,7 @@ declare_lint! {
} }
pub struct UnnameableTestItems { pub struct UnnameableTestItems {
boundary: Option<hir::HirId>, // HirId of the item under which things are not nameable boundary: Option<LocalDefId>, // Id of the item under which things are not nameable
items_nameable: bool, items_nameable: bool,
} }
@ -1828,7 +1822,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnameableTestItems {
if let hir::ItemKind::Mod(..) = it.kind { if let hir::ItemKind::Mod(..) = it.kind {
} else { } else {
self.items_nameable = false; self.items_nameable = false;
self.boundary = Some(it.hir_id); self.boundary = Some(it.def_id);
} }
return; return;
} }
@ -1841,7 +1835,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnameableTestItems {
} }
fn check_item_post(&mut self, _cx: &LateContext<'_>, it: &hir::Item<'_>) { fn check_item_post(&mut self, _cx: &LateContext<'_>, it: &hir::Item<'_>) {
if !self.items_nameable && self.boundary == Some(it.hir_id) { if !self.items_nameable && self.boundary == Some(it.def_id) {
self.items_nameable = true; self.items_nameable = true;
} }
} }
@ -2125,7 +2119,7 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
use rustc_middle::middle::resolve_lifetime::Region; use rustc_middle::middle::resolve_lifetime::Region;
let infer_static = cx.tcx.features().infer_static_outlives_requirements; let infer_static = cx.tcx.features().infer_static_outlives_requirements;
let def_id = cx.tcx.hir().local_def_id(item.hir_id); let def_id = item.def_id;
if let hir::ItemKind::Struct(_, ref hir_generics) if let hir::ItemKind::Struct(_, ref hir_generics)
| hir::ItemKind::Enum(_, ref hir_generics) | hir::ItemKind::Enum(_, ref hir_generics)
| hir::ItemKind::Union(_, ref hir_generics) = item.kind | hir::ItemKind::Union(_, ref hir_generics) = item.kind
@ -2680,10 +2674,7 @@ impl ClashingExternDeclarations {
/// Insert a new foreign item into the seen set. If a symbol with the same name already exists /// Insert a new foreign item into the seen set. If a symbol with the same name already exists
/// for the item, return its HirId without updating the set. /// for the item, return its HirId without updating the set.
fn insert(&mut self, tcx: TyCtxt<'_>, fi: &hir::ForeignItem<'_>) -> Option<HirId> { fn insert(&mut self, tcx: TyCtxt<'_>, fi: &hir::ForeignItem<'_>) -> Option<HirId> {
let hid = fi.hir_id; let did = fi.def_id.to_def_id();
let local_did = tcx.hir().local_def_id(fi.hir_id);
let did = local_did.to_def_id();
let instance = Instance::new(did, ty::List::identity_for_item(tcx, did)); let instance = Instance::new(did, ty::List::identity_for_item(tcx, did));
let name = Symbol::intern(tcx.symbol_name(instance).name); let name = Symbol::intern(tcx.symbol_name(instance).name);
if let Some(&hir_id) = self.seen_decls.get(&name) { if let Some(&hir_id) = self.seen_decls.get(&name) {
@ -2692,7 +2683,7 @@ impl ClashingExternDeclarations {
// This lets us avoid emitting "knock-on" diagnostics. // This lets us avoid emitting "knock-on" diagnostics.
Some(hir_id) Some(hir_id)
} else { } else {
self.seen_decls.insert(name, hid) self.seen_decls.insert(name, fi.hir_id())
} }
} }
@ -2700,16 +2691,15 @@ impl ClashingExternDeclarations {
/// the name specified in a #[link_name = ...] attribute if one was specified, else, just the /// the name specified in a #[link_name = ...] attribute if one was specified, else, just the
/// symbol's name. /// symbol's name.
fn name_of_extern_decl(tcx: TyCtxt<'_>, fi: &hir::ForeignItem<'_>) -> SymbolName { fn name_of_extern_decl(tcx: TyCtxt<'_>, fi: &hir::ForeignItem<'_>) -> SymbolName {
let did = tcx.hir().local_def_id(fi.hir_id);
if let Some((overridden_link_name, overridden_link_name_span)) = if let Some((overridden_link_name, overridden_link_name_span)) =
tcx.codegen_fn_attrs(did).link_name.map(|overridden_link_name| { tcx.codegen_fn_attrs(fi.def_id).link_name.map(|overridden_link_name| {
// FIXME: Instead of searching through the attributes again to get span // FIXME: Instead of searching through the attributes again to get span
// information, we could have codegen_fn_attrs also give span information back for // information, we could have codegen_fn_attrs also give span information back for
// where the attribute was defined. However, until this is found to be a // where the attribute was defined. However, until this is found to be a
// bottleneck, this does just fine. // bottleneck, this does just fine.
( (
overridden_link_name, overridden_link_name,
tcx.get_attrs(did.to_def_id()) tcx.get_attrs(fi.def_id.to_def_id())
.iter() .iter()
.find(|at| tcx.sess.check_name(at, sym::link_name)) .find(|at| tcx.sess.check_name(at, sym::link_name))
.unwrap() .unwrap()
@ -2937,10 +2927,10 @@ impl<'tcx> LateLintPass<'tcx> for ClashingExternDeclarations {
let tcx = cx.tcx; let tcx = cx.tcx;
if let Some(existing_hid) = self.insert(tcx, this_fi) { if let Some(existing_hid) = self.insert(tcx, this_fi) {
let existing_decl_ty = tcx.type_of(tcx.hir().local_def_id(existing_hid)); let existing_decl_ty = tcx.type_of(tcx.hir().local_def_id(existing_hid));
let this_decl_ty = tcx.type_of(tcx.hir().local_def_id(this_fi.hir_id)); let this_decl_ty = tcx.type_of(this_fi.def_id);
debug!( debug!(
"ClashingExternDeclarations: Comparing existing {:?}: {:?} to this {:?}: {:?}", "ClashingExternDeclarations: Comparing existing {:?}: {:?} to this {:?}: {:?}",
existing_hid, existing_decl_ty, this_fi.hir_id, this_decl_ty existing_hid, existing_decl_ty, this_fi.def_id, this_decl_ty
); );
// Check that the declarations match. // Check that the declarations match.
if !Self::structurally_same_type( if !Self::structurally_same_type(
@ -2962,7 +2952,7 @@ impl<'tcx> LateLintPass<'tcx> for ClashingExternDeclarations {
// Finally, emit the diagnostic. // Finally, emit the diagnostic.
tcx.struct_span_lint_hir( tcx.struct_span_lint_hir(
CLASHING_EXTERN_DECLARATIONS, CLASHING_EXTERN_DECLARATIONS,
this_fi.hir_id, this_fi.hir_id(),
get_relevant_span(this_fi), get_relevant_span(this_fi),
|lint| { |lint| {
let mut expected_str = DiagnosticStyledString::new(); let mut expected_str = DiagnosticStyledString::new();

View file

@ -142,8 +142,8 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
self.context.generics = it.kind.generics(); self.context.generics = it.kind.generics();
let old_cached_typeck_results = self.context.cached_typeck_results.take(); let old_cached_typeck_results = self.context.cached_typeck_results.take();
let old_enclosing_body = self.context.enclosing_body.take(); let old_enclosing_body = self.context.enclosing_body.take();
self.with_lint_attrs(it.hir_id, &it.attrs, |cx| { self.with_lint_attrs(it.hir_id(), &it.attrs, |cx| {
cx.with_param_env(it.hir_id, |cx| { cx.with_param_env(it.hir_id(), |cx| {
lint_callback!(cx, check_item, it); lint_callback!(cx, check_item, it);
hir_visit::walk_item(cx, it); hir_visit::walk_item(cx, it);
lint_callback!(cx, check_item_post, it); lint_callback!(cx, check_item_post, it);
@ -155,8 +155,8 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
} }
fn visit_foreign_item(&mut self, it: &'tcx hir::ForeignItem<'tcx>) { fn visit_foreign_item(&mut self, it: &'tcx hir::ForeignItem<'tcx>) {
self.with_lint_attrs(it.hir_id, &it.attrs, |cx| { self.with_lint_attrs(it.hir_id(), &it.attrs, |cx| {
cx.with_param_env(it.hir_id, |cx| { cx.with_param_env(it.hir_id(), |cx| {
lint_callback!(cx, check_foreign_item, it); lint_callback!(cx, check_foreign_item, it);
hir_visit::walk_foreign_item(cx, it); hir_visit::walk_foreign_item(cx, it);
lint_callback!(cx, check_foreign_item_post, it); lint_callback!(cx, check_foreign_item_post, it);
@ -178,7 +178,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
} }
fn visit_stmt(&mut self, s: &'tcx hir::Stmt<'tcx>) { fn visit_stmt(&mut self, s: &'tcx hir::Stmt<'tcx>) {
let get_item = |id: hir::ItemId| self.context.tcx.hir().item(id.id); let get_item = |id: hir::ItemId| self.context.tcx.hir().item(id);
let attrs = &s.kind.attrs(get_item); let attrs = &s.kind.attrs(get_item);
// See `EarlyContextAndPass::visit_stmt` for an explanation // See `EarlyContextAndPass::visit_stmt` for an explanation
// of why we call `walk_stmt` outside of `with_lint_attrs` // of why we call `walk_stmt` outside of `with_lint_attrs`
@ -301,8 +301,8 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) { fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) {
let generics = self.context.generics.take(); let generics = self.context.generics.take();
self.context.generics = Some(&trait_item.generics); self.context.generics = Some(&trait_item.generics);
self.with_lint_attrs(trait_item.hir_id, &trait_item.attrs, |cx| { self.with_lint_attrs(trait_item.hir_id(), &trait_item.attrs, |cx| {
cx.with_param_env(trait_item.hir_id, |cx| { cx.with_param_env(trait_item.hir_id(), |cx| {
lint_callback!(cx, check_trait_item, trait_item); lint_callback!(cx, check_trait_item, trait_item);
hir_visit::walk_trait_item(cx, trait_item); hir_visit::walk_trait_item(cx, trait_item);
lint_callback!(cx, check_trait_item_post, trait_item); lint_callback!(cx, check_trait_item_post, trait_item);
@ -314,8 +314,8 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) { fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
let generics = self.context.generics.take(); let generics = self.context.generics.take();
self.context.generics = Some(&impl_item.generics); self.context.generics = Some(&impl_item.generics);
self.with_lint_attrs(impl_item.hir_id, &impl_item.attrs, |cx| { self.with_lint_attrs(impl_item.hir_id(), &impl_item.attrs, |cx| {
cx.with_param_env(impl_item.hir_id, |cx| { cx.with_param_env(impl_item.hir_id(), |cx| {
lint_callback!(cx, check_impl_item, impl_item); lint_callback!(cx, check_impl_item, impl_item);
hir_visit::walk_impl_item(cx, impl_item); hir_visit::walk_impl_item(cx, impl_item);
lint_callback!(cx, check_impl_item_post, impl_item); lint_callback!(cx, check_impl_item_post, impl_item);
@ -496,7 +496,7 @@ pub fn check_crate<'tcx, T: LateLintPass<'tcx>>(
tcx.sess.time("module_lints", || { tcx.sess.time("module_lints", || {
// Run per-module lints // Run per-module lints
par_iter(&tcx.hir().krate().modules).for_each(|(&module, _)| { par_iter(&tcx.hir().krate().modules).for_each(|(&module, _)| {
tcx.ensure().lint_mod(tcx.hir().local_def_id(module)); tcx.ensure().lint_mod(module);
}); });
}); });
}, },

View file

@ -41,7 +41,7 @@ fn lint_levels(tcx: TyCtxt<'_>, cnum: CrateNum) -> LintLevelMap {
let push = builder.levels.push(&krate.item.attrs, &store, true); let push = builder.levels.push(&krate.item.attrs, &store, true);
builder.levels.register_id(hir::CRATE_HIR_ID); builder.levels.register_id(hir::CRATE_HIR_ID);
for macro_def in krate.exported_macros { for macro_def in krate.exported_macros {
builder.levels.register_id(macro_def.hir_id); builder.levels.register_id(macro_def.hir_id());
} }
intravisit::walk_crate(&mut builder, krate); intravisit::walk_crate(&mut builder, krate);
builder.levels.pop(push); builder.levels.pop(push);
@ -577,13 +577,13 @@ impl<'tcx> intravisit::Visitor<'tcx> for LintLevelMapBuilder<'_, 'tcx> {
} }
fn visit_item(&mut self, it: &'tcx hir::Item<'tcx>) { fn visit_item(&mut self, it: &'tcx hir::Item<'tcx>) {
self.with_lint_attrs(it.hir_id, &it.attrs, |builder| { self.with_lint_attrs(it.hir_id(), &it.attrs, |builder| {
intravisit::walk_item(builder, it); intravisit::walk_item(builder, it);
}); });
} }
fn visit_foreign_item(&mut self, it: &'tcx hir::ForeignItem<'tcx>) { fn visit_foreign_item(&mut self, it: &'tcx hir::ForeignItem<'tcx>) {
self.with_lint_attrs(it.hir_id, &it.attrs, |builder| { self.with_lint_attrs(it.hir_id(), &it.attrs, |builder| {
intravisit::walk_foreign_item(builder, it); intravisit::walk_foreign_item(builder, it);
}) })
} }
@ -631,13 +631,13 @@ impl<'tcx> intravisit::Visitor<'tcx> for LintLevelMapBuilder<'_, 'tcx> {
} }
fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) { fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) {
self.with_lint_attrs(trait_item.hir_id, &trait_item.attrs, |builder| { self.with_lint_attrs(trait_item.hir_id(), &trait_item.attrs, |builder| {
intravisit::walk_trait_item(builder, trait_item); intravisit::walk_trait_item(builder, trait_item);
}); });
} }
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) { fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
self.with_lint_attrs(impl_item.hir_id, &impl_item.attrs, |builder| { self.with_lint_attrs(impl_item.hir_id(), &impl_item.attrs, |builder| {
intravisit::walk_impl_item(builder, impl_item); intravisit::walk_impl_item(builder, impl_item);
}); });
} }

View file

@ -47,8 +47,7 @@ impl<'tcx> LateLintPass<'tcx> for DropTraitConstraints {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
use rustc_middle::ty::PredicateKind::*; use rustc_middle::ty::PredicateKind::*;
let def_id = cx.tcx.hir().local_def_id(item.hir_id); let predicates = cx.tcx.explicit_predicates_of(item.def_id);
let predicates = cx.tcx.explicit_predicates_of(def_id);
for &(predicate, span) in predicates.predicates { for &(predicate, span) in predicates.predicates {
let trait_predicate = match predicate.kind().skip_binder() { let trait_predicate = match predicate.kind().skip_binder() {
Trait(trait_predicate, _constness) => trait_predicate, Trait(trait_predicate, _constness) => trait_predicate,

View file

@ -1262,15 +1262,15 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
impl<'tcx> LateLintPass<'tcx> for ImproperCTypesDeclarations { impl<'tcx> LateLintPass<'tcx> for ImproperCTypesDeclarations {
fn check_foreign_item(&mut self, cx: &LateContext<'_>, it: &hir::ForeignItem<'_>) { fn check_foreign_item(&mut self, cx: &LateContext<'_>, it: &hir::ForeignItem<'_>) {
let mut vis = ImproperCTypesVisitor { cx, mode: CItemKind::Declaration }; let mut vis = ImproperCTypesVisitor { cx, mode: CItemKind::Declaration };
let abi = cx.tcx.hir().get_foreign_abi(it.hir_id); let abi = cx.tcx.hir().get_foreign_abi(it.hir_id());
if !vis.is_internal_abi(abi) { if !vis.is_internal_abi(abi) {
match it.kind { match it.kind {
hir::ForeignItemKind::Fn(ref decl, _, _) => { hir::ForeignItemKind::Fn(ref decl, _, _) => {
vis.check_foreign_fn(it.hir_id, decl); vis.check_foreign_fn(it.hir_id(), decl);
} }
hir::ForeignItemKind::Static(ref ty, _) => { hir::ForeignItemKind::Static(ref ty, _) => {
vis.check_foreign_static(it.hir_id, ty.span); vis.check_foreign_static(it.hir_id(), ty.span);
} }
hir::ForeignItemKind::Type => (), hir::ForeignItemKind::Type => (),
} }
@ -1308,8 +1308,7 @@ declare_lint_pass!(VariantSizeDifferences => [VARIANT_SIZE_DIFFERENCES]);
impl<'tcx> LateLintPass<'tcx> for VariantSizeDifferences { impl<'tcx> LateLintPass<'tcx> for VariantSizeDifferences {
fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) { fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
if let hir::ItemKind::Enum(ref enum_definition, _) = it.kind { if let hir::ItemKind::Enum(ref enum_definition, _) = it.kind {
let item_def_id = cx.tcx.hir().local_def_id(it.hir_id); let t = cx.tcx.type_of(it.def_id);
let t = cx.tcx.type_of(item_def_id);
let ty = cx.tcx.erase_regions(t); let ty = cx.tcx.erase_regions(t);
let layout = match cx.layout_of(ty) { let layout = match cx.layout_of(ty) {
Ok(layout) => layout, Ok(layout) => layout,

View file

@ -4,29 +4,24 @@ use rustc_middle::middle::cstore::ForeignModule;
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
crate fn collect(tcx: TyCtxt<'_>) -> Vec<ForeignModule> { crate fn collect(tcx: TyCtxt<'_>) -> Vec<ForeignModule> {
let mut collector = Collector { tcx, modules: Vec::new() }; let mut collector = Collector { modules: Vec::new() };
tcx.hir().krate().visit_all_item_likes(&mut collector); tcx.hir().krate().visit_all_item_likes(&mut collector);
collector.modules collector.modules
} }
struct Collector<'tcx> { struct Collector {
tcx: TyCtxt<'tcx>,
modules: Vec<ForeignModule>, modules: Vec<ForeignModule>,
} }
impl ItemLikeVisitor<'tcx> for Collector<'tcx> { impl ItemLikeVisitor<'tcx> for Collector {
fn visit_item(&mut self, it: &'tcx hir::Item<'tcx>) { fn visit_item(&mut self, it: &'tcx hir::Item<'tcx>) {
let items = match it.kind { let items = match it.kind {
hir::ItemKind::ForeignMod { items, .. } => items, hir::ItemKind::ForeignMod { items, .. } => items,
_ => return, _ => return,
}; };
let foreign_items = let foreign_items = items.iter().map(|it| it.id.def_id.to_def_id()).collect();
items.iter().map(|it| self.tcx.hir().local_def_id(it.id.hir_id).to_def_id()).collect(); self.modules.push(ForeignModule { foreign_items, def_id: it.def_id.to_def_id() });
self.modules.push(ForeignModule {
foreign_items,
def_id: self.tcx.hir().local_def_id(it.hir_id).to_def_id(),
});
} }
fn visit_trait_item(&mut self, _it: &'tcx hir::TraitItem<'tcx>) {} fn visit_trait_item(&mut self, _it: &'tcx hir::TraitItem<'tcx>) {}

View file

@ -53,7 +53,7 @@ impl ItemLikeVisitor<'tcx> for Collector<'tcx> {
name: None, name: None,
kind: NativeLibKind::Unspecified, kind: NativeLibKind::Unspecified,
cfg: None, cfg: None,
foreign_module: Some(self.tcx.hir().local_def_id(it.hir_id).to_def_id()), foreign_module: Some(it.def_id.to_def_id()),
wasm_import_module: None, wasm_import_module: None,
}; };
let mut kind_specified = false; let mut kind_specified = false;

View file

@ -7,7 +7,9 @@ use rustc_data_structures::stable_hasher::StableHasher;
use rustc_data_structures::sync::{join, par_iter, Lrc, ParallelIterator}; use rustc_data_structures::sync::{join, par_iter, Lrc, ParallelIterator};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::{CtorOf, DefKind}; use rustc_hir::def::{CtorOf, DefKind};
use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc_hir::def_id::{
CrateNum, DefId, DefIndex, LocalDefId, CRATE_DEF_ID, CRATE_DEF_INDEX, LOCAL_CRATE,
};
use rustc_hir::definitions::DefPathData; use rustc_hir::definitions::DefPathData;
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::itemlikevisit::ItemLikeVisitor;
@ -431,7 +433,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
fn encode_info_for_items(&mut self) { fn encode_info_for_items(&mut self) {
let krate = self.tcx.hir().krate(); let krate = self.tcx.hir().krate();
self.encode_info_for_mod(hir::CRATE_HIR_ID, &krate.item.module); self.encode_info_for_mod(CRATE_DEF_ID, &krate.item.module);
// Proc-macro crates only export proc-macro items, which are looked // Proc-macro crates only export proc-macro items, which are looked
// up using `proc_macro_data` // up using `proc_macro_data`
@ -932,9 +934,8 @@ impl EncodeContext<'a, 'tcx> {
self.encode_inferred_outlives(def_id); self.encode_inferred_outlives(def_id);
} }
fn encode_info_for_mod(&mut self, id: hir::HirId, md: &hir::Mod<'_>) { fn encode_info_for_mod(&mut self, local_def_id: LocalDefId, md: &hir::Mod<'_>) {
let tcx = self.tcx; let tcx = self.tcx;
let local_def_id = tcx.hir().local_def_id(id);
let def_id = local_def_id.to_def_id(); let def_id = local_def_id.to_def_id();
debug!("EncodeContext::encode_info_for_mod({:?})", def_id); debug!("EncodeContext::encode_info_for_mod({:?})", def_id);
@ -969,7 +970,7 @@ impl EncodeContext<'a, 'tcx> {
record!(self.tables.children[def_id] <- &[]); record!(self.tables.children[def_id] <- &[]);
} else { } else {
record!(self.tables.children[def_id] <- md.item_ids.iter().map(|item_id| { record!(self.tables.children[def_id] <- md.item_ids.iter().map(|item_id| {
tcx.hir().local_def_id(item_id.id).local_def_index item_id.def_id.local_def_index
})); }));
} }
} }
@ -1312,7 +1313,7 @@ impl EncodeContext<'a, 'tcx> {
EntryKind::Fn(self.lazy(data)) EntryKind::Fn(self.lazy(data))
} }
hir::ItemKind::Mod(ref m) => { hir::ItemKind::Mod(ref m) => {
return self.encode_info_for_mod(item.hir_id, m); return self.encode_info_for_mod(item.def_id, m);
} }
hir::ItemKind::ForeignMod { .. } => EntryKind::ForeignMod, hir::ItemKind::ForeignMod { .. } => EntryKind::ForeignMod,
hir::ItemKind::GlobalAsm(..) => EntryKind::GlobalAsm, hir::ItemKind::GlobalAsm(..) => EntryKind::GlobalAsm,
@ -1410,8 +1411,7 @@ impl EncodeContext<'a, 'tcx> {
hir::ItemKind::ForeignMod { items, .. } => record!(self.tables.children[def_id] <- hir::ItemKind::ForeignMod { items, .. } => record!(self.tables.children[def_id] <-
items items
.iter() .iter()
.map(|foreign_item| tcx.hir().local_def_id( .map(|foreign_item| foreign_item.id.def_id.local_def_index)
foreign_item.id.hir_id).local_def_index)
), ),
hir::ItemKind::Enum(..) => record!(self.tables.children[def_id] <- hir::ItemKind::Enum(..) => record!(self.tables.children[def_id] <-
self.tcx.adt_def(def_id).variants.iter().map(|v| { self.tcx.adt_def(def_id).variants.iter().map(|v| {
@ -1494,7 +1494,7 @@ impl EncodeContext<'a, 'tcx> {
/// Serialize the text of exported macros /// Serialize the text of exported macros
fn encode_info_for_macro_def(&mut self, macro_def: &hir::MacroDef<'_>) { fn encode_info_for_macro_def(&mut self, macro_def: &hir::MacroDef<'_>) {
let def_id = self.tcx.hir().local_def_id(macro_def.hir_id).to_def_id(); let def_id = macro_def.def_id.to_def_id();
record!(self.tables.kind[def_id] <- EntryKind::MacroDef(self.lazy(macro_def.ast.clone()))); record!(self.tables.kind[def_id] <- EntryKind::MacroDef(self.lazy(macro_def.ast.clone())));
self.encode_ident_span(def_id, macro_def.ident); self.encode_ident_span(def_id, macro_def.ident);
} }
@ -1850,17 +1850,15 @@ impl Visitor<'tcx> for EncodeContext<'a, 'tcx> {
} }
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
intravisit::walk_item(self, item); intravisit::walk_item(self, item);
let def_id = self.tcx.hir().local_def_id(item.hir_id);
match item.kind { match item.kind {
hir::ItemKind::ExternCrate(_) | hir::ItemKind::Use(..) => {} // ignore these hir::ItemKind::ExternCrate(_) | hir::ItemKind::Use(..) => {} // ignore these
_ => self.encode_info_for_item(def_id.to_def_id(), item), _ => self.encode_info_for_item(item.def_id.to_def_id(), item),
} }
self.encode_addl_info_for_item(item); self.encode_addl_info_for_item(item);
} }
fn visit_foreign_item(&mut self, ni: &'tcx hir::ForeignItem<'tcx>) { fn visit_foreign_item(&mut self, ni: &'tcx hir::ForeignItem<'tcx>) {
intravisit::walk_foreign_item(self, ni); intravisit::walk_foreign_item(self, ni);
let def_id = self.tcx.hir().local_def_id(ni.hir_id); self.encode_info_for_foreign_item(ni.def_id.to_def_id(), ni);
self.encode_info_for_foreign_item(def_id.to_def_id(), ni);
} }
fn visit_generics(&mut self, generics: &'tcx hir::Generics<'tcx>) { fn visit_generics(&mut self, generics: &'tcx hir::Generics<'tcx>) {
intravisit::walk_generics(self, generics); intravisit::walk_generics(self, generics);
@ -1920,7 +1918,6 @@ impl EncodeContext<'a, 'tcx> {
/// so it's easier to do that here then to wait until we would encounter /// so it's easier to do that here then to wait until we would encounter
/// normally in the visitor walk. /// normally in the visitor walk.
fn encode_addl_info_for_item(&mut self, item: &hir::Item<'_>) { fn encode_addl_info_for_item(&mut self, item: &hir::Item<'_>) {
let def_id = self.tcx.hir().local_def_id(item.hir_id);
match item.kind { match item.kind {
hir::ItemKind::Static(..) hir::ItemKind::Static(..)
| hir::ItemKind::Const(..) | hir::ItemKind::Const(..)
@ -1936,7 +1933,7 @@ impl EncodeContext<'a, 'tcx> {
// no sub-item recording needed in these cases // no sub-item recording needed in these cases
} }
hir::ItemKind::Enum(..) => { hir::ItemKind::Enum(..) => {
let def = self.tcx.adt_def(def_id.to_def_id()); let def = self.tcx.adt_def(item.def_id.to_def_id());
self.encode_fields(def); self.encode_fields(def);
for (i, variant) in def.variants.iter_enumerated() { for (i, variant) in def.variants.iter_enumerated() {
@ -1948,7 +1945,7 @@ impl EncodeContext<'a, 'tcx> {
} }
} }
hir::ItemKind::Struct(ref struct_def, _) => { hir::ItemKind::Struct(ref struct_def, _) => {
let def = self.tcx.adt_def(def_id.to_def_id()); let def = self.tcx.adt_def(item.def_id.to_def_id());
self.encode_fields(def); self.encode_fields(def);
// If the struct has a constructor, encode it. // If the struct has a constructor, encode it.
@ -1958,18 +1955,19 @@ impl EncodeContext<'a, 'tcx> {
} }
} }
hir::ItemKind::Union(..) => { hir::ItemKind::Union(..) => {
let def = self.tcx.adt_def(def_id.to_def_id()); let def = self.tcx.adt_def(item.def_id.to_def_id());
self.encode_fields(def); self.encode_fields(def);
} }
hir::ItemKind::Impl { .. } => { hir::ItemKind::Impl { .. } => {
for &trait_item_def_id in for &trait_item_def_id in
self.tcx.associated_item_def_ids(def_id.to_def_id()).iter() self.tcx.associated_item_def_ids(item.def_id.to_def_id()).iter()
{ {
self.encode_info_for_impl_item(trait_item_def_id); self.encode_info_for_impl_item(trait_item_def_id);
} }
} }
hir::ItemKind::Trait(..) => { hir::ItemKind::Trait(..) => {
for &item_def_id in self.tcx.associated_item_def_ids(def_id.to_def_id()).iter() { for &item_def_id in self.tcx.associated_item_def_ids(item.def_id.to_def_id()).iter()
{
self.encode_info_for_trait_item(item_def_id); self.encode_info_for_trait_item(item_def_id);
} }
} }
@ -1985,15 +1983,14 @@ struct ImplVisitor<'tcx> {
impl<'tcx, 'v> ItemLikeVisitor<'v> for ImplVisitor<'tcx> { impl<'tcx, 'v> ItemLikeVisitor<'v> for ImplVisitor<'tcx> {
fn visit_item(&mut self, item: &hir::Item<'_>) { fn visit_item(&mut self, item: &hir::Item<'_>) {
if let hir::ItemKind::Impl { .. } = item.kind { if let hir::ItemKind::Impl { .. } = item.kind {
let impl_id = self.tcx.hir().local_def_id(item.hir_id); if let Some(trait_ref) = self.tcx.impl_trait_ref(item.def_id.to_def_id()) {
if let Some(trait_ref) = self.tcx.impl_trait_ref(impl_id.to_def_id()) {
let simplified_self_ty = let simplified_self_ty =
ty::fast_reject::simplify_type(self.tcx, trait_ref.self_ty(), false); ty::fast_reject::simplify_type(self.tcx, trait_ref.self_ty(), false);
self.impls self.impls
.entry(trait_ref.def_id) .entry(trait_ref.def_id)
.or_default() .or_default()
.push((impl_id.local_def_index, simplified_self_ty)); .push((item.def_id.local_def_index, simplified_self_ty));
} }
} }
} }

View file

@ -215,7 +215,7 @@ impl<'a> FnLikeNode<'a> {
match self.node { match self.node {
Node::Item(i) => match i.kind { Node::Item(i) => match i.kind {
hir::ItemKind::Fn(ref sig, ref generics, block) => item_fn(ItemFnParts { hir::ItemKind::Fn(ref sig, ref generics, block) => item_fn(ItemFnParts {
id: i.hir_id, id: i.hir_id(),
ident: i.ident, ident: i.ident,
decl: &sig.decl, decl: &sig.decl,
body: block, body: block,
@ -229,13 +229,13 @@ impl<'a> FnLikeNode<'a> {
}, },
Node::TraitItem(ti) => match ti.kind { Node::TraitItem(ti) => match ti.kind {
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(body)) => { hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(body)) => {
method(ti.hir_id, ti.ident, sig, None, body, ti.span, &ti.attrs) method(ti.hir_id(), ti.ident, sig, None, body, ti.span, &ti.attrs)
} }
_ => bug!("trait method FnLikeNode that is not fn-like"), _ => bug!("trait method FnLikeNode that is not fn-like"),
}, },
Node::ImplItem(ii) => match ii.kind { Node::ImplItem(ii) => match ii.kind {
hir::ImplItemKind::Fn(ref sig, body) => { hir::ImplItemKind::Fn(ref sig, body) => {
method(ii.hir_id, ii.ident, sig, Some(&ii.vis), body, ii.span, &ii.attrs) method(ii.hir_id(), ii.ident, sig, Some(&ii.vis), body, ii.span, &ii.attrs)
} }
_ => bug!("impl method FnLikeNode that is not fn-like"), _ => bug!("impl method FnLikeNode that is not fn-like"),
}, },

View file

@ -55,22 +55,19 @@ fn insert_vec_map<K: Idx, V: Clone>(map: &mut IndexVec<K, Option<V>>, k: K, v: V
map[k] = Some(v); map[k] = Some(v);
} }
fn hash(
hcx: &mut StableHashingContext<'_>,
input: impl for<'a> HashStable<StableHashingContext<'a>>,
) -> Fingerprint {
let mut stable_hasher = StableHasher::new();
input.hash_stable(hcx, &mut stable_hasher);
stable_hasher.finish()
}
fn hash_body( fn hash_body(
hcx: &mut StableHashingContext<'_>, hcx: &mut StableHashingContext<'_>,
def_path_hash: DefPathHash, def_path_hash: DefPathHash,
item_like: impl for<'a> HashStable<StableHashingContext<'a>>, item_like: impl for<'a> HashStable<StableHashingContext<'a>>,
hir_body_nodes: &mut Vec<(DefPathHash, Fingerprint)>, hir_body_nodes: &mut Vec<(DefPathHash, Fingerprint)>,
) -> Fingerprint { ) -> Fingerprint {
let hash = hash(hcx, HirItemLike { item_like: &item_like }); let hash = {
let mut stable_hasher = StableHasher::new();
hcx.while_hashing_hir_bodies(true, |hcx| {
item_like.hash_stable(hcx, &mut stable_hasher);
});
stable_hasher.finish()
};
hir_body_nodes.push((def_path_hash, hash)); hir_body_nodes.push((def_path_hash, hash));
hash hash
} }
@ -309,7 +306,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
fn visit_nested_item(&mut self, item: ItemId) { fn visit_nested_item(&mut self, item: ItemId) {
debug!("visit_nested_item: {:?}", item); debug!("visit_nested_item: {:?}", item);
self.visit_item(self.krate.item(item.id)); self.visit_item(self.krate.item(item));
} }
fn visit_nested_trait_item(&mut self, item_id: TraitItemId) { fn visit_nested_trait_item(&mut self, item_id: TraitItemId) {
@ -338,13 +335,10 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
fn visit_item(&mut self, i: &'hir Item<'hir>) { fn visit_item(&mut self, i: &'hir Item<'hir>) {
debug!("visit_item: {:?}", i); debug!("visit_item: {:?}", i);
debug_assert_eq!( self.with_dep_node_owner(i.def_id, i, |this, hash| {
i.hir_id.owner, let hir_id = i.hir_id();
self.definitions.opt_hir_id_to_local_def_id(i.hir_id).unwrap() this.insert_with_hash(i.span, hir_id, Node::Item(i), hash);
); this.with_parent(hir_id, |this| {
self.with_dep_node_owner(i.hir_id.owner, i, |this, hash| {
this.insert_with_hash(i.span, i.hir_id, Node::Item(i), hash);
this.with_parent(i.hir_id, |this| {
if let ItemKind::Struct(ref struct_def, _) = i.kind { if let ItemKind::Struct(ref struct_def, _) = i.kind {
// If this is a tuple or unit-like struct, register the constructor. // If this is a tuple or unit-like struct, register the constructor.
if let Some(ctor_hir_id) = struct_def.ctor_hir_id() { if let Some(ctor_hir_id) = struct_def.ctor_hir_id() {
@ -357,14 +351,10 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
} }
fn visit_foreign_item(&mut self, fi: &'hir ForeignItem<'hir>) { fn visit_foreign_item(&mut self, fi: &'hir ForeignItem<'hir>) {
debug_assert_eq!( self.with_dep_node_owner(fi.def_id, fi, |this, hash| {
fi.hir_id.owner, this.insert_with_hash(fi.span, fi.hir_id(), Node::ForeignItem(fi), hash);
self.definitions.opt_hir_id_to_local_def_id(fi.hir_id).unwrap()
);
self.with_dep_node_owner(fi.hir_id.owner, fi, |this, hash| {
this.insert_with_hash(fi.span, fi.hir_id, Node::ForeignItem(fi), hash);
this.with_parent(fi.hir_id, |this| { this.with_parent(fi.hir_id(), |this| {
intravisit::walk_foreign_item(this, fi); intravisit::walk_foreign_item(this, fi);
}); });
}); });
@ -394,28 +384,20 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
} }
fn visit_trait_item(&mut self, ti: &'hir TraitItem<'hir>) { fn visit_trait_item(&mut self, ti: &'hir TraitItem<'hir>) {
debug_assert_eq!( self.with_dep_node_owner(ti.def_id, ti, |this, hash| {
ti.hir_id.owner, this.insert_with_hash(ti.span, ti.hir_id(), Node::TraitItem(ti), hash);
self.definitions.opt_hir_id_to_local_def_id(ti.hir_id).unwrap()
);
self.with_dep_node_owner(ti.hir_id.owner, ti, |this, hash| {
this.insert_with_hash(ti.span, ti.hir_id, Node::TraitItem(ti), hash);
this.with_parent(ti.hir_id, |this| { this.with_parent(ti.hir_id(), |this| {
intravisit::walk_trait_item(this, ti); intravisit::walk_trait_item(this, ti);
}); });
}); });
} }
fn visit_impl_item(&mut self, ii: &'hir ImplItem<'hir>) { fn visit_impl_item(&mut self, ii: &'hir ImplItem<'hir>) {
debug_assert_eq!( self.with_dep_node_owner(ii.def_id, ii, |this, hash| {
ii.hir_id.owner, this.insert_with_hash(ii.span, ii.hir_id(), Node::ImplItem(ii), hash);
self.definitions.opt_hir_id_to_local_def_id(ii.hir_id).unwrap()
);
self.with_dep_node_owner(ii.hir_id.owner, ii, |this, hash| {
this.insert_with_hash(ii.span, ii.hir_id, Node::ImplItem(ii), hash);
this.with_parent(ii.hir_id, |this| { this.with_parent(ii.hir_id(), |this| {
intravisit::walk_impl_item(this, ii); intravisit::walk_impl_item(this, ii);
}); });
}); });
@ -532,15 +514,15 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
// Exported macros are visited directly from the crate root, // Exported macros are visited directly from the crate root,
// so they do not have `parent_node` set. // so they do not have `parent_node` set.
// Find the correct enclosing module from their DefKey. // Find the correct enclosing module from their DefKey.
let def_key = self.definitions.def_key(macro_def.hir_id.owner); let def_key = self.definitions.def_key(macro_def.def_id);
let parent = def_key.parent.map_or(hir::CRATE_HIR_ID, |local_def_index| { let parent = def_key.parent.map_or(hir::CRATE_HIR_ID, |local_def_index| {
self.definitions.local_def_id_to_hir_id(LocalDefId { local_def_index }) self.definitions.local_def_id_to_hir_id(LocalDefId { local_def_index })
}); });
self.with_parent(parent, |this| { self.with_parent(parent, |this| {
this.with_dep_node_owner(macro_def.hir_id.owner, macro_def, |this, hash| { this.with_dep_node_owner(macro_def.def_id, macro_def, |this, hash| {
this.insert_with_hash( this.insert_with_hash(
macro_def.span, macro_def.span,
macro_def.hir_id, macro_def.hir_id(),
Node::MacroDef(macro_def), Node::MacroDef(macro_def),
hash, hash,
); );
@ -590,18 +572,3 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
self.visit_nested_foreign_item(id); self.visit_nested_foreign_item(id);
} }
} }
struct HirItemLike<T> {
item_like: T,
}
impl<'hir, T> HashStable<StableHashingContext<'hir>> for HirItemLike<T>
where
T: HashStable<StableHashingContext<'hir>>,
{
fn hash_stable(&self, hcx: &mut StableHashingContext<'hir>, hasher: &mut StableHasher) {
hcx.while_hashing_hir_bodies(true, |hcx| {
self.item_like.hash_stable(hcx, hasher);
});
}
}

View file

@ -300,29 +300,29 @@ impl<'hir> Map<'hir> {
self.find_entry(id).unwrap() self.find_entry(id).unwrap()
} }
pub fn item(&self, id: HirId) -> &'hir Item<'hir> { pub fn item(&self, id: ItemId) -> &'hir Item<'hir> {
match self.find(id).unwrap() { match self.find(id.hir_id()).unwrap() {
Node::Item(item) => item, Node::Item(item) => item,
_ => bug!(), _ => bug!(),
} }
} }
pub fn trait_item(&self, id: TraitItemId) -> &'hir TraitItem<'hir> { pub fn trait_item(&self, id: TraitItemId) -> &'hir TraitItem<'hir> {
match self.find(id.hir_id).unwrap() { match self.find(id.hir_id()).unwrap() {
Node::TraitItem(item) => item, Node::TraitItem(item) => item,
_ => bug!(), _ => bug!(),
} }
} }
pub fn impl_item(&self, id: ImplItemId) -> &'hir ImplItem<'hir> { pub fn impl_item(&self, id: ImplItemId) -> &'hir ImplItem<'hir> {
match self.find(id.hir_id).unwrap() { match self.find(id.hir_id()).unwrap() {
Node::ImplItem(item) => item, Node::ImplItem(item) => item,
_ => bug!(), _ => bug!(),
} }
} }
pub fn foreign_item(&self, id: ForeignItemId) -> &'hir ForeignItem<'hir> { pub fn foreign_item(&self, id: ForeignItemId) -> &'hir ForeignItem<'hir> {
match self.find(id.hir_id).unwrap() { match self.find(id.hir_id()).unwrap() {
Node::ForeignItem(item) => item, Node::ForeignItem(item) => item,
_ => bug!(), _ => bug!(),
} }
@ -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[..]) self.tcx.all_local_trait_impls(LOCAL_CRATE).get(&trait_did).map_or(&[], |xs| &xs[..])
} }
@ -479,19 +479,19 @@ impl<'hir> Map<'hir> {
let module = self.tcx.hir_module_items(module); let module = self.tcx.hir_module_items(module);
for id in &module.items { for id in &module.items {
visitor.visit_item(self.expect_item(*id)); visitor.visit_item(self.item(*id));
} }
for id in &module.trait_items { for id in &module.trait_items {
visitor.visit_trait_item(self.expect_trait_item(id.hir_id)); visitor.visit_trait_item(self.trait_item(*id));
} }
for id in &module.impl_items { for id in &module.impl_items {
visitor.visit_impl_item(self.expect_impl_item(id.hir_id)); visitor.visit_impl_item(self.impl_item(*id));
} }
for id in &module.foreign_items { for id in &module.foreign_items {
visitor.visit_foreign_item(self.expect_foreign_item(id.hir_id)); visitor.visit_foreign_item(self.foreign_item(*id));
} }
} }
@ -500,7 +500,7 @@ impl<'hir> Map<'hir> {
V: Visitor<'hir>, V: Visitor<'hir>,
{ {
for id in self.krate().exported_macros { for id in self.krate().exported_macros {
visitor.visit_macro_def(self.expect_macro_def(id.hir_id)); visitor.visit_macro_def(self.expect_macro_def(id.hir_id()));
} }
} }
@ -863,7 +863,7 @@ impl<'hir> Map<'hir> {
Node::Variant(ref v) => v.attrs, Node::Variant(ref v) => v.attrs,
Node::Field(ref f) => f.attrs, Node::Field(ref f) => f.attrs,
Node::Expr(ref e) => &*e.attrs, Node::Expr(ref e) => &*e.attrs,
Node::Stmt(ref s) => s.kind.attrs(|id| self.item(id.id)), Node::Stmt(ref s) => s.kind.attrs(|id| self.item(id)),
Node::Arm(ref a) => &*a.attrs, Node::Arm(ref a) => &*a.attrs,
Node::GenericParam(param) => param.attrs, Node::GenericParam(param) => param.attrs,
// Unit/tuple structs/variants take the attributes straight from // Unit/tuple structs/variants take the attributes straight from
@ -977,7 +977,7 @@ impl<'hir> intravisit::Map<'hir> for Map<'hir> {
self.body(id) self.body(id)
} }
fn item(&self, id: HirId) -> &'hir Item<'hir> { fn item(&self, id: ItemId) -> &'hir Item<'hir> {
self.item(id) self.item(id)
} }
@ -994,47 +994,6 @@ impl<'hir> intravisit::Map<'hir> for Map<'hir> {
} }
} }
trait Named {
fn name(&self) -> Symbol;
}
impl<T: Named> Named for Spanned<T> {
fn name(&self) -> Symbol {
self.node.name()
}
}
impl Named for Item<'_> {
fn name(&self) -> Symbol {
self.ident.name
}
}
impl Named for ForeignItem<'_> {
fn name(&self) -> Symbol {
self.ident.name
}
}
impl Named for Variant<'_> {
fn name(&self) -> Symbol {
self.ident.name
}
}
impl Named for StructField<'_> {
fn name(&self) -> Symbol {
self.ident.name
}
}
impl Named for TraitItem<'_> {
fn name(&self) -> Symbol {
self.ident.name
}
}
impl Named for ImplItem<'_> {
fn name(&self) -> Symbol {
self.ident.name
}
}
pub(super) fn index_hir<'tcx>(tcx: TyCtxt<'tcx>, cnum: CrateNum) -> &'tcx IndexedHir<'tcx> { pub(super) fn index_hir<'tcx>(tcx: TyCtxt<'tcx>, cnum: CrateNum) -> &'tcx IndexedHir<'tcx> {
assert_eq!(cnum, LOCAL_CRATE); assert_eq!(cnum, LOCAL_CRATE);

View file

@ -73,11 +73,7 @@ pub fn provide(providers: &mut Providers) {
}; };
providers.hir_crate = |tcx, _| tcx.untracked_crate; providers.hir_crate = |tcx, _| tcx.untracked_crate;
providers.index_hir = map::index_hir; providers.index_hir = map::index_hir;
providers.hir_module_items = |tcx, id| { providers.hir_module_items = |tcx, id| &tcx.untracked_crate.modules[&id];
let hir = tcx.hir();
let module = hir.local_def_id_to_hir_id(id);
&tcx.untracked_crate.modules[&module]
};
providers.hir_owner = |tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].signature; providers.hir_owner = |tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].signature;
providers.hir_owner_nodes = |tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].with_bodies.as_deref(); providers.hir_owner_nodes = |tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].with_bodies.as_deref();
providers.def_span = |tcx, def_id| tcx.hir().span_if_local(def_id).unwrap_or(DUMMY_SP); providers.def_span = |tcx, def_id| tcx.hir().span_if_local(def_id).unwrap_or(DUMMY_SP);

View file

@ -55,8 +55,7 @@ impl<'ctx> rustc_hir::HashStableContext for StableHashingContext<'ctx> {
let item_ids_hash = item_ids let item_ids_hash = item_ids
.iter() .iter()
.map(|id| { .map(|id| {
let (def_path_hash, local_id) = id.id.to_stable_hash_key(hcx); let def_path_hash = id.to_stable_hash_key(hcx);
debug_assert_eq!(local_id, hir::ItemLocalId::from_u32(0));
def_path_hash.0 def_path_hash.0
}) })
.fold(Fingerprint::ZERO, |a, b| a.combine_commutative(b)); .fold(Fingerprint::ZERO, |a, b| a.combine_commutative(b));

View file

@ -7,7 +7,7 @@ use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE}; use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
use rustc_hir::HirId; use rustc_hir::{HirId, ItemId};
use rustc_session::config::OptLevel; use rustc_session::config::OptLevel;
use rustc_span::source_map::Span; use rustc_span::source_map::Span;
use rustc_span::symbol::Symbol; use rustc_span::symbol::Symbol;
@ -43,7 +43,7 @@ pub enum InstantiationMode {
pub enum MonoItem<'tcx> { pub enum MonoItem<'tcx> {
Fn(Instance<'tcx>), Fn(Instance<'tcx>),
Static(DefId), Static(DefId),
GlobalAsm(HirId), GlobalAsm(ItemId),
} }
impl<'tcx> MonoItem<'tcx> { impl<'tcx> MonoItem<'tcx> {
@ -71,9 +71,8 @@ impl<'tcx> MonoItem<'tcx> {
match *self { match *self {
MonoItem::Fn(instance) => tcx.symbol_name(instance), MonoItem::Fn(instance) => tcx.symbol_name(instance),
MonoItem::Static(def_id) => tcx.symbol_name(Instance::mono(tcx, def_id)), MonoItem::Static(def_id) => tcx.symbol_name(Instance::mono(tcx, def_id)),
MonoItem::GlobalAsm(hir_id) => { MonoItem::GlobalAsm(item_id) => {
let def_id = tcx.hir().local_def_id(hir_id); SymbolName::new(tcx, &format!("global_asm_{:?}", item_id.def_id))
SymbolName::new(tcx, &format!("global_asm_{:?}", def_id))
} }
} }
} }
@ -178,7 +177,7 @@ impl<'tcx> MonoItem<'tcx> {
MonoItem::Static(def_id) => { MonoItem::Static(def_id) => {
def_id.as_local().map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id)) def_id.as_local().map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id))
} }
MonoItem::GlobalAsm(hir_id) => Some(hir_id), MonoItem::GlobalAsm(item_id) => Some(item_id.hir_id()),
} }
.map(|hir_id| tcx.hir().span(hir_id)) .map(|hir_id| tcx.hir().span(hir_id))
} }
@ -195,9 +194,9 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for MonoItem<'tcx> {
MonoItem::Static(def_id) => { MonoItem::Static(def_id) => {
def_id.hash_stable(hcx, hasher); def_id.hash_stable(hcx, hasher);
} }
MonoItem::GlobalAsm(node_id) => { MonoItem::GlobalAsm(item_id) => {
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| { hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
node_id.hash_stable(hcx, hasher); item_id.hash_stable(hcx, hasher);
}) })
} }
} }
@ -351,7 +350,7 @@ impl<'tcx> CodegenUnit<'tcx> {
MonoItem::Static(def_id) => { MonoItem::Static(def_id) => {
def_id.as_local().map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id)) def_id.as_local().map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id))
} }
MonoItem::GlobalAsm(hir_id) => Some(hir_id), MonoItem::GlobalAsm(item_id) => Some(item_id.hir_id()),
}, },
item.symbol_name(tcx), item.symbol_name(tcx),
) )

View file

@ -956,7 +956,7 @@ rustc_queries! {
/// Passing in any other crate will cause an ICE. /// Passing in any other crate will cause an ICE.
/// ///
/// [`LOCAL_CRATE`]: rustc_hir::def_id::LOCAL_CRATE /// [`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" } desc { "local trait impls" }
} }

View file

@ -289,7 +289,7 @@ impl<'v> hir::intravisit::Visitor<'v> for TraitObjectVisitor<'v> {
} }
hir::TyKind::OpaqueDef(item_id, _) => { hir::TyKind::OpaqueDef(item_id, _) => {
self.0.push(ty); self.0.push(ty);
let item = self.1.expect_item(item_id.id); let item = self.1.item(item_id);
hir::intravisit::walk_item(self, item); hir::intravisit::walk_item(self, item);
} }
_ => {} _ => {}

View file

@ -821,7 +821,7 @@ fn foo(&self) -> Self::T { String::new() }
// an assoc type as a return type (#72076). // an assoc type as a return type (#72076).
if let hir::Defaultness::Default { has_value: true } = item.defaultness if let hir::Defaultness::Default { has_value: true } = item.defaultness
{ {
if self.type_of(self.hir().local_def_id(item.id.hir_id)) == found { if self.type_of(item.id.def_id) == found {
db.span_label( db.span_label(
item.span, item.span,
"associated type defaults can't be assumed inside the \ "associated type defaults can't be assumed inside the \
@ -841,7 +841,7 @@ fn foo(&self) -> Self::T { String::new() }
})) => { })) => {
for item in &items[..] { for item in &items[..] {
if let hir::AssocItemKind::Type = item.kind { if let hir::AssocItemKind::Type = item.kind {
if self.type_of(self.hir().local_def_id(item.id.hir_id)) == found { if self.type_of(item.id.def_id) == found {
db.span_label(item.span, "expected this associated type"); db.span_label(item.span, "expected this associated type");
return true; return true;
} }

View file

@ -2107,11 +2107,9 @@ fn for_each_def(tcx: TyCtxt<'_>, mut collect_fn: impl for<'b> FnMut(&'b Ident, N
continue; continue;
} }
if let Some(local_def_id) = hir.definitions().opt_hir_id_to_local_def_id(item.hir_id) { let def_id = item.def_id.to_def_id();
let def_id = local_def_id.to_def_id(); let ns = tcx.def_kind(def_id).ns().unwrap_or(Namespace::TypeNS);
let ns = tcx.def_kind(def_id).ns().unwrap_or(Namespace::TypeNS); collect_fn(&item.ident, ns, def_id);
collect_fn(&item.ident, ns, def_id);
}
} }
// Now take care of extern crate items. // Now take care of extern crate items.

View file

@ -4,9 +4,8 @@ use crate::ty::fast_reject;
use crate::ty::fold::TypeFoldable; use crate::ty::fold::TypeFoldable;
use crate::ty::{Ty, TyCtxt}; use crate::ty::{Ty, TyCtxt};
use rustc_hir as hir; 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::definitions::DefPathHash;
use rustc_hir::HirId;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@ -201,7 +200,7 @@ impl<'tcx> TyCtxt<'tcx> {
pub(super) fn all_local_trait_impls<'tcx>( pub(super) fn all_local_trait_impls<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
krate: CrateNum, krate: CrateNum,
) -> &'tcx BTreeMap<DefId, Vec<HirId>> { ) -> &'tcx BTreeMap<DefId, Vec<LocalDefId>> {
&tcx.hir_crate(krate).trait_impls &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) { for &impl_def_id in tcx.hir().trait_impls(trait_id) {
let impl_def_id = tcx.hir().local_def_id(hir_id).to_def_id(); let impl_def_id = impl_def_id.to_def_id();
let impl_self_ty = tcx.type_of(impl_def_id); let impl_self_ty = tcx.type_of(impl_def_id);
if impl_self_ty.references_error() { if impl_self_ty.references_error() {

View file

@ -767,7 +767,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
let hir = self.infcx.tcx.hir(); let hir = self.infcx.tcx.hir();
if let hir::TyKind::OpaqueDef(id, _) = hir_ty.kind { if let hir::TyKind::OpaqueDef(id, _) = hir_ty.kind {
let opaque_ty = hir.item(id.id); let opaque_ty = hir.item(id);
if let hir::ItemKind::OpaqueTy(hir::OpaqueTy { if let hir::ItemKind::OpaqueTy(hir::OpaqueTy {
bounds: bounds:
[hir::GenericBound::LangItemTrait( [hir::GenericBound::LangItemTrait(

View file

@ -1013,13 +1013,12 @@ impl ItemLikeVisitor<'v> for RootCollector<'_, 'v> {
| hir::ItemKind::Union(_, ref generics) => { | hir::ItemKind::Union(_, ref generics) => {
if generics.params.is_empty() { if generics.params.is_empty() {
if self.mode == MonoItemCollectionMode::Eager { if self.mode == MonoItemCollectionMode::Eager {
let def_id = self.tcx.hir().local_def_id(item.hir_id);
debug!( debug!(
"RootCollector: ADT drop-glue for {}", "RootCollector: ADT drop-glue for {}",
self.tcx.def_path_str(def_id.to_def_id()) self.tcx.def_path_str(item.def_id.to_def_id())
); );
let ty = Instance::new(def_id.to_def_id(), InternalSubsts::empty()) let ty = Instance::new(item.def_id.to_def_id(), InternalSubsts::empty())
.ty(self.tcx, ty::ParamEnv::reveal_all()); .ty(self.tcx, ty::ParamEnv::reveal_all());
visit_drop_use(self.tcx, ty, true, DUMMY_SP, self.output); visit_drop_use(self.tcx, ty, true, DUMMY_SP, self.output);
} }
@ -1028,29 +1027,28 @@ impl ItemLikeVisitor<'v> for RootCollector<'_, 'v> {
hir::ItemKind::GlobalAsm(..) => { hir::ItemKind::GlobalAsm(..) => {
debug!( debug!(
"RootCollector: ItemKind::GlobalAsm({})", "RootCollector: ItemKind::GlobalAsm({})",
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.hir_id).to_def_id()) self.tcx.def_path_str(item.def_id.to_def_id())
); );
self.output.push(dummy_spanned(MonoItem::GlobalAsm(item.hir_id))); self.output.push(dummy_spanned(MonoItem::GlobalAsm(item.item_id())));
} }
hir::ItemKind::Static(..) => { hir::ItemKind::Static(..) => {
let def_id = self.tcx.hir().local_def_id(item.hir_id).to_def_id(); debug!(
debug!("RootCollector: ItemKind::Static({})", self.tcx.def_path_str(def_id)); "RootCollector: ItemKind::Static({})",
self.output.push(dummy_spanned(MonoItem::Static(def_id))); self.tcx.def_path_str(item.def_id.to_def_id())
);
self.output.push(dummy_spanned(MonoItem::Static(item.def_id.to_def_id())));
} }
hir::ItemKind::Const(..) => { hir::ItemKind::Const(..) => {
// const items only generate mono items if they are // const items only generate mono items if they are
// actually used somewhere. Just declaring them is insufficient. // actually used somewhere. Just declaring them is insufficient.
// but even just declaring them must collect the items they refer to // but even just declaring them must collect the items they refer to
let def_id = self.tcx.hir().local_def_id(item.hir_id); if let Ok(val) = self.tcx.const_eval_poly(item.def_id.to_def_id()) {
if let Ok(val) = self.tcx.const_eval_poly(def_id.to_def_id()) {
collect_const_value(self.tcx, val, &mut self.output); collect_const_value(self.tcx, val, &mut self.output);
} }
} }
hir::ItemKind::Fn(..) => { hir::ItemKind::Fn(..) => {
let def_id = self.tcx.hir().local_def_id(item.hir_id); self.push_if_root(item.def_id);
self.push_if_root(def_id);
} }
} }
} }
@ -1062,8 +1060,7 @@ impl ItemLikeVisitor<'v> for RootCollector<'_, 'v> {
fn visit_impl_item(&mut self, ii: &'v hir::ImplItem<'v>) { fn visit_impl_item(&mut self, ii: &'v hir::ImplItem<'v>) {
if let hir::ImplItemKind::Fn(hir::FnSig { .. }, _) = ii.kind { if let hir::ImplItemKind::Fn(hir::FnSig { .. }, _) = ii.kind {
let def_id = self.tcx.hir().local_def_id(ii.hir_id); self.push_if_root(ii.def_id);
self.push_if_root(def_id);
} }
} }
@ -1156,14 +1153,12 @@ fn create_mono_items_for_default_impls<'tcx>(
} }
} }
let impl_def_id = tcx.hir().local_def_id(item.hir_id);
debug!( debug!(
"create_mono_items_for_default_impls(item={})", "create_mono_items_for_default_impls(item={})",
tcx.def_path_str(impl_def_id.to_def_id()) tcx.def_path_str(item.def_id.to_def_id())
); );
if let Some(trait_ref) = tcx.impl_trait_ref(impl_def_id) { if let Some(trait_ref) = tcx.impl_trait_ref(item.def_id) {
let param_env = ty::ParamEnv::reveal_all(); let param_env = ty::ParamEnv::reveal_all();
let trait_ref = tcx.normalize_erasing_regions(param_env, trait_ref); let trait_ref = tcx.normalize_erasing_regions(param_env, trait_ref);
let overridden_methods: FxHashSet<_> = let overridden_methods: FxHashSet<_> =

View file

@ -314,7 +314,7 @@ fn characteristic_def_id_of_mono_item<'tcx>(
Some(def_id) Some(def_id)
} }
MonoItem::Static(def_id) => Some(def_id), MonoItem::Static(def_id) => Some(def_id),
MonoItem::GlobalAsm(hir_id) => Some(tcx.hir().local_def_id(hir_id).to_def_id()), MonoItem::GlobalAsm(item_id) => Some(item_id.def_id.to_def_id()),
} }
} }
@ -405,11 +405,10 @@ fn mono_item_visibility(
Visibility::Hidden Visibility::Hidden
}; };
} }
MonoItem::GlobalAsm(hir_id) => { MonoItem::GlobalAsm(item_id) => {
let def_id = tcx.hir().local_def_id(*hir_id); return if tcx.is_reachable_non_generic(item_id.def_id) {
return if tcx.is_reachable_non_generic(def_id) {
*can_be_internalized = false; *can_be_internalized = false;
default_visibility(tcx, def_id.to_def_id(), false) default_visibility(tcx, item_id.def_id.to_def_id(), false)
} else { } else {
Visibility::Hidden Visibility::Hidden
}; };

View file

@ -29,7 +29,7 @@ pub(crate) fn target_from_impl_item<'tcx>(
match impl_item.kind { match impl_item.kind {
hir::ImplItemKind::Const(..) => Target::AssocConst, hir::ImplItemKind::Const(..) => Target::AssocConst,
hir::ImplItemKind::Fn(..) => { hir::ImplItemKind::Fn(..) => {
let parent_hir_id = tcx.hir().get_parent_item(impl_item.hir_id); let parent_hir_id = tcx.hir().get_parent_item(impl_item.hir_id());
let containing_item = tcx.hir().expect_item(parent_hir_id); let containing_item = tcx.hir().expect_item(parent_hir_id);
let containing_impl_is_for_trait = match &containing_item.kind { let containing_impl_is_for_trait = match &containing_item.kind {
hir::ItemKind::Impl(impl_) => impl_.of_trait.is_some(), hir::ItemKind::Impl(impl_) => impl_.of_trait.is_some(),
@ -1058,7 +1058,7 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
fn visit_item(&mut self, item: &'tcx Item<'tcx>) { fn visit_item(&mut self, item: &'tcx Item<'tcx>) {
let target = Target::from_item(item); let target = Target::from_item(item);
self.check_attributes( self.check_attributes(
item.hir_id, item.hir_id(),
item.attrs, item.attrs,
&item.span, &item.span,
target, target,
@ -1081,7 +1081,13 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
fn visit_trait_item(&mut self, trait_item: &'tcx TraitItem<'tcx>) { fn visit_trait_item(&mut self, trait_item: &'tcx TraitItem<'tcx>) {
let target = Target::from_trait_item(trait_item); let target = Target::from_trait_item(trait_item);
self.check_attributes(trait_item.hir_id, &trait_item.attrs, &trait_item.span, target, None); self.check_attributes(
trait_item.hir_id(),
&trait_item.attrs,
&trait_item.span,
target,
None,
);
intravisit::walk_trait_item(self, trait_item) intravisit::walk_trait_item(self, trait_item)
} }
@ -1104,7 +1110,7 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
fn visit_foreign_item(&mut self, f_item: &'tcx ForeignItem<'tcx>) { fn visit_foreign_item(&mut self, f_item: &'tcx ForeignItem<'tcx>) {
let target = Target::from_foreign_item(f_item); let target = Target::from_foreign_item(f_item);
self.check_attributes( self.check_attributes(
f_item.hir_id, f_item.hir_id(),
&f_item.attrs, &f_item.attrs,
&f_item.span, &f_item.span,
target, target,
@ -1115,7 +1121,7 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) { fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
let target = target_from_impl_item(self.tcx, impl_item); let target = target_from_impl_item(self.tcx, impl_item);
self.check_attributes(impl_item.hir_id, &impl_item.attrs, &impl_item.span, target, None); self.check_attributes(impl_item.hir_id(), &impl_item.attrs, &impl_item.span, target, None);
intravisit::walk_impl_item(self, impl_item) intravisit::walk_impl_item(self, impl_item)
} }
@ -1149,7 +1155,7 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
fn visit_macro_def(&mut self, macro_def: &'tcx hir::MacroDef<'tcx>) { fn visit_macro_def(&mut self, macro_def: &'tcx hir::MacroDef<'tcx>) {
self.check_attributes( self.check_attributes(
macro_def.hir_id, macro_def.hir_id(),
macro_def.attrs, macro_def.attrs,
&macro_def.span, &macro_def.span,
Target::MacroDef, Target::MacroDef,

View file

@ -188,8 +188,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
match node { match node {
Node::Item(item) => match item.kind { Node::Item(item) => match item.kind {
hir::ItemKind::Struct(..) | hir::ItemKind::Union(..) => { hir::ItemKind::Struct(..) | hir::ItemKind::Union(..) => {
let def_id = self.tcx.hir().local_def_id(item.hir_id); let def = self.tcx.adt_def(item.def_id);
let def = self.tcx.adt_def(def_id);
self.repr_has_repr_c = def.repr.c(); self.repr_has_repr_c = def.repr.c();
intravisit::walk_item(self, &item); intravisit::walk_item(self, &item);
@ -329,7 +328,7 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
fn visit_ty(&mut self, ty: &'tcx hir::Ty<'tcx>) { fn visit_ty(&mut self, ty: &'tcx hir::Ty<'tcx>) {
if let TyKind::OpaqueDef(item_id, _) = ty.kind { if let TyKind::OpaqueDef(item_id, _) = ty.kind {
let item = self.tcx.hir().expect_item(item_id.id); let item = self.tcx.hir().item(item_id);
intravisit::walk_item(self, item); intravisit::walk_item(self, item);
} }
intravisit::walk_ty(self, ty); intravisit::walk_ty(self, ty);
@ -395,9 +394,10 @@ struct LifeSeeder<'k, 'tcx> {
impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> { impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
fn visit_item(&mut self, item: &hir::Item<'_>) { fn visit_item(&mut self, item: &hir::Item<'_>) {
let allow_dead_code = has_allow_dead_code_or_lang_attr(self.tcx, item.hir_id, &item.attrs); let allow_dead_code =
has_allow_dead_code_or_lang_attr(self.tcx, item.hir_id(), &item.attrs);
if allow_dead_code { if allow_dead_code {
self.worklist.push(item.hir_id); self.worklist.push(item.hir_id());
} }
match item.kind { match item.kind {
hir::ItemKind::Enum(ref enum_def, _) => { hir::ItemKind::Enum(ref enum_def, _) => {
@ -413,24 +413,24 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
} }
hir::ItemKind::Impl(hir::Impl { ref of_trait, items, .. }) => { hir::ItemKind::Impl(hir::Impl { ref of_trait, items, .. }) => {
if of_trait.is_some() { if of_trait.is_some() {
self.worklist.push(item.hir_id); self.worklist.push(item.hir_id());
} }
for impl_item_ref in items { for impl_item_ref in items {
let impl_item = self.krate.impl_item(impl_item_ref.id); let impl_item = self.krate.impl_item(impl_item_ref.id);
if of_trait.is_some() if of_trait.is_some()
|| has_allow_dead_code_or_lang_attr( || has_allow_dead_code_or_lang_attr(
self.tcx, self.tcx,
impl_item.hir_id, impl_item.hir_id(),
&impl_item.attrs, &impl_item.attrs,
) )
{ {
self.worklist.push(impl_item_ref.id.hir_id); self.worklist.push(impl_item_ref.id.hir_id());
} }
} }
} }
hir::ItemKind::Struct(ref variant_data, _) => { hir::ItemKind::Struct(ref variant_data, _) => {
if let Some(ctor_hir_id) = variant_data.ctor_hir_id() { if let Some(ctor_hir_id) = variant_data.ctor_hir_id() {
self.struct_constructors.insert(ctor_hir_id, item.hir_id); self.struct_constructors.insert(ctor_hir_id, item.hir_id());
} }
} }
_ => (), _ => (),
@ -440,9 +440,9 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
fn visit_trait_item(&mut self, trait_item: &hir::TraitItem<'_>) { fn visit_trait_item(&mut self, trait_item: &hir::TraitItem<'_>) {
use hir::TraitItemKind::{Const, Fn}; use hir::TraitItemKind::{Const, Fn};
if matches!(trait_item.kind, Const(_, Some(_)) | Fn(_, hir::TraitFn::Provided(_))) if matches!(trait_item.kind, Const(_, Some(_)) | Fn(_, hir::TraitFn::Provided(_)))
&& has_allow_dead_code_or_lang_attr(self.tcx, trait_item.hir_id, &trait_item.attrs) && has_allow_dead_code_or_lang_attr(self.tcx, trait_item.hir_id(), &trait_item.attrs)
{ {
self.worklist.push(trait_item.hir_id); self.worklist.push(trait_item.hir_id());
} }
} }
@ -453,9 +453,13 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
fn visit_foreign_item(&mut self, foreign_item: &hir::ForeignItem<'_>) { fn visit_foreign_item(&mut self, foreign_item: &hir::ForeignItem<'_>) {
use hir::ForeignItemKind::{Fn, Static}; use hir::ForeignItemKind::{Fn, Static};
if matches!(foreign_item.kind, Static(..) | Fn(..)) if matches!(foreign_item.kind, Static(..) | Fn(..))
&& has_allow_dead_code_or_lang_attr(self.tcx, foreign_item.hir_id, &foreign_item.attrs) && has_allow_dead_code_or_lang_attr(
self.tcx,
foreign_item.hir_id(),
&foreign_item.attrs,
)
{ {
self.worklist.push(foreign_item.hir_id); self.worklist.push(foreign_item.hir_id());
} }
} }
} }
@ -525,7 +529,7 @@ impl DeadVisitor<'tcx> {
| hir::ItemKind::Struct(..) | hir::ItemKind::Struct(..)
| hir::ItemKind::Union(..) | hir::ItemKind::Union(..)
); );
should_warn && !self.symbol_is_live(item.hir_id) should_warn && !self.symbol_is_live(item.hir_id())
} }
fn should_warn_about_field(&mut self, field: &hir::StructField<'_>) -> bool { fn should_warn_about_field(&mut self, field: &hir::StructField<'_>) -> bool {
@ -542,8 +546,8 @@ impl DeadVisitor<'tcx> {
} }
fn should_warn_about_foreign_item(&mut self, fi: &hir::ForeignItem<'_>) -> bool { fn should_warn_about_foreign_item(&mut self, fi: &hir::ForeignItem<'_>) -> bool {
!self.symbol_is_live(fi.hir_id) !self.symbol_is_live(fi.hir_id())
&& !has_allow_dead_code_or_lang_attr(self.tcx, fi.hir_id, &fi.attrs) && !has_allow_dead_code_or_lang_attr(self.tcx, fi.hir_id(), &fi.attrs)
} }
// id := HIR id of an item's definition. // id := HIR id of an item's definition.
@ -627,7 +631,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> {
hir::ItemKind::Struct(..) => "constructed", // Issue #52325 hir::ItemKind::Struct(..) => "constructed", // Issue #52325
_ => "used", _ => "used",
}; };
self.warn_dead_code(item.hir_id, span, item.ident.name, participle); self.warn_dead_code(item.hir_id(), span, item.ident.name, participle);
} else { } else {
// Only continue if we didn't warn // Only continue if we didn't warn
intravisit::walk_item(self, item); intravisit::walk_item(self, item);
@ -649,7 +653,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> {
fn visit_foreign_item(&mut self, fi: &'tcx hir::ForeignItem<'tcx>) { fn visit_foreign_item(&mut self, fi: &'tcx hir::ForeignItem<'tcx>) {
if self.should_warn_about_foreign_item(fi) { if self.should_warn_about_foreign_item(fi) {
self.warn_dead_code(fi.hir_id, fi.span, fi.ident.name, "used"); self.warn_dead_code(fi.hir_id(), fi.span, fi.ident.name, "used");
} }
intravisit::walk_foreign_item(self, fi); intravisit::walk_foreign_item(self, fi);
} }
@ -664,9 +668,9 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> {
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) { fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
match impl_item.kind { match impl_item.kind {
hir::ImplItemKind::Const(_, body_id) => { hir::ImplItemKind::Const(_, body_id) => {
if !self.symbol_is_live(impl_item.hir_id) { if !self.symbol_is_live(impl_item.hir_id()) {
self.warn_dead_code( self.warn_dead_code(
impl_item.hir_id, impl_item.hir_id(),
impl_item.span, impl_item.span,
impl_item.ident.name, impl_item.ident.name,
"used", "used",
@ -675,7 +679,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> {
self.visit_nested_body(body_id) self.visit_nested_body(body_id)
} }
hir::ImplItemKind::Fn(_, body_id) => { hir::ImplItemKind::Fn(_, body_id) => {
if !self.symbol_is_live(impl_item.hir_id) { if !self.symbol_is_live(impl_item.hir_id()) {
// FIXME(66095): Because impl_item.span is annotated with things // FIXME(66095): Because impl_item.span is annotated with things
// like expansion data, and ident.span isn't, we use the // like expansion data, and ident.span isn't, we use the
// def_span method if it's part of a macro invocation // def_span method if it's part of a macro invocation
@ -687,7 +691,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> {
} else { } else {
impl_item.ident.span impl_item.ident.span
}; };
self.warn_dead_code(impl_item.hir_id, span, impl_item.ident.name, "used"); self.warn_dead_code(impl_item.hir_id(), span, impl_item.ident.name, "used");
} }
self.visit_nested_body(body_id) self.visit_nested_body(body_id)
} }

View file

@ -16,7 +16,7 @@ use rustc_hir::itemlikevisit::ItemLikeVisitor;
use rustc_middle::ty::query::Providers; use rustc_middle::ty::query::Providers;
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
use rustc_session::Session; use rustc_session::Session;
use rustc_span::def_id::{DefId, LOCAL_CRATE}; use rustc_span::def_id::{DefId, LocalDefId, LOCAL_CRATE};
use rustc_span::symbol::{sym, Symbol}; use rustc_span::symbol::{sym, Symbol};
struct DiagnosticItemCollector<'tcx> { struct DiagnosticItemCollector<'tcx> {
@ -27,19 +27,19 @@ struct DiagnosticItemCollector<'tcx> {
impl<'v, 'tcx> ItemLikeVisitor<'v> for DiagnosticItemCollector<'tcx> { impl<'v, 'tcx> ItemLikeVisitor<'v> for DiagnosticItemCollector<'tcx> {
fn visit_item(&mut self, item: &hir::Item<'_>) { fn visit_item(&mut self, item: &hir::Item<'_>) {
self.observe_item(&item.attrs, item.hir_id); self.observe_item(&item.attrs, item.def_id);
} }
fn visit_trait_item(&mut self, trait_item: &hir::TraitItem<'_>) { fn visit_trait_item(&mut self, trait_item: &hir::TraitItem<'_>) {
self.observe_item(&trait_item.attrs, trait_item.hir_id); self.observe_item(&trait_item.attrs, trait_item.def_id);
} }
fn visit_impl_item(&mut self, impl_item: &hir::ImplItem<'_>) { fn visit_impl_item(&mut self, impl_item: &hir::ImplItem<'_>) {
self.observe_item(&impl_item.attrs, impl_item.hir_id); self.observe_item(&impl_item.attrs, impl_item.def_id);
} }
fn visit_foreign_item(&mut self, foreign_item: &hir::ForeignItem<'_>) { fn visit_foreign_item(&mut self, foreign_item: &hir::ForeignItem<'_>) {
self.observe_item(foreign_item.attrs, foreign_item.hir_id); self.observe_item(foreign_item.attrs, foreign_item.def_id);
} }
} }
@ -48,9 +48,8 @@ impl<'tcx> DiagnosticItemCollector<'tcx> {
DiagnosticItemCollector { tcx, items: Default::default() } DiagnosticItemCollector { tcx, items: Default::default() }
} }
fn observe_item(&mut self, attrs: &[ast::Attribute], hir_id: hir::HirId) { fn observe_item(&mut self, attrs: &[ast::Attribute], def_id: LocalDefId) {
if let Some(name) = extract(&self.tcx.sess, attrs) { if let Some(name) = extract(&self.tcx.sess, attrs) {
let def_id = self.tcx.hir().local_def_id(hir_id);
// insert into our table // insert into our table
collect_item(self.tcx, &mut self.items, name, def_id.to_def_id()); collect_item(self.tcx, &mut self.items, name, def_id.to_def_id());
} }
@ -106,7 +105,7 @@ fn collect<'tcx>(tcx: TyCtxt<'tcx>) -> FxHashMap<Symbol, DefId> {
tcx.hir().krate().visit_all_item_likes(&mut collector); tcx.hir().krate().visit_all_item_likes(&mut collector);
for m in tcx.hir().krate().exported_macros { for m in tcx.hir().krate().exported_macros {
collector.observe_item(m.attrs, m.hir_id); collector.observe_item(m.attrs, m.def_id);
} }
collector.items collector.items

View file

@ -32,8 +32,7 @@ struct EntryContext<'a, 'tcx> {
impl<'a, 'tcx> ItemLikeVisitor<'tcx> for EntryContext<'a, 'tcx> { impl<'a, 'tcx> ItemLikeVisitor<'tcx> for EntryContext<'a, 'tcx> {
fn visit_item(&mut self, item: &'tcx Item<'tcx>) { fn visit_item(&mut self, item: &'tcx Item<'tcx>) {
let def_id = self.map.local_def_id(item.hir_id); let def_key = self.map.def_key(item.def_id);
let def_key = self.map.def_key(def_id);
let at_root = def_key.parent == Some(CRATE_DEF_INDEX); let at_root = def_key.parent == Some(CRATE_DEF_INDEX);
find_item(item, self, at_root); find_item(item, self, at_root);
} }
@ -116,18 +115,18 @@ fn find_item(item: &Item<'_>, ctxt: &mut EntryContext<'_, '_>, at_root: bool) {
} }
EntryPointType::MainNamed => { EntryPointType::MainNamed => {
if ctxt.main_fn.is_none() { if ctxt.main_fn.is_none() {
ctxt.main_fn = Some((item.hir_id, item.span)); ctxt.main_fn = Some((item.hir_id(), item.span));
} else { } else {
struct_span_err!(ctxt.session, item.span, E0136, "multiple `main` functions") struct_span_err!(ctxt.session, item.span, E0136, "multiple `main` functions")
.emit(); .emit();
} }
} }
EntryPointType::OtherMain => { EntryPointType::OtherMain => {
ctxt.non_main_fns.push((item.hir_id, item.span)); ctxt.non_main_fns.push((item.hir_id(), item.span));
} }
EntryPointType::MainAttr => { EntryPointType::MainAttr => {
if ctxt.attr_main_fn.is_none() { if ctxt.attr_main_fn.is_none() {
ctxt.attr_main_fn = Some((item.hir_id, item.span)); ctxt.attr_main_fn = Some((item.hir_id(), item.span));
} else { } else {
struct_span_err!( struct_span_err!(
ctxt.session, ctxt.session,
@ -142,7 +141,7 @@ fn find_item(item: &Item<'_>, ctxt: &mut EntryContext<'_, '_>, at_root: bool) {
} }
EntryPointType::Start => { EntryPointType::Start => {
if ctxt.start_fn.is_none() { if ctxt.start_fn.is_none() {
ctxt.start_fn = Some((item.hir_id, item.span)); ctxt.start_fn = Some((item.hir_id(), item.span));
} else { } else {
struct_span_err!(ctxt.session, item.span, E0138, "multiple `start` functions") struct_span_err!(ctxt.session, item.span, E0138, "multiple `start` functions")
.span_label(ctxt.start_fn.unwrap().1, "previous `#[start]` function here") .span_label(ctxt.start_fn.unwrap().1, "previous `#[start]` function here")

View file

@ -14,12 +14,9 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
let errors = Lock::new(Vec::new()); let errors = Lock::new(Vec::new());
let hir_map = tcx.hir(); let hir_map = tcx.hir();
par_iter(&hir_map.krate().modules).for_each(|(module_id, _)| { par_iter(&hir_map.krate().modules).for_each(|(&module_id, _)| {
let local_def_id = hir_map.local_def_id(*module_id); hir_map
hir_map.visit_item_likes_in_module( .visit_item_likes_in_module(module_id, &mut OuterVisitor { hir_map, errors: &errors });
local_def_id,
&mut OuterVisitor { hir_map, errors: &errors },
);
}); });
let errors = errors.into_inner(); let errors = errors.into_inner();
@ -56,22 +53,22 @@ impl<'a, 'hir> OuterVisitor<'a, 'hir> {
impl<'a, 'hir> ItemLikeVisitor<'hir> for OuterVisitor<'a, 'hir> { impl<'a, 'hir> ItemLikeVisitor<'hir> for OuterVisitor<'a, 'hir> {
fn visit_item(&mut self, i: &'hir hir::Item<'hir>) { fn visit_item(&mut self, i: &'hir hir::Item<'hir>) {
let mut inner_visitor = self.new_inner_visitor(self.hir_map); let mut inner_visitor = self.new_inner_visitor(self.hir_map);
inner_visitor.check(i.hir_id, |this| intravisit::walk_item(this, i)); inner_visitor.check(i.hir_id(), |this| intravisit::walk_item(this, i));
} }
fn visit_trait_item(&mut self, i: &'hir hir::TraitItem<'hir>) { fn visit_trait_item(&mut self, i: &'hir hir::TraitItem<'hir>) {
let mut inner_visitor = self.new_inner_visitor(self.hir_map); let mut inner_visitor = self.new_inner_visitor(self.hir_map);
inner_visitor.check(i.hir_id, |this| intravisit::walk_trait_item(this, i)); inner_visitor.check(i.hir_id(), |this| intravisit::walk_trait_item(this, i));
} }
fn visit_impl_item(&mut self, i: &'hir hir::ImplItem<'hir>) { fn visit_impl_item(&mut self, i: &'hir hir::ImplItem<'hir>) {
let mut inner_visitor = self.new_inner_visitor(self.hir_map); let mut inner_visitor = self.new_inner_visitor(self.hir_map);
inner_visitor.check(i.hir_id, |this| intravisit::walk_impl_item(this, i)); inner_visitor.check(i.hir_id(), |this| intravisit::walk_impl_item(this, i));
} }
fn visit_foreign_item(&mut self, i: &'hir hir::ForeignItem<'hir>) { fn visit_foreign_item(&mut self, i: &'hir hir::ForeignItem<'hir>) {
let mut inner_visitor = self.new_inner_visitor(self.hir_map); let mut inner_visitor = self.new_inner_visitor(self.hir_map);
inner_visitor.check(i.hir_id, |this| intravisit::walk_foreign_item(this, i)); inner_visitor.check(i.hir_id(), |this| intravisit::walk_foreign_item(this, i));
} }
} }

View file

@ -100,7 +100,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
} }
fn visit_nested_item(&mut self, id: hir::ItemId) { fn visit_nested_item(&mut self, id: hir::ItemId) {
let nested_item = self.krate.unwrap().item(id.id); let nested_item = self.krate.unwrap().item(id);
self.visit_item(nested_item) self.visit_item(nested_item)
} }
@ -120,7 +120,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
} }
fn visit_item(&mut self, i: &'v hir::Item<'v>) { fn visit_item(&mut self, i: &'v hir::Item<'v>) {
self.record("Item", Id::Node(i.hir_id), i); self.record("Item", Id::Node(i.hir_id()), i);
hir_visit::walk_item(self, i) hir_visit::walk_item(self, i)
} }
@ -130,7 +130,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
} }
fn visit_foreign_item(&mut self, i: &'v hir::ForeignItem<'v>) { fn visit_foreign_item(&mut self, i: &'v hir::ForeignItem<'v>) {
self.record("ForeignItem", Id::Node(i.hir_id), i); self.record("ForeignItem", Id::Node(i.hir_id()), i);
hir_visit::walk_foreign_item(self, i) hir_visit::walk_foreign_item(self, i)
} }
@ -187,12 +187,12 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
} }
fn visit_trait_item(&mut self, ti: &'v hir::TraitItem<'v>) { fn visit_trait_item(&mut self, ti: &'v hir::TraitItem<'v>) {
self.record("TraitItem", Id::Node(ti.hir_id), ti); self.record("TraitItem", Id::Node(ti.hir_id()), ti);
hir_visit::walk_trait_item(self, ti) hir_visit::walk_trait_item(self, ti)
} }
fn visit_impl_item(&mut self, ii: &'v hir::ImplItem<'v>) { fn visit_impl_item(&mut self, ii: &'v hir::ImplItem<'v>) {
self.record("ImplItem", Id::Node(ii.hir_id), ii); self.record("ImplItem", Id::Node(ii.hir_id()), ii);
hir_visit::walk_impl_item(self, ii) hir_visit::walk_impl_item(self, ii)
} }
@ -246,7 +246,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
} }
fn visit_macro_def(&mut self, macro_def: &'v hir::MacroDef<'v>) { fn visit_macro_def(&mut self, macro_def: &'v hir::MacroDef<'v>) {
self.record("MacroDef", Id::Node(macro_def.hir_id), macro_def); self.record("MacroDef", Id::Node(macro_def.hir_id()), macro_def);
hir_visit::walk_macro_def(self, macro_def) hir_visit::walk_macro_def(self, macro_def)
} }
} }

View file

@ -30,7 +30,7 @@ struct LanguageItemCollector<'tcx> {
impl ItemLikeVisitor<'v> for LanguageItemCollector<'tcx> { impl ItemLikeVisitor<'v> for LanguageItemCollector<'tcx> {
fn visit_item(&mut self, item: &hir::Item<'_>) { fn visit_item(&mut self, item: &hir::Item<'_>) {
self.check_for_lang(Target::from_item(item), item.hir_id, item.attrs); self.check_for_lang(Target::from_item(item), item.hir_id(), item.attrs);
if let hir::ItemKind::Enum(def, ..) = &item.kind { if let hir::ItemKind::Enum(def, ..) = &item.kind {
for variant in def.variants { for variant in def.variants {
@ -42,7 +42,7 @@ impl ItemLikeVisitor<'v> for LanguageItemCollector<'tcx> {
fn visit_trait_item(&mut self, trait_item: &hir::TraitItem<'_>) { fn visit_trait_item(&mut self, trait_item: &hir::TraitItem<'_>) {
self.check_for_lang( self.check_for_lang(
Target::from_trait_item(trait_item), Target::from_trait_item(trait_item),
trait_item.hir_id, trait_item.hir_id(),
trait_item.attrs, trait_item.attrs,
) )
} }
@ -50,7 +50,7 @@ impl ItemLikeVisitor<'v> for LanguageItemCollector<'tcx> {
fn visit_impl_item(&mut self, impl_item: &hir::ImplItem<'_>) { fn visit_impl_item(&mut self, impl_item: &hir::ImplItem<'_>) {
self.check_for_lang( self.check_for_lang(
target_from_impl_item(self.tcx, impl_item), target_from_impl_item(self.tcx, impl_item),
impl_item.hir_id, impl_item.hir_id(),
impl_item.attrs, impl_item.attrs,
) )
} }

View file

@ -21,16 +21,14 @@ struct LayoutTest<'tcx> {
impl ItemLikeVisitor<'tcx> for LayoutTest<'tcx> { impl ItemLikeVisitor<'tcx> for LayoutTest<'tcx> {
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
let item_def_id = self.tcx.hir().local_def_id(item.hir_id);
match item.kind { match item.kind {
ItemKind::TyAlias(..) ItemKind::TyAlias(..)
| ItemKind::Enum(..) | ItemKind::Enum(..)
| ItemKind::Struct(..) | ItemKind::Struct(..)
| ItemKind::Union(..) => { | ItemKind::Union(..) => {
for attr in self.tcx.get_attrs(item_def_id.to_def_id()).iter() { for attr in self.tcx.get_attrs(item.def_id.to_def_id()).iter() {
if self.tcx.sess.check_name(attr, sym::rustc_layout) { if self.tcx.sess.check_name(attr, sym::rustc_layout) {
self.dump_layout_of(item_def_id, item, attr); self.dump_layout_of(item.def_id, item, attr);
} }
} }
} }

View file

@ -31,7 +31,7 @@ fn item_might_be_inlined(tcx: TyCtxt<'tcx>, item: &hir::Item<'_>, attrs: &Codege
match item.kind { match item.kind {
hir::ItemKind::Fn(ref sig, ..) if sig.header.is_const() => true, hir::ItemKind::Fn(ref sig, ..) if sig.header.is_const() => true,
hir::ItemKind::Impl { .. } | hir::ItemKind::Fn(..) => { hir::ItemKind::Impl { .. } | hir::ItemKind::Fn(..) => {
let generics = tcx.generics_of(tcx.hir().local_def_id(item.hir_id)); let generics = tcx.generics_of(item.def_id);
generics.requires_monomorphization(tcx) generics.requires_monomorphization(tcx)
} }
_ => false, _ => false,
@ -43,8 +43,8 @@ fn method_might_be_inlined(
impl_item: &hir::ImplItem<'_>, impl_item: &hir::ImplItem<'_>,
impl_src: LocalDefId, impl_src: LocalDefId,
) -> bool { ) -> bool {
let codegen_fn_attrs = tcx.codegen_fn_attrs(impl_item.hir_id.owner.to_def_id()); let codegen_fn_attrs = tcx.codegen_fn_attrs(impl_item.hir_id().owner.to_def_id());
let generics = tcx.generics_of(tcx.hir().local_def_id(impl_item.hir_id)); let generics = tcx.generics_of(impl_item.def_id);
if codegen_fn_attrs.requests_inline() || generics.requires_monomorphization(tcx) { if codegen_fn_attrs.requests_inline() || generics.requires_monomorphization(tcx) {
return true; return true;
} }
@ -218,8 +218,7 @@ impl<'tcx> ReachableContext<'tcx> {
} else { } else {
false false
}; };
let def_id = self.tcx.hir().local_def_id(item.hir_id); let codegen_attrs = self.tcx.codegen_fn_attrs(item.def_id);
let codegen_attrs = self.tcx.codegen_fn_attrs(def_id);
let is_extern = codegen_attrs.contains_extern_indicator(); let is_extern = codegen_attrs.contains_extern_indicator();
let std_internal = let std_internal =
codegen_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL); codegen_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL);
@ -239,9 +238,11 @@ impl<'tcx> ReachableContext<'tcx> {
Node::Item(item) => { Node::Item(item) => {
match item.kind { match item.kind {
hir::ItemKind::Fn(.., body) => { hir::ItemKind::Fn(.., body) => {
let def_id = self.tcx.hir().local_def_id(item.hir_id); if item_might_be_inlined(
if item_might_be_inlined(self.tcx, &item, self.tcx.codegen_fn_attrs(def_id)) self.tcx,
{ &item,
self.tcx.codegen_fn_attrs(item.def_id),
) {
self.visit_nested_body(body); self.visit_nested_body(body);
} }
} }
@ -341,23 +342,21 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, 'tcx
// Anything which has custom linkage gets thrown on the worklist no // Anything which has custom linkage gets thrown on the worklist no
// matter where it is in the crate, along with "special std symbols" // matter where it is in the crate, along with "special std symbols"
// which are currently akin to allocator symbols. // which are currently akin to allocator symbols.
let def_id = self.tcx.hir().local_def_id(item.hir_id); let codegen_attrs = self.tcx.codegen_fn_attrs(item.def_id);
let codegen_attrs = self.tcx.codegen_fn_attrs(def_id);
if codegen_attrs.contains_extern_indicator() if codegen_attrs.contains_extern_indicator()
|| codegen_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL) || codegen_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL)
{ {
self.worklist.push(def_id); self.worklist.push(item.def_id);
} }
// We need only trait impls here, not inherent impls, and only non-exported ones // We need only trait impls here, not inherent impls, and only non-exported ones
if let hir::ItemKind::Impl(hir::Impl { of_trait: Some(ref trait_ref), ref items, .. }) = if let hir::ItemKind::Impl(hir::Impl { of_trait: Some(ref trait_ref), ref items, .. }) =
item.kind item.kind
{ {
if !self.access_levels.is_reachable(item.hir_id) { if !self.access_levels.is_reachable(item.hir_id()) {
// FIXME(#53488) remove `let` // FIXME(#53488) remove `let`
let tcx = self.tcx; let tcx = self.tcx;
self.worklist self.worklist.extend(items.iter().map(|ii_ref| ii_ref.id.def_id));
.extend(items.iter().map(|ii_ref| tcx.hir().local_def_id(ii_ref.id.hir_id)));
let trait_def_id = match trait_ref.path.res { let trait_def_id = match trait_ref.path.res {
Res::Def(DefKind::Trait, def_id) => def_id, Res::Def(DefKind::Trait, def_id) => def_id,

View file

@ -376,7 +376,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
} }
self.annotate( self.annotate(
i.hir_id, i.hir_id(),
&i.attrs, &i.attrs,
i.span, i.span,
kind, kind,
@ -389,7 +389,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem<'tcx>) { fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem<'tcx>) {
self.annotate( self.annotate(
ti.hir_id, ti.hir_id(),
&ti.attrs, &ti.attrs,
ti.span, ti.span,
AnnotationKind::Required, AnnotationKind::Required,
@ -405,7 +405,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
let kind = let kind =
if self.in_trait_impl { AnnotationKind::Prohibited } else { AnnotationKind::Required }; if self.in_trait_impl { AnnotationKind::Prohibited } else { AnnotationKind::Required };
self.annotate( self.annotate(
ii.hir_id, ii.hir_id(),
&ii.attrs, &ii.attrs,
ii.span, ii.span,
kind, kind,
@ -459,7 +459,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
fn visit_foreign_item(&mut self, i: &'tcx hir::ForeignItem<'tcx>) { fn visit_foreign_item(&mut self, i: &'tcx hir::ForeignItem<'tcx>) {
self.annotate( self.annotate(
i.hir_id, i.hir_id(),
&i.attrs, &i.attrs,
i.span, i.span,
AnnotationKind::Required, AnnotationKind::Required,
@ -473,7 +473,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef<'tcx>) { fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef<'tcx>) {
self.annotate( self.annotate(
md.hir_id, md.hir_id(),
&md.attrs, &md.attrs,
md.span, md.span,
AnnotationKind::Required, AnnotationKind::Required,
@ -556,7 +556,7 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> {
hir::ItemKind::Impl(hir::Impl { of_trait: None, .. }) hir::ItemKind::Impl(hir::Impl { of_trait: None, .. })
| hir::ItemKind::ForeignMod { .. } | hir::ItemKind::ForeignMod { .. }
) { ) {
self.check_missing_stability(i.hir_id, i.span); self.check_missing_stability(i.hir_id(), i.span);
} }
// Ensure `const fn` that are `stable` have one of `rustc_const_unstable` or // Ensure `const fn` that are `stable` have one of `rustc_const_unstable` or
@ -564,21 +564,21 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> {
if self.tcx.features().staged_api if self.tcx.features().staged_api
&& matches!(&i.kind, hir::ItemKind::Fn(sig, ..) if sig.header.is_const()) && matches!(&i.kind, hir::ItemKind::Fn(sig, ..) if sig.header.is_const())
{ {
self.check_missing_const_stability(i.hir_id, i.span); self.check_missing_const_stability(i.hir_id(), i.span);
} }
intravisit::walk_item(self, i) intravisit::walk_item(self, i)
} }
fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem<'tcx>) { fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem<'tcx>) {
self.check_missing_stability(ti.hir_id, ti.span); self.check_missing_stability(ti.hir_id(), ti.span);
intravisit::walk_trait_item(self, ti); intravisit::walk_trait_item(self, ti);
} }
fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem<'tcx>) { fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem<'tcx>) {
let impl_def_id = self.tcx.hir().local_def_id(self.tcx.hir().get_parent_item(ii.hir_id)); let impl_def_id = self.tcx.hir().local_def_id(self.tcx.hir().get_parent_item(ii.hir_id()));
if self.tcx.impl_trait_ref(impl_def_id).is_none() { if self.tcx.impl_trait_ref(impl_def_id).is_none() {
self.check_missing_stability(ii.hir_id, ii.span); self.check_missing_stability(ii.hir_id(), ii.span);
} }
intravisit::walk_impl_item(self, ii); intravisit::walk_impl_item(self, ii);
} }
@ -594,12 +594,12 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> {
} }
fn visit_foreign_item(&mut self, i: &'tcx hir::ForeignItem<'tcx>) { fn visit_foreign_item(&mut self, i: &'tcx hir::ForeignItem<'tcx>) {
self.check_missing_stability(i.hir_id, i.span); self.check_missing_stability(i.hir_id(), i.span);
intravisit::walk_foreign_item(self, i); intravisit::walk_foreign_item(self, i);
} }
fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef<'tcx>) { fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef<'tcx>) {
self.check_missing_stability(md.hir_id, md.span); self.check_missing_stability(md.hir_id(), md.span);
} }
// Note that we don't need to `check_missing_stability` for default generic parameters, // Note that we don't need to `check_missing_stability` for default generic parameters,
@ -712,13 +712,12 @@ impl Visitor<'tcx> for Checker<'tcx> {
return; return;
} }
let def_id = self.tcx.hir().local_def_id(item.hir_id); let cnum = match self.tcx.extern_mod_stmt_cnum(item.def_id) {
let cnum = match self.tcx.extern_mod_stmt_cnum(def_id) {
Some(cnum) => cnum, Some(cnum) => cnum,
None => return, None => return,
}; };
let def_id = DefId { krate: cnum, index: CRATE_DEF_INDEX }; let def_id = DefId { krate: cnum, index: CRATE_DEF_INDEX };
self.tcx.check_stability(def_id, Some(item.hir_id), item.span); self.tcx.check_stability(def_id, Some(item.hir_id()), item.span);
} }
// For implementations of traits, check the stability of each item // For implementations of traits, check the stability of each item
@ -744,7 +743,7 @@ impl Visitor<'tcx> for Checker<'tcx> {
.map_or(item.span, |a| a.span); .map_or(item.span, |a| a.span);
self.tcx.struct_span_lint_hir( self.tcx.struct_span_lint_hir(
INEFFECTIVE_UNSTABLE_TRAIT_IMPL, INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
item.hir_id, item.hir_id(),
span, span,
|lint| lint |lint| lint
.build("an `#[unstable]` annotation here has no effect") .build("an `#[unstable]` annotation here has no effect")
@ -775,15 +774,14 @@ impl Visitor<'tcx> for Checker<'tcx> {
// There's no good place to insert stability check for non-Copy unions, // There's no good place to insert stability check for non-Copy unions,
// so semi-randomly perform it here in stability.rs // so semi-randomly perform it here in stability.rs
hir::ItemKind::Union(..) if !self.tcx.features().untagged_unions => { hir::ItemKind::Union(..) if !self.tcx.features().untagged_unions => {
let def_id = self.tcx.hir().local_def_id(item.hir_id); let ty = self.tcx.type_of(item.def_id);
let ty = self.tcx.type_of(def_id);
let (adt_def, substs) = match ty.kind() { let (adt_def, substs) = match ty.kind() {
ty::Adt(adt_def, substs) => (adt_def, substs), ty::Adt(adt_def, substs) => (adt_def, substs),
_ => bug!(), _ => bug!(),
}; };
// Non-`Copy` fields are unstable, except for `ManuallyDrop`. // Non-`Copy` fields are unstable, except for `ManuallyDrop`.
let param_env = self.tcx.param_env(def_id); let param_env = self.tcx.param_env(item.def_id);
for field in &adt_def.non_enum_variant().fields { for field in &adt_def.non_enum_variant().fields {
let field_ty = field.ty(self.tcx, substs); let field_ty = field.ty(self.tcx, substs);
if !field_ty.ty_adt_def().map_or(false, |adt_def| adt_def.is_manually_drop()) if !field_ty.ty_adt_def().map_or(false, |adt_def| adt_def.is_manually_drop())

View file

@ -1,7 +1,7 @@
//! Used by `rustc` when compiling a plugin crate. //! Used by `rustc` when compiling a plugin crate.
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::itemlikevisit::ItemLikeVisitor;
use rustc_middle::ty::query::Providers; use rustc_middle::ty::query::Providers;
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
@ -10,14 +10,14 @@ use rustc_span::Span;
struct RegistrarFinder<'tcx> { struct RegistrarFinder<'tcx> {
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
registrars: Vec<(hir::HirId, Span)>, registrars: Vec<(LocalDefId, Span)>,
} }
impl<'v, 'tcx> ItemLikeVisitor<'v> for RegistrarFinder<'tcx> { impl<'v, 'tcx> ItemLikeVisitor<'v> for RegistrarFinder<'tcx> {
fn visit_item(&mut self, item: &hir::Item<'_>) { fn visit_item(&mut self, item: &hir::Item<'_>) {
if let hir::ItemKind::Fn(..) = item.kind { if let hir::ItemKind::Fn(..) = item.kind {
if self.tcx.sess.contains_name(&item.attrs, sym::plugin_registrar) { if self.tcx.sess.contains_name(&item.attrs, sym::plugin_registrar) {
self.registrars.push((item.hir_id, item.span)); self.registrars.push((item.def_id, item.span));
} }
} }
} }
@ -43,8 +43,8 @@ fn plugin_registrar_fn(tcx: TyCtxt<'_>, cnum: CrateNum) -> Option<DefId> {
match finder.registrars.len() { match finder.registrars.len() {
0 => None, 0 => None,
1 => { 1 => {
let (hir_id, _) = finder.registrars.pop().unwrap(); let (def_id, _) = finder.registrars.pop().unwrap();
Some(tcx.hir().local_def_id(hir_id).to_def_id()) Some(def_id.to_def_id())
} }
_ => { _ => {
let diagnostic = tcx.sess.diagnostic(); let diagnostic = tcx.sess.diagnostic();

View file

@ -454,11 +454,9 @@ impl EmbargoVisitor<'tcx> {
let module_def_id = self.tcx.hir().local_def_id(reachable_mod); let module_def_id = self.tcx.hir().local_def_id(reachable_mod);
let module = self.tcx.hir().get_module(module_def_id).0; let module = self.tcx.hir().get_module(module_def_id).0;
for item_id in module.item_ids { for item_id in module.item_ids {
let hir_id = item_id.id; let def_kind = self.tcx.def_kind(item_id.def_id);
let item_def_id = self.tcx.hir().local_def_id(hir_id); let vis = self.tcx.visibility(item_id.def_id);
let def_kind = self.tcx.def_kind(item_def_id); self.update_macro_reachable_def(item_id.hir_id(), def_kind, vis, defining_mod);
let vis = self.tcx.visibility(item_def_id);
self.update_macro_reachable_def(hir_id, def_kind, vis, defining_mod);
} }
if let Some(exports) = self.tcx.module_exports(module_def_id) { if let Some(exports) = self.tcx.module_exports(module_def_id) {
for export in exports { for export in exports {
@ -588,14 +586,17 @@ impl EmbargoVisitor<'tcx> {
.map(|module_hir_id| self.tcx.hir().expect_item(module_hir_id)) .map(|module_hir_id| self.tcx.hir().expect_item(module_hir_id))
{ {
if let hir::ItemKind::Mod(m) = &item.kind { if let hir::ItemKind::Mod(m) = &item.kind {
for item_id in m.item_ids { for &item_id in m.item_ids {
let item = self.tcx.hir().expect_item(item_id.id); let item = self.tcx.hir().item(item_id);
let def_id = self.tcx.hir().local_def_id(item_id.id); if !self.tcx.hygienic_eq(
if !self.tcx.hygienic_eq(segment.ident, item.ident, def_id.to_def_id()) { segment.ident,
item.ident,
item_id.def_id.to_def_id(),
) {
continue; continue;
} }
if let hir::ItemKind::Use(..) = item.kind { if let hir::ItemKind::Use(..) = item.kind {
self.update(item.hir_id, Some(AccessLevel::Exported)); self.update(item.hir_id(), Some(AccessLevel::Exported));
} }
} }
} }
@ -616,7 +617,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
let inherited_item_level = match item.kind { let inherited_item_level = match item.kind {
hir::ItemKind::Impl { .. } => { hir::ItemKind::Impl { .. } => {
Option::<AccessLevel>::of_impl(item.hir_id, self.tcx, &self.access_levels) Option::<AccessLevel>::of_impl(item.hir_id(), self.tcx, &self.access_levels)
} }
// Foreign modules inherit level from parents. // Foreign modules inherit level from parents.
hir::ItemKind::ForeignMod { .. } => self.prev_level, hir::ItemKind::ForeignMod { .. } => self.prev_level,
@ -644,7 +645,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
}; };
// Update level of the item itself. // Update level of the item itself.
let item_level = self.update(item.hir_id, inherited_item_level); let item_level = self.update(item.hir_id(), inherited_item_level);
// Update levels of nested things. // Update levels of nested things.
match item.kind { match item.kind {
@ -662,13 +663,13 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
hir::ItemKind::Impl(ref impl_) => { hir::ItemKind::Impl(ref impl_) => {
for impl_item_ref in impl_.items { for impl_item_ref in impl_.items {
if impl_.of_trait.is_some() || impl_item_ref.vis.node.is_pub() { if impl_.of_trait.is_some() || impl_item_ref.vis.node.is_pub() {
self.update(impl_item_ref.id.hir_id, item_level); self.update(impl_item_ref.id.hir_id(), item_level);
} }
} }
} }
hir::ItemKind::Trait(.., trait_item_refs) => { hir::ItemKind::Trait(.., trait_item_refs) => {
for trait_item_ref in trait_item_refs { for trait_item_ref in trait_item_refs {
self.update(trait_item_ref.id.hir_id, item_level); self.update(trait_item_ref.id.hir_id(), item_level);
} }
} }
hir::ItemKind::Struct(ref def, _) | hir::ItemKind::Union(ref def, _) => { hir::ItemKind::Struct(ref def, _) | hir::ItemKind::Union(ref def, _) => {
@ -684,7 +685,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
hir::ItemKind::ForeignMod { items, .. } => { hir::ItemKind::ForeignMod { items, .. } => {
for foreign_item in items { for foreign_item in items {
if foreign_item.vis.node.is_pub() { if foreign_item.vis.node.is_pub() {
self.update(foreign_item.id.hir_id, item_level); self.update(foreign_item.id.hir_id(), item_level);
} }
} }
} }
@ -727,7 +728,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
// reachable if they are returned via `impl Trait`, even from private functions. // reachable if they are returned via `impl Trait`, even from private functions.
let exist_level = let exist_level =
cmp::max(item_level, Some(AccessLevel::ReachableFromImplTrait)); cmp::max(item_level, Some(AccessLevel::ReachableFromImplTrait));
self.reach(item.hir_id, exist_level).generics().predicates().ty(); self.reach(item.hir_id(), exist_level).generics().predicates().ty();
} }
} }
// Visit everything. // Visit everything.
@ -736,15 +737,15 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
| hir::ItemKind::Fn(..) | hir::ItemKind::Fn(..)
| hir::ItemKind::TyAlias(..) => { | hir::ItemKind::TyAlias(..) => {
if item_level.is_some() { if item_level.is_some() {
self.reach(item.hir_id, item_level).generics().predicates().ty(); self.reach(item.hir_id(), item_level).generics().predicates().ty();
} }
} }
hir::ItemKind::Trait(.., trait_item_refs) => { hir::ItemKind::Trait(.., trait_item_refs) => {
if item_level.is_some() { if item_level.is_some() {
self.reach(item.hir_id, item_level).generics().predicates(); self.reach(item.hir_id(), item_level).generics().predicates();
for trait_item_ref in trait_item_refs { for trait_item_ref in trait_item_refs {
let mut reach = self.reach(trait_item_ref.id.hir_id, item_level); let mut reach = self.reach(trait_item_ref.id.hir_id(), item_level);
reach.generics().predicates(); reach.generics().predicates();
if trait_item_ref.kind == AssocItemKind::Type if trait_item_ref.kind == AssocItemKind::Type
@ -759,18 +760,18 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
} }
hir::ItemKind::TraitAlias(..) => { hir::ItemKind::TraitAlias(..) => {
if item_level.is_some() { if item_level.is_some() {
self.reach(item.hir_id, item_level).generics().predicates(); self.reach(item.hir_id(), item_level).generics().predicates();
} }
} }
// Visit everything except for private impl items. // Visit everything except for private impl items.
hir::ItemKind::Impl(ref impl_) => { hir::ItemKind::Impl(ref impl_) => {
if item_level.is_some() { if item_level.is_some() {
self.reach(item.hir_id, item_level).generics().predicates().ty().trait_ref(); self.reach(item.hir_id(), item_level).generics().predicates().ty().trait_ref();
for impl_item_ref in impl_.items { for impl_item_ref in impl_.items {
let impl_item_level = self.get(impl_item_ref.id.hir_id); let impl_item_level = self.get(impl_item_ref.id.hir_id());
if impl_item_level.is_some() { if impl_item_level.is_some() {
self.reach(impl_item_ref.id.hir_id, impl_item_level) self.reach(impl_item_ref.id.hir_id(), impl_item_level)
.generics() .generics()
.predicates() .predicates()
.ty(); .ty();
@ -782,7 +783,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
// Visit everything, but enum variants have their own levels. // Visit everything, but enum variants have their own levels.
hir::ItemKind::Enum(ref def, _) => { hir::ItemKind::Enum(ref def, _) => {
if item_level.is_some() { if item_level.is_some() {
self.reach(item.hir_id, item_level).generics().predicates(); self.reach(item.hir_id(), item_level).generics().predicates();
} }
for variant in def.variants { for variant in def.variants {
let variant_level = self.get(variant.id); let variant_level = self.get(variant.id);
@ -792,16 +793,16 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
} }
// Corner case: if the variant is reachable, but its // Corner case: if the variant is reachable, but its
// enum is not, make the enum reachable as well. // enum is not, make the enum reachable as well.
self.update(item.hir_id, variant_level); self.update(item.hir_id(), variant_level);
} }
} }
} }
// Visit everything, but foreign items have their own levels. // Visit everything, but foreign items have their own levels.
hir::ItemKind::ForeignMod { items, .. } => { hir::ItemKind::ForeignMod { items, .. } => {
for foreign_item in items { for foreign_item in items {
let foreign_item_level = self.get(foreign_item.id.hir_id); let foreign_item_level = self.get(foreign_item.id.hir_id());
if foreign_item_level.is_some() { if foreign_item_level.is_some() {
self.reach(foreign_item.id.hir_id, foreign_item_level) self.reach(foreign_item.id.hir_id(), foreign_item_level)
.generics() .generics()
.predicates() .predicates()
.ty(); .ty();
@ -811,7 +812,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
// Visit everything except for private fields. // Visit everything except for private fields.
hir::ItemKind::Struct(ref struct_def, _) | hir::ItemKind::Union(ref struct_def, _) => { hir::ItemKind::Struct(ref struct_def, _) | hir::ItemKind::Union(ref struct_def, _) => {
if item_level.is_some() { if item_level.is_some() {
self.reach(item.hir_id, item_level).generics().predicates(); self.reach(item.hir_id(), item_level).generics().predicates();
for field in struct_def.fields() { for field in struct_def.fields() {
let field_level = self.get(field.hir_id); let field_level = self.get(field.hir_id);
if field_level.is_some() { if field_level.is_some() {
@ -866,14 +867,12 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
// `#[macro_export]`-ed `macro_rules!` are `Public` since they // `#[macro_export]`-ed `macro_rules!` are `Public` since they
// ignore their containing path to always appear at the crate root. // ignore their containing path to always appear at the crate root.
if md.ast.macro_rules { if md.ast.macro_rules {
self.update(md.hir_id, Some(AccessLevel::Public)); self.update(md.hir_id(), Some(AccessLevel::Public));
} }
return; return;
} }
let macro_module_def_id = let macro_module_def_id = ty::DefIdTree::parent(self.tcx, md.def_id.to_def_id()).unwrap();
ty::DefIdTree::parent(self.tcx, self.tcx.hir().local_def_id(md.hir_id).to_def_id())
.unwrap();
let hir_id = macro_module_def_id let hir_id = macro_module_def_id
.as_local() .as_local()
.map(|def_id| self.tcx.hir().local_def_id_to_hir_id(def_id)); .map(|def_id| self.tcx.hir().local_def_id_to_hir_id(def_id));
@ -883,7 +882,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
_ => return, _ => return,
}; };
let level = if md.vis.node.is_pub() { self.get(module_id) } else { None }; let level = if md.vis.node.is_pub() { self.get(module_id) } else { None };
let new_level = self.update(md.hir_id, level); let new_level = self.update(md.hir_id(), level);
if new_level.is_none() { if new_level.is_none() {
return; return;
} }
@ -1037,7 +1036,7 @@ impl<'tcx> Visitor<'tcx> for NamePrivacyVisitor<'tcx> {
} }
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
let orig_current_item = self.current_item.replace(item.hir_id); let orig_current_item = self.current_item.replace(item.hir_id());
intravisit::walk_item(self, item); intravisit::walk_item(self, item);
self.current_item = orig_current_item; self.current_item = orig_current_item;
} }
@ -1322,8 +1321,7 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
// Check types in item interfaces. // Check types in item interfaces.
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
let orig_current_item = let orig_current_item = mem::replace(&mut self.current_item, item.def_id);
mem::replace(&mut self.current_item, self.tcx.hir().local_def_id(item.hir_id));
let old_maybe_typeck_results = self.maybe_typeck_results.take(); let old_maybe_typeck_results = self.maybe_typeck_results.take();
intravisit::walk_item(self, item); intravisit::walk_item(self, item);
self.maybe_typeck_results = old_maybe_typeck_results; self.maybe_typeck_results = old_maybe_typeck_results;
@ -1463,7 +1461,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
hir::ItemKind::ForeignMod { .. } => {} hir::ItemKind::ForeignMod { .. } => {}
hir::ItemKind::Trait(.., ref bounds, _) => { hir::ItemKind::Trait(.., ref bounds, _) => {
if !self.trait_is_public(item.hir_id) { if !self.trait_is_public(item.hir_id()) {
return; return;
} }
@ -1526,7 +1524,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
let impl_item = self.tcx.hir().impl_item(impl_item_ref.id); let impl_item = self.tcx.hir().impl_item(impl_item_ref.id);
match impl_item.kind { match impl_item.kind {
hir::ImplItemKind::Const(..) | hir::ImplItemKind::Fn(..) => { hir::ImplItemKind::Const(..) | hir::ImplItemKind::Fn(..) => {
self.access_levels.is_reachable(impl_item_ref.id.hir_id) self.access_levels.is_reachable(impl_item_ref.id.hir_id())
} }
hir::ImplItemKind::TyAlias(_) => false, hir::ImplItemKind::TyAlias(_) => false,
} }
@ -1546,8 +1544,10 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
let impl_item = self.tcx.hir().impl_item(impl_item_ref.id); let impl_item = self.tcx.hir().impl_item(impl_item_ref.id);
match impl_item.kind { match impl_item.kind {
hir::ImplItemKind::Const(..) | hir::ImplItemKind::Fn(..) hir::ImplItemKind::Const(..) | hir::ImplItemKind::Fn(..)
if self if self.item_is_public(
.item_is_public(&impl_item.hir_id, &impl_item.vis) => &impl_item.hir_id(),
&impl_item.vis,
) =>
{ {
intravisit::walk_impl_item(self, impl_item) intravisit::walk_impl_item(self, impl_item)
} }
@ -1588,7 +1588,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
// methods will be visible as `Public::foo`. // methods will be visible as `Public::foo`.
let mut found_pub_static = false; let mut found_pub_static = false;
for impl_item_ref in impl_.items { for impl_item_ref in impl_.items {
if self.item_is_public(&impl_item_ref.id.hir_id, &impl_item_ref.vis) { if self.item_is_public(&impl_item_ref.id.hir_id(), &impl_item_ref.vis) {
let impl_item = self.tcx.hir().impl_item(impl_item_ref.id); let impl_item = self.tcx.hir().impl_item(impl_item_ref.id);
match impl_item_ref.kind { match impl_item_ref.kind {
AssocItemKind::Const => { AssocItemKind::Const => {
@ -1615,7 +1615,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
hir::ItemKind::TyAlias(..) => return, hir::ItemKind::TyAlias(..) => return,
// Not at all public, so we don't care. // Not at all public, so we don't care.
_ if !self.item_is_public(&item.hir_id, &item.vis) => { _ if !self.item_is_public(&item.hir_id(), &item.vis) => {
return; return;
} }
@ -1651,7 +1651,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
} }
fn visit_foreign_item(&mut self, item: &'tcx hir::ForeignItem<'tcx>) { fn visit_foreign_item(&mut self, item: &'tcx hir::ForeignItem<'tcx>) {
if self.access_levels.is_reachable(item.hir_id) { if self.access_levels.is_reachable(item.hir_id()) {
intravisit::walk_foreign_item(self, item) intravisit::walk_foreign_item(self, item)
} }
} }
@ -1926,7 +1926,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx>
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
let tcx = self.tcx; let tcx = self.tcx;
let item_visibility = tcx.visibility(tcx.hir().local_def_id(item.hir_id).to_def_id()); let item_visibility = tcx.visibility(item.def_id);
match item.kind { match item.kind {
// Crates are always public. // Crates are always public.
@ -1942,34 +1942,34 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx>
| hir::ItemKind::Static(..) | hir::ItemKind::Static(..)
| hir::ItemKind::Fn(..) | hir::ItemKind::Fn(..)
| hir::ItemKind::TyAlias(..) => { | hir::ItemKind::TyAlias(..) => {
self.check(item.hir_id, item_visibility).generics().predicates().ty(); self.check(item.hir_id(), item_visibility).generics().predicates().ty();
} }
hir::ItemKind::OpaqueTy(..) => { hir::ItemKind::OpaqueTy(..) => {
// `ty()` for opaque types is the underlying type, // `ty()` for opaque types is the underlying type,
// it's not a part of interface, so we skip it. // it's not a part of interface, so we skip it.
self.check(item.hir_id, item_visibility).generics().bounds(); self.check(item.hir_id(), item_visibility).generics().bounds();
} }
hir::ItemKind::Trait(.., trait_item_refs) => { hir::ItemKind::Trait(.., trait_item_refs) => {
self.check(item.hir_id, item_visibility).generics().predicates(); self.check(item.hir_id(), item_visibility).generics().predicates();
for trait_item_ref in trait_item_refs { for trait_item_ref in trait_item_refs {
self.check_assoc_item( self.check_assoc_item(
trait_item_ref.id.hir_id, trait_item_ref.id.hir_id(),
trait_item_ref.kind, trait_item_ref.kind,
trait_item_ref.defaultness, trait_item_ref.defaultness,
item_visibility, item_visibility,
); );
if let AssocItemKind::Type = trait_item_ref.kind { if let AssocItemKind::Type = trait_item_ref.kind {
self.check(trait_item_ref.id.hir_id, item_visibility).bounds(); self.check(trait_item_ref.id.hir_id(), item_visibility).bounds();
} }
} }
} }
hir::ItemKind::TraitAlias(..) => { hir::ItemKind::TraitAlias(..) => {
self.check(item.hir_id, item_visibility).generics().predicates(); self.check(item.hir_id(), item_visibility).generics().predicates();
} }
hir::ItemKind::Enum(ref def, _) => { hir::ItemKind::Enum(ref def, _) => {
self.check(item.hir_id, item_visibility).generics().predicates(); self.check(item.hir_id(), item_visibility).generics().predicates();
for variant in def.variants { for variant in def.variants {
for field in variant.data.fields() { for field in variant.data.fields() {
@ -1980,13 +1980,13 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx>
// Subitems of foreign modules have their own publicity. // Subitems of foreign modules have their own publicity.
hir::ItemKind::ForeignMod { items, .. } => { hir::ItemKind::ForeignMod { items, .. } => {
for foreign_item in items { for foreign_item in items {
let vis = tcx.visibility(tcx.hir().local_def_id(foreign_item.id.hir_id)); let vis = tcx.visibility(foreign_item.id.def_id);
self.check(foreign_item.id.hir_id, vis).generics().predicates().ty(); self.check(foreign_item.id.hir_id(), vis).generics().predicates().ty();
} }
} }
// Subitems of structs and unions have their own publicity. // Subitems of structs and unions have their own publicity.
hir::ItemKind::Struct(ref struct_def, _) | hir::ItemKind::Union(ref struct_def, _) => { hir::ItemKind::Struct(ref struct_def, _) | hir::ItemKind::Union(ref struct_def, _) => {
self.check(item.hir_id, item_visibility).generics().predicates(); self.check(item.hir_id(), item_visibility).generics().predicates();
for field in struct_def.fields() { for field in struct_def.fields() {
let field_visibility = tcx.visibility(tcx.hir().local_def_id(field.hir_id)); let field_visibility = tcx.visibility(tcx.hir().local_def_id(field.hir_id));
@ -1998,20 +1998,16 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx>
// A trait impl is public when both its type and its trait are public // A trait impl is public when both its type and its trait are public
// Subitems of trait impls have inherited publicity. // Subitems of trait impls have inherited publicity.
hir::ItemKind::Impl(ref impl_) => { hir::ItemKind::Impl(ref impl_) => {
let impl_vis = ty::Visibility::of_impl(item.hir_id, tcx, &Default::default()); let impl_vis = ty::Visibility::of_impl(item.hir_id(), tcx, &Default::default());
self.check(item.hir_id, impl_vis).generics().predicates(); self.check(item.hir_id(), impl_vis).generics().predicates();
for impl_item_ref in impl_.items { for impl_item_ref in impl_.items {
let impl_item_vis = if impl_.of_trait.is_none() { let impl_item_vis = if impl_.of_trait.is_none() {
min( min(tcx.visibility(impl_item_ref.id.def_id), impl_vis, tcx)
tcx.visibility(tcx.hir().local_def_id(impl_item_ref.id.hir_id)),
impl_vis,
tcx,
)
} else { } else {
impl_vis impl_vis
}; };
self.check_assoc_item( self.check_assoc_item(
impl_item_ref.id.hir_id, impl_item_ref.id.hir_id(),
impl_item_ref.kind, impl_item_ref.kind,
impl_item_ref.defaultness, impl_item_ref.defaultness,
impl_item_vis, impl_item_vis,

View file

@ -587,7 +587,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
// `type MyAnonTy<'b> = impl MyTrait<'b>;` // `type MyAnonTy<'b> = impl MyTrait<'b>;`
// ^ ^ this gets resolved in the scope of // ^ ^ this gets resolved in the scope of
// the opaque_ty generics // the opaque_ty generics
let opaque_ty = self.tcx.hir().expect_item(item_id.id); let opaque_ty = self.tcx.hir().item(item_id);
let (generics, bounds) = match opaque_ty.kind { let (generics, bounds) = match opaque_ty.kind {
// Named opaque `impl Trait` types are reached via `TyKind::Path`. // Named opaque `impl Trait` types are reached via `TyKind::Path`.
// This arm is for `impl Trait` in the types of statics, constants and locals. // This arm is for `impl Trait` in the types of statics, constants and locals.
@ -632,20 +632,32 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id); let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id);
// Ensure that the parent of the def is an item, not HRTB // Ensure that the parent of the def is an item, not HRTB
let parent_id = self.tcx.hir().get_parent_node(hir_id); let parent_id = self.tcx.hir().get_parent_node(hir_id);
let parent_impl_id = hir::ImplItemId { hir_id: parent_id }; let parent_is_item = if let Some(parent_def_id) =
let parent_trait_id = hir::TraitItemId { hir_id: parent_id }; parent_id.as_owner()
let krate = self.tcx.hir().krate();
if !(krate.items.contains_key(&parent_id)
|| krate.impl_items.contains_key(&parent_impl_id)
|| krate.trait_items.contains_key(&parent_trait_id))
{ {
let parent_item_id = hir::ItemId { def_id: parent_def_id };
let parent_impl_id = hir::ImplItemId { def_id: parent_def_id };
let parent_trait_id =
hir::TraitItemId { def_id: parent_def_id };
let parent_foreign_id =
hir::ForeignItemId { def_id: parent_def_id };
let krate = self.tcx.hir().krate();
krate.items.contains_key(&parent_item_id)
|| krate.impl_items.contains_key(&parent_impl_id)
|| krate.trait_items.contains_key(&parent_trait_id)
|| krate.foreign_items.contains_key(&parent_foreign_id)
} else {
false
};
if !parent_is_item {
struct_span_err!( struct_span_err!(
self.tcx.sess, self.tcx.sess,
lifetime.span, lifetime.span,
E0657, E0657,
"`impl Trait` can only capture lifetimes \ "`impl Trait` can only capture lifetimes \
bound at the fn or impl level" bound at the fn or impl level"
) )
.emit(); .emit();
self.uninsert_lifetime_on_error(lifetime, def.unwrap()); self.uninsert_lifetime_on_error(lifetime, def.unwrap());
@ -738,7 +750,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
self.missing_named_lifetime_spots.push((&trait_item.generics).into()); self.missing_named_lifetime_spots.push((&trait_item.generics).into());
let tcx = self.tcx; let tcx = self.tcx;
self.visit_early_late( self.visit_early_late(
Some(tcx.hir().get_parent_item(trait_item.hir_id)), Some(tcx.hir().get_parent_item(trait_item.hir_id())),
&sig.decl, &sig.decl,
&trait_item.generics, &trait_item.generics,
|this| intravisit::walk_trait_item(this, trait_item), |this| intravisit::walk_trait_item(this, trait_item),
@ -800,7 +812,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
self.missing_named_lifetime_spots.push((&impl_item.generics).into()); self.missing_named_lifetime_spots.push((&impl_item.generics).into());
let tcx = self.tcx; let tcx = self.tcx;
self.visit_early_late( self.visit_early_late(
Some(tcx.hir().get_parent_item(impl_item.hir_id)), Some(tcx.hir().get_parent_item(impl_item.hir_id())),
&sig.decl, &sig.decl,
&impl_item.generics, &impl_item.generics,
|this| intravisit::walk_impl_item(this, impl_item), |this| intravisit::walk_impl_item(this, impl_item),
@ -1255,7 +1267,7 @@ fn compute_object_lifetime_defaults(tcx: TyCtxt<'_>) -> HirIdMap<Vec<ObjectLifet
tcx.sess.span_err(item.span, &object_lifetime_default_reprs); tcx.sess.span_err(item.span, &object_lifetime_default_reprs);
} }
map.insert(item.hir_id, result); map.insert(item.hir_id(), result);
} }
_ => {} _ => {}
} }
@ -2111,7 +2123,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
self.tcx.hir().expect_item(self.tcx.hir().get_parent_item(parent)).kind self.tcx.hir().expect_item(self.tcx.hir().get_parent_item(parent)).kind
{ {
assoc_item_kind = assoc_item_kind =
trait_items.iter().find(|ti| ti.id.hir_id == parent).map(|ti| ti.kind); trait_items.iter().find(|ti| ti.id.hir_id() == parent).map(|ti| ti.kind);
} }
match *m { match *m {
hir::TraitFn::Required(_) => None, hir::TraitFn::Required(_) => None,
@ -2125,7 +2137,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
{ {
impl_self = Some(self_ty); impl_self = Some(self_ty);
assoc_item_kind = assoc_item_kind =
items.iter().find(|ii| ii.id.hir_id == parent).map(|ii| ii.kind); items.iter().find(|ii| ii.id.hir_id() == parent).map(|ii| ii.kind);
} }
Some(body) Some(body)
} }

View file

@ -373,14 +373,14 @@ impl<'tcx> DumpVisitor<'tcx> {
body: hir::BodyId, body: hir::BodyId,
) { ) {
let map = &self.tcx.hir(); let map = &self.tcx.hir();
self.nest_typeck_results(map.local_def_id(item.hir_id), |v| { self.nest_typeck_results(item.def_id, |v| {
let body = map.body(body); let body = map.body(body);
if let Some(fn_data) = v.save_ctxt.get_item_data(item) { if let Some(fn_data) = v.save_ctxt.get_item_data(item) {
down_cast_data!(fn_data, DefData, item.span); down_cast_data!(fn_data, DefData, item.span);
v.process_formals(body.params, &fn_data.qualname); v.process_formals(body.params, &fn_data.qualname);
v.process_generic_params(ty_params, &fn_data.qualname, item.hir_id); v.process_generic_params(ty_params, &fn_data.qualname, item.hir_id());
v.dumper.dump_def(&access_from!(v.save_ctxt, item, item.hir_id), fn_data); v.dumper.dump_def(&access_from!(v.save_ctxt, item, item.hir_id()), fn_data);
} }
for arg in decl.inputs { for arg in decl.inputs {
@ -401,10 +401,10 @@ impl<'tcx> DumpVisitor<'tcx> {
typ: &'tcx hir::Ty<'tcx>, typ: &'tcx hir::Ty<'tcx>,
expr: &'tcx hir::Expr<'tcx>, expr: &'tcx hir::Expr<'tcx>,
) { ) {
self.nest_typeck_results(self.tcx.hir().local_def_id(item.hir_id), |v| { self.nest_typeck_results(item.def_id, |v| {
if let Some(var_data) = v.save_ctxt.get_item_data(item) { if let Some(var_data) = v.save_ctxt.get_item_data(item) {
down_cast_data!(var_data, DefData, item.span); down_cast_data!(var_data, DefData, item.span);
v.dumper.dump_def(&access_from!(v.save_ctxt, item, item.hir_id), var_data); v.dumper.dump_def(&access_from!(v.save_ctxt, item, item.hir_id()), var_data);
} }
v.visit_ty(&typ); v.visit_ty(&typ);
v.visit_expr(expr); v.visit_expr(expr);
@ -465,10 +465,7 @@ impl<'tcx> DumpVisitor<'tcx> {
) { ) {
debug!("process_struct {:?} {:?}", item, item.span); debug!("process_struct {:?} {:?}", item, item.span);
let name = item.ident.to_string(); let name = item.ident.to_string();
let qualname = format!( let qualname = format!("::{}", self.tcx.def_path_str(item.def_id.to_def_id()));
"::{}",
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.hir_id).to_def_id())
);
let kind = match item.kind { let kind = match item.kind {
hir::ItemKind::Struct(_, _) => DefKind::Struct, hir::ItemKind::Struct(_, _) => DefKind::Struct,
@ -500,10 +497,10 @@ impl<'tcx> DumpVisitor<'tcx> {
if !self.span.filter_generated(item.ident.span) { if !self.span.filter_generated(item.ident.span) {
let span = self.span_from_span(item.ident.span); let span = self.span_from_span(item.ident.span);
self.dumper.dump_def( self.dumper.dump_def(
&access_from!(self.save_ctxt, item, item.hir_id), &access_from!(self.save_ctxt, item, item.hir_id()),
Def { Def {
kind, kind,
id: id_from_hir_id(item.hir_id, &self.save_ctxt), id: id_from_def_id(item.def_id.to_def_id()),
span, span,
name, name,
qualname: qualname.clone(), qualname: qualname.clone(),
@ -518,13 +515,13 @@ impl<'tcx> DumpVisitor<'tcx> {
); );
} }
self.nest_typeck_results(self.tcx.hir().local_def_id(item.hir_id), |v| { self.nest_typeck_results(item.def_id, |v| {
for field in def.fields() { for field in def.fields() {
v.process_struct_field_def(field, item.hir_id); v.process_struct_field_def(field, item.hir_id());
v.visit_ty(&field.ty); v.visit_ty(&field.ty);
} }
v.process_generic_params(ty_params, &qualname, item.hir_id); v.process_generic_params(ty_params, &qualname, item.hir_id());
}); });
} }
@ -541,7 +538,7 @@ impl<'tcx> DumpVisitor<'tcx> {
}; };
down_cast_data!(enum_data, DefData, item.span); down_cast_data!(enum_data, DefData, item.span);
let access = access_from!(self.save_ctxt, item, item.hir_id); let access = access_from!(self.save_ctxt, item, item.hir_id());
for variant in enum_definition.variants { for variant in enum_definition.variants {
let name = variant.ident.name.to_string(); let name = variant.ident.name.to_string();
@ -556,7 +553,7 @@ impl<'tcx> DumpVisitor<'tcx> {
if !self.span.filter_generated(name_span) { if !self.span.filter_generated(name_span) {
let span = self.span_from_span(name_span); let span = self.span_from_span(name_span);
let id = id_from_hir_id(variant.id, &self.save_ctxt); let id = id_from_hir_id(variant.id, &self.save_ctxt);
let parent = Some(id_from_hir_id(item.hir_id, &self.save_ctxt)); let parent = Some(id_from_def_id(item.def_id.to_def_id()));
self.dumper.dump_def( self.dumper.dump_def(
&access, &access,
@ -596,7 +593,7 @@ impl<'tcx> DumpVisitor<'tcx> {
if !self.span.filter_generated(name_span) { if !self.span.filter_generated(name_span) {
let span = self.span_from_span(name_span); let span = self.span_from_span(name_span);
let id = id_from_hir_id(variant.id, &self.save_ctxt); let id = id_from_hir_id(variant.id, &self.save_ctxt);
let parent = Some(id_from_hir_id(item.hir_id, &self.save_ctxt)); let parent = Some(id_from_def_id(item.def_id.to_def_id()));
self.dumper.dump_def( self.dumper.dump_def(
&access, &access,
@ -627,7 +624,7 @@ impl<'tcx> DumpVisitor<'tcx> {
self.visit_ty(field.ty); self.visit_ty(field.ty);
} }
} }
self.process_generic_params(ty_params, &enum_data.qualname, item.hir_id); self.process_generic_params(ty_params, &enum_data.qualname, item.hir_id());
self.dumper.dump_def(&access, enum_data); self.dumper.dump_def(&access, enum_data);
} }
@ -644,17 +641,14 @@ impl<'tcx> DumpVisitor<'tcx> {
} }
let map = &self.tcx.hir(); let map = &self.tcx.hir();
self.nest_typeck_results(map.local_def_id(item.hir_id), |v| { self.nest_typeck_results(item.def_id, |v| {
v.visit_ty(&impl_.self_ty); v.visit_ty(&impl_.self_ty);
if let Some(trait_ref) = &impl_.of_trait { if let Some(trait_ref) = &impl_.of_trait {
v.process_path(trait_ref.hir_ref_id, &hir::QPath::Resolved(None, &trait_ref.path)); v.process_path(trait_ref.hir_ref_id, &hir::QPath::Resolved(None, &trait_ref.path));
} }
v.process_generic_params(&impl_.generics, "", item.hir_id); v.process_generic_params(&impl_.generics, "", item.hir_id());
for impl_item in impl_.items { for impl_item in impl_.items {
v.process_impl_item( v.process_impl_item(map.impl_item(impl_item.id), item.def_id.to_def_id());
map.impl_item(impl_item.id),
map.local_def_id(item.hir_id).to_def_id(),
);
} }
}); });
} }
@ -667,10 +661,7 @@ impl<'tcx> DumpVisitor<'tcx> {
methods: &'tcx [hir::TraitItemRef], methods: &'tcx [hir::TraitItemRef],
) { ) {
let name = item.ident.to_string(); let name = item.ident.to_string();
let qualname = format!( let qualname = format!("::{}", self.tcx.def_path_str(item.def_id.to_def_id()));
"::{}",
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.hir_id).to_def_id())
);
let mut val = name.clone(); let mut val = name.clone();
if !generics.params.is_empty() { if !generics.params.is_empty() {
val.push_str(&generic_params_to_string(generics.params)); val.push_str(&generic_params_to_string(generics.params));
@ -680,12 +671,12 @@ impl<'tcx> DumpVisitor<'tcx> {
val.push_str(&bounds_to_string(trait_refs)); val.push_str(&bounds_to_string(trait_refs));
} }
if !self.span.filter_generated(item.ident.span) { if !self.span.filter_generated(item.ident.span) {
let id = id_from_hir_id(item.hir_id, &self.save_ctxt); let id = id_from_def_id(item.def_id.to_def_id());
let span = self.span_from_span(item.ident.span); let span = self.span_from_span(item.ident.span);
let children = let children =
methods.iter().map(|i| id_from_hir_id(i.id.hir_id, &self.save_ctxt)).collect(); methods.iter().map(|i| id_from_def_id(i.id.def_id.to_def_id())).collect();
self.dumper.dump_def( self.dumper.dump_def(
&access_from!(self.save_ctxt, item, item.hir_id), &access_from!(self.save_ctxt, item, item.hir_id()),
Def { Def {
kind: DefKind::Trait, kind: DefKind::Trait,
id, id,
@ -729,20 +720,17 @@ impl<'tcx> DumpVisitor<'tcx> {
kind: RelationKind::SuperTrait, kind: RelationKind::SuperTrait,
span, span,
from: id_from_def_id(id), from: id_from_def_id(id),
to: id_from_hir_id(item.hir_id, &self.save_ctxt), to: id_from_def_id(item.def_id.to_def_id()),
}); });
} }
} }
} }
// walk generics and methods // walk generics and methods
self.process_generic_params(generics, &qualname, item.hir_id); self.process_generic_params(generics, &qualname, item.hir_id());
for method in methods { for method in methods {
let map = &self.tcx.hir(); let map = &self.tcx.hir();
self.process_trait_item( self.process_trait_item(map.trait_item(method.id), item.def_id.to_def_id())
map.trait_item(method.id),
map.local_def_id(item.hir_id).to_def_id(),
)
} }
} }
@ -750,7 +738,7 @@ impl<'tcx> DumpVisitor<'tcx> {
fn process_mod(&mut self, item: &'tcx hir::Item<'tcx>) { fn process_mod(&mut self, item: &'tcx hir::Item<'tcx>) {
if let Some(mod_data) = self.save_ctxt.get_item_data(item) { if let Some(mod_data) = self.save_ctxt.get_item_data(item) {
down_cast_data!(mod_data, DefData, item.span); down_cast_data!(mod_data, DefData, item.span);
self.dumper.dump_def(&access_from!(self.save_ctxt, item, item.hir_id), mod_data); self.dumper.dump_def(&access_from!(self.save_ctxt, item, item.hir_id()), mod_data);
} }
} }
@ -1011,7 +999,7 @@ impl<'tcx> DumpVisitor<'tcx> {
let body = body.map(|b| &self.tcx.hir().body(b).value); let body = body.map(|b| &self.tcx.hir().body(b).value);
let respan = respan(vis_span, hir::VisibilityKind::Public); let respan = respan(vis_span, hir::VisibilityKind::Public);
self.process_assoc_const( self.process_assoc_const(
trait_item.hir_id, trait_item.hir_id(),
trait_item.ident, trait_item.ident,
&ty, &ty,
body, body,
@ -1027,7 +1015,7 @@ impl<'tcx> DumpVisitor<'tcx> {
self.process_method( self.process_method(
sig, sig,
body, body,
trait_item.hir_id, trait_item.hir_id(),
trait_item.ident, trait_item.ident,
&trait_item.generics, &trait_item.generics,
&respan, &respan,
@ -1037,15 +1025,12 @@ impl<'tcx> DumpVisitor<'tcx> {
hir::TraitItemKind::Type(ref bounds, ref default_ty) => { hir::TraitItemKind::Type(ref bounds, ref default_ty) => {
// FIXME do something with _bounds (for type refs) // FIXME do something with _bounds (for type refs)
let name = trait_item.ident.name.to_string(); let name = trait_item.ident.name.to_string();
let qualname = format!( let qualname =
"::{}", format!("::{}", self.tcx.def_path_str(trait_item.def_id.to_def_id()));
self.tcx
.def_path_str(self.tcx.hir().local_def_id(trait_item.hir_id).to_def_id())
);
if !self.span.filter_generated(trait_item.ident.span) { if !self.span.filter_generated(trait_item.ident.span) {
let span = self.span_from_span(trait_item.ident.span); let span = self.span_from_span(trait_item.ident.span);
let id = id_from_hir_id(trait_item.hir_id, &self.save_ctxt); let id = id_from_def_id(trait_item.def_id.to_def_id());
self.dumper.dump_def( self.dumper.dump_def(
&Access { public: true, reachable: true }, &Access { public: true, reachable: true },
@ -1061,7 +1046,7 @@ impl<'tcx> DumpVisitor<'tcx> {
decl_id: None, decl_id: None,
docs: self.save_ctxt.docs_for_attrs(&trait_item.attrs), docs: self.save_ctxt.docs_for_attrs(&trait_item.attrs),
sig: sig::assoc_type_signature( sig: sig::assoc_type_signature(
trait_item.hir_id, trait_item.hir_id(),
trait_item.ident, trait_item.ident,
Some(bounds), Some(bounds),
default_ty.as_ref().map(|ty| &**ty), default_ty.as_ref().map(|ty| &**ty),
@ -1088,7 +1073,7 @@ impl<'tcx> DumpVisitor<'tcx> {
hir::ImplItemKind::Const(ref ty, body) => { hir::ImplItemKind::Const(ref ty, body) => {
let body = self.tcx.hir().body(body); let body = self.tcx.hir().body(body);
self.process_assoc_const( self.process_assoc_const(
impl_item.hir_id, impl_item.hir_id(),
impl_item.ident, impl_item.ident,
&ty, &ty,
Some(&body.value), Some(&body.value),
@ -1101,7 +1086,7 @@ impl<'tcx> DumpVisitor<'tcx> {
self.process_method( self.process_method(
sig, sig,
Some(body), Some(body),
impl_item.hir_id, impl_item.hir_id(),
impl_item.ident, impl_item.ident,
&impl_item.generics, &impl_item.generics,
&impl_item.vis, &impl_item.vis,
@ -1130,7 +1115,7 @@ impl<'tcx> DumpVisitor<'tcx> {
.module .module
.item_ids .item_ids
.iter() .iter()
.map(|i| id_from_hir_id(i.id, &self.save_ctxt)) .map(|i| id_from_def_id(i.def_id.to_def_id()))
.collect(); .collect();
let span = self.span_from_span(krate.item.span); let span = self.span_from_span(krate.item.span);
@ -1179,16 +1164,11 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
hir::ItemKind::Use(path, hir::UseKind::Single) => { hir::ItemKind::Use(path, hir::UseKind::Single) => {
let sub_span = path.segments.last().unwrap().ident.span; let sub_span = path.segments.last().unwrap().ident.span;
if !self.span.filter_generated(sub_span) { if !self.span.filter_generated(sub_span) {
let access = access_from!(self.save_ctxt, item, item.hir_id); let access = access_from!(self.save_ctxt, item, item.hir_id());
let ref_id = self.lookup_def_id(item.hir_id).map(id_from_def_id); let ref_id = self.lookup_def_id(item.hir_id()).map(id_from_def_id);
let span = self.span_from_span(sub_span); let span = self.span_from_span(sub_span);
let parent = self let parent =
.save_ctxt self.save_ctxt.tcx.parent(item.def_id.to_def_id()).map(id_from_def_id);
.tcx
.hir()
.opt_local_def_id(item.hir_id)
.and_then(|id| self.save_ctxt.tcx.parent(id.to_def_id()))
.map(id_from_def_id);
self.dumper.import( self.dumper.import(
&access, &access,
Import { Import {
@ -1206,23 +1186,17 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
} }
hir::ItemKind::Use(path, hir::UseKind::Glob) => { hir::ItemKind::Use(path, hir::UseKind::Glob) => {
// Make a comma-separated list of names of imported modules. // Make a comma-separated list of names of imported modules.
let def_id = self.tcx.hir().local_def_id(item.hir_id); let names = self.tcx.names_imported_by_glob_use(item.def_id);
let names = self.tcx.names_imported_by_glob_use(def_id);
let names: Vec<_> = names.iter().map(|n| n.to_string()).collect(); let names: Vec<_> = names.iter().map(|n| n.to_string()).collect();
// Otherwise it's a span with wrong macro expansion info, which // Otherwise it's a span with wrong macro expansion info, which
// we don't want to track anyway, since it's probably macro-internal `use` // we don't want to track anyway, since it's probably macro-internal `use`
if let Some(sub_span) = self.span.sub_span_of_star(item.span) { if let Some(sub_span) = self.span.sub_span_of_star(item.span) {
if !self.span.filter_generated(item.span) { if !self.span.filter_generated(item.span) {
let access = access_from!(self.save_ctxt, item, item.hir_id); let access = access_from!(self.save_ctxt, item, item.hir_id());
let span = self.span_from_span(sub_span); let span = self.span_from_span(sub_span);
let parent = self let parent =
.save_ctxt self.save_ctxt.tcx.parent(item.def_id.to_def_id()).map(id_from_def_id);
.tcx
.hir()
.opt_local_def_id(item.hir_id)
.and_then(|id| self.save_ctxt.tcx.parent(id.to_def_id()))
.map(id_from_def_id);
self.dumper.import( self.dumper.import(
&access, &access,
Import { Import {
@ -1243,13 +1217,8 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
let name_span = item.ident.span; let name_span = item.ident.span;
if !self.span.filter_generated(name_span) { if !self.span.filter_generated(name_span) {
let span = self.span_from_span(name_span); let span = self.span_from_span(name_span);
let parent = self let parent =
.save_ctxt self.save_ctxt.tcx.parent(item.def_id.to_def_id()).map(id_from_def_id);
.tcx
.hir()
.opt_local_def_id(item.hir_id)
.and_then(|id| self.save_ctxt.tcx.parent(id.to_def_id()))
.map(id_from_def_id);
self.dumper.import( self.dumper.import(
&Access { public: false, reachable: false }, &Access { public: false, reachable: false },
Import { Import {
@ -1286,20 +1255,17 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
} }
hir::ItemKind::Mod(ref m) => { hir::ItemKind::Mod(ref m) => {
self.process_mod(item); self.process_mod(item);
intravisit::walk_mod(self, m, item.hir_id); intravisit::walk_mod(self, m, item.hir_id());
} }
hir::ItemKind::TyAlias(ty, ref generics) => { hir::ItemKind::TyAlias(ty, ref generics) => {
let qualname = format!( let qualname = format!("::{}", self.tcx.def_path_str(item.def_id.to_def_id()));
"::{}",
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.hir_id).to_def_id())
);
let value = ty_to_string(&ty); let value = ty_to_string(&ty);
if !self.span.filter_generated(item.ident.span) { if !self.span.filter_generated(item.ident.span) {
let span = self.span_from_span(item.ident.span); let span = self.span_from_span(item.ident.span);
let id = id_from_hir_id(item.hir_id, &self.save_ctxt); let id = id_from_def_id(item.def_id.to_def_id());
self.dumper.dump_def( self.dumper.dump_def(
&access_from!(self.save_ctxt, item, item.hir_id), &access_from!(self.save_ctxt, item, item.hir_id()),
Def { Def {
kind: DefKind::Type, kind: DefKind::Type,
id, id,
@ -1318,7 +1284,7 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
} }
self.visit_ty(ty); self.visit_ty(ty);
self.process_generic_params(generics, &qualname, item.hir_id); self.process_generic_params(generics, &qualname, item.hir_id());
} }
_ => intravisit::walk_item(self, item), _ => intravisit::walk_item(self, item),
} }
@ -1382,10 +1348,8 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
}); });
} }
hir::TyKind::OpaqueDef(item_id, _) => { hir::TyKind::OpaqueDef(item_id, _) => {
let item = self.tcx.hir().item(item_id.id); let item = self.tcx.hir().item(item_id);
self.nest_typeck_results(self.tcx.hir().local_def_id(item_id.id), |v| { self.nest_typeck_results(item_id.def_id, |v| v.visit_item(item));
v.visit_item(item)
});
} }
_ => intravisit::walk_ty(self, t), _ => intravisit::walk_ty(self, t),
} }
@ -1485,14 +1449,14 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
} }
fn visit_foreign_item(&mut self, item: &'tcx hir::ForeignItem<'tcx>) { fn visit_foreign_item(&mut self, item: &'tcx hir::ForeignItem<'tcx>) {
let access = access_from!(self.save_ctxt, item, item.hir_id); let access = access_from!(self.save_ctxt, item, item.hir_id());
match item.kind { match item.kind {
hir::ForeignItemKind::Fn(decl, _, ref generics) => { hir::ForeignItemKind::Fn(decl, _, ref generics) => {
if let Some(fn_data) = self.save_ctxt.get_extern_item_data(item) { if let Some(fn_data) = self.save_ctxt.get_extern_item_data(item) {
down_cast_data!(fn_data, DefData, item.span); down_cast_data!(fn_data, DefData, item.span);
self.process_generic_params(generics, &fn_data.qualname, item.hir_id); self.process_generic_params(generics, &fn_data.qualname, item.hir_id());
self.dumper.dump_def(&access, fn_data); self.dumper.dump_def(&access, fn_data);
} }

View file

@ -137,7 +137,7 @@ impl<'tcx> SaveContext<'tcx> {
} }
pub fn get_extern_item_data(&self, item: &hir::ForeignItem<'_>) -> Option<Data> { pub fn get_extern_item_data(&self, item: &hir::ForeignItem<'_>) -> Option<Data> {
let def_id = self.tcx.hir().local_def_id(item.hir_id).to_def_id(); let def_id = item.def_id.to_def_id();
let qualname = format!("::{}", self.tcx.def_path_str(def_id)); let qualname = format!("::{}", self.tcx.def_path_str(def_id));
match item.kind { match item.kind {
hir::ForeignItemKind::Fn(ref decl, arg_names, ref generics) => { hir::ForeignItemKind::Fn(ref decl, arg_names, ref generics) => {
@ -156,7 +156,7 @@ impl<'tcx> SaveContext<'tcx> {
unsafety: hir::Unsafety::Unsafe, unsafety: hir::Unsafety::Unsafe,
// functions in extern block cannot be const // functions in extern block cannot be const
constness: hir::Constness::NotConst, constness: hir::Constness::NotConst,
abi: self.tcx.hir().get_foreign_abi(item.hir_id), abi: self.tcx.hir().get_foreign_abi(item.hir_id()),
// functions in extern block cannot be async // functions in extern block cannot be async
asyncness: hir::IsAsync::NotAsync, asyncness: hir::IsAsync::NotAsync,
}, },
@ -201,7 +201,7 @@ impl<'tcx> SaveContext<'tcx> {
} }
pub fn get_item_data(&self, item: &hir::Item<'_>) -> Option<Data> { pub fn get_item_data(&self, item: &hir::Item<'_>) -> Option<Data> {
let def_id = self.tcx.hir().local_def_id(item.hir_id).to_def_id(); let def_id = item.def_id.to_def_id();
match item.kind { match item.kind {
hir::ItemKind::Fn(ref sig, ref generics, _) => { hir::ItemKind::Fn(ref sig, ref generics, _) => {
let qualname = format!("::{}", self.tcx.def_path_str(def_id)); let qualname = format!("::{}", self.tcx.def_path_str(def_id));
@ -290,7 +290,11 @@ impl<'tcx> SaveContext<'tcx> {
span: self.span_from_span(item.ident.span), span: self.span_from_span(item.ident.span),
value: filename.to_string(), value: filename.to_string(),
parent: None, parent: None,
children: m.item_ids.iter().map(|i| id_from_hir_id(i.id, self)).collect(), children: m
.item_ids
.iter()
.map(|i| id_from_def_id(i.def_id.to_def_id()))
.collect(),
decl_id: None, decl_id: None,
docs: self.docs_for_attrs(&item.attrs), docs: self.docs_for_attrs(&item.attrs),
sig: sig::item_signature(item, self), sig: sig::item_signature(item, self),
@ -354,7 +358,7 @@ impl<'tcx> SaveContext<'tcx> {
parent: None, parent: None,
children: items children: items
.iter() .iter()
.map(|i| id_from_hir_id(i.id.hir_id, self)) .map(|i| id_from_def_id(i.id.def_id.to_def_id()))
.collect(), .collect(),
docs: String::new(), docs: String::new(),
sig: None, sig: None,

View file

@ -317,8 +317,8 @@ impl<'hir> Sig for hir::Ty<'hir> {
Ok(replace_text(nested_ty, text)) Ok(replace_text(nested_ty, text))
} }
hir::TyKind::OpaqueDef(item_id, _) => { hir::TyKind::OpaqueDef(item_id, _) => {
let item = scx.tcx.hir().item(item_id.id); let item = scx.tcx.hir().item(item_id);
item.make(offset, Some(item_id.id), scx) item.make(offset, Some(item_id.hir_id()), scx)
} }
hir::TyKind::Typeof(_) | hir::TyKind::Infer | hir::TyKind::Err => Err("Ty"), hir::TyKind::Typeof(_) | hir::TyKind::Infer | hir::TyKind::Err => Err("Ty"),
} }
@ -327,7 +327,7 @@ impl<'hir> Sig for hir::Ty<'hir> {
impl<'hir> Sig for hir::Item<'hir> { impl<'hir> Sig for hir::Item<'hir> {
fn make(&self, offset: usize, _parent_id: Option<hir::HirId>, scx: &SaveContext<'_>) -> Result { fn make(&self, offset: usize, _parent_id: Option<hir::HirId>, scx: &SaveContext<'_>) -> Result {
let id = Some(self.hir_id); let id = Some(self.hir_id());
match self.kind { match self.kind {
hir::ItemKind::Static(ref ty, m, ref body) => { hir::ItemKind::Static(ref ty, m, ref body) => {
@ -337,7 +337,7 @@ impl<'hir> Sig for hir::Item<'hir> {
} }
let name = self.ident.to_string(); let name = self.ident.to_string();
let defs = vec![SigElement { let defs = vec![SigElement {
id: id_from_hir_id(self.hir_id, scx), id: id_from_def_id(self.def_id.to_def_id()),
start: offset + text.len(), start: offset + text.len(),
end: offset + text.len() + name.len(), end: offset + text.len() + name.len(),
}]; }];
@ -359,7 +359,7 @@ impl<'hir> Sig for hir::Item<'hir> {
let mut text = "const ".to_owned(); let mut text = "const ".to_owned();
let name = self.ident.to_string(); let name = self.ident.to_string();
let defs = vec![SigElement { let defs = vec![SigElement {
id: id_from_hir_id(self.hir_id, scx), id: id_from_def_id(self.def_id.to_def_id()),
start: offset + text.len(), start: offset + text.len(),
end: offset + text.len() + name.len(), end: offset + text.len() + name.len(),
}]; }];
@ -391,7 +391,7 @@ impl<'hir> Sig for hir::Item<'hir> {
text.push_str("fn "); text.push_str("fn ");
let mut sig = let mut sig =
name_and_generics(text, offset, generics, self.hir_id, self.ident, scx)?; name_and_generics(text, offset, generics, self.hir_id(), self.ident, scx)?;
sig.text.push('('); sig.text.push('(');
for i in decl.inputs { for i in decl.inputs {
@ -420,7 +420,7 @@ impl<'hir> Sig for hir::Item<'hir> {
let mut text = "mod ".to_owned(); let mut text = "mod ".to_owned();
let name = self.ident.to_string(); let name = self.ident.to_string();
let defs = vec![SigElement { let defs = vec![SigElement {
id: id_from_hir_id(self.hir_id, scx), id: id_from_def_id(self.def_id.to_def_id()),
start: offset + text.len(), start: offset + text.len(),
end: offset + text.len() + name.len(), end: offset + text.len() + name.len(),
}]; }];
@ -433,7 +433,7 @@ impl<'hir> Sig for hir::Item<'hir> {
hir::ItemKind::TyAlias(ref ty, ref generics) => { hir::ItemKind::TyAlias(ref ty, ref generics) => {
let text = "type ".to_owned(); let text = "type ".to_owned();
let mut sig = let mut sig =
name_and_generics(text, offset, generics, self.hir_id, self.ident, scx)?; name_and_generics(text, offset, generics, self.hir_id(), self.ident, scx)?;
sig.text.push_str(" = "); sig.text.push_str(" = ");
let ty = ty.make(offset + sig.text.len(), id, scx)?; let ty = ty.make(offset + sig.text.len(), id, scx)?;
@ -445,21 +445,21 @@ impl<'hir> Sig for hir::Item<'hir> {
hir::ItemKind::Enum(_, ref generics) => { hir::ItemKind::Enum(_, ref generics) => {
let text = "enum ".to_owned(); let text = "enum ".to_owned();
let mut sig = let mut sig =
name_and_generics(text, offset, generics, self.hir_id, self.ident, scx)?; name_and_generics(text, offset, generics, self.hir_id(), self.ident, scx)?;
sig.text.push_str(" {}"); sig.text.push_str(" {}");
Ok(sig) Ok(sig)
} }
hir::ItemKind::Struct(_, ref generics) => { hir::ItemKind::Struct(_, ref generics) => {
let text = "struct ".to_owned(); let text = "struct ".to_owned();
let mut sig = let mut sig =
name_and_generics(text, offset, generics, self.hir_id, self.ident, scx)?; name_and_generics(text, offset, generics, self.hir_id(), self.ident, scx)?;
sig.text.push_str(" {}"); sig.text.push_str(" {}");
Ok(sig) Ok(sig)
} }
hir::ItemKind::Union(_, ref generics) => { hir::ItemKind::Union(_, ref generics) => {
let text = "union ".to_owned(); let text = "union ".to_owned();
let mut sig = let mut sig =
name_and_generics(text, offset, generics, self.hir_id, self.ident, scx)?; name_and_generics(text, offset, generics, self.hir_id(), self.ident, scx)?;
sig.text.push_str(" {}"); sig.text.push_str(" {}");
Ok(sig) Ok(sig)
} }
@ -475,7 +475,7 @@ impl<'hir> Sig for hir::Item<'hir> {
} }
text.push_str("trait "); text.push_str("trait ");
let mut sig = let mut sig =
name_and_generics(text, offset, generics, self.hir_id, self.ident, scx)?; name_and_generics(text, offset, generics, self.hir_id(), self.ident, scx)?;
if !bounds.is_empty() { if !bounds.is_empty() {
sig.text.push_str(": "); sig.text.push_str(": ");
@ -490,7 +490,7 @@ impl<'hir> Sig for hir::Item<'hir> {
let mut text = String::new(); let mut text = String::new();
text.push_str("trait "); text.push_str("trait ");
let mut sig = let mut sig =
name_and_generics(text, offset, generics, self.hir_id, self.ident, scx)?; name_and_generics(text, offset, generics, self.hir_id(), self.ident, scx)?;
if !bounds.is_empty() { if !bounds.is_empty() {
sig.text.push_str(" = "); sig.text.push_str(" = ");
@ -736,14 +736,14 @@ impl<'hir> Sig for hir::Variant<'hir> {
impl<'hir> Sig for hir::ForeignItem<'hir> { impl<'hir> Sig for hir::ForeignItem<'hir> {
fn make(&self, offset: usize, _parent_id: Option<hir::HirId>, scx: &SaveContext<'_>) -> Result { fn make(&self, offset: usize, _parent_id: Option<hir::HirId>, scx: &SaveContext<'_>) -> Result {
let id = Some(self.hir_id); let id = Some(self.hir_id());
match self.kind { match self.kind {
hir::ForeignItemKind::Fn(decl, _, ref generics) => { hir::ForeignItemKind::Fn(decl, _, ref generics) => {
let mut text = String::new(); let mut text = String::new();
text.push_str("fn "); text.push_str("fn ");
let mut sig = let mut sig =
name_and_generics(text, offset, generics, self.hir_id, self.ident, scx)?; name_and_generics(text, offset, generics, self.hir_id(), self.ident, scx)?;
sig.text.push('('); sig.text.push('(');
for i in decl.inputs { for i in decl.inputs {
@ -774,7 +774,7 @@ impl<'hir> Sig for hir::ForeignItem<'hir> {
} }
let name = self.ident.to_string(); let name = self.ident.to_string();
let defs = vec![SigElement { let defs = vec![SigElement {
id: id_from_hir_id(self.hir_id, scx), id: id_from_def_id(self.def_id.to_def_id()),
start: offset + text.len(), start: offset + text.len(),
end: offset + text.len() + name.len(), end: offset + text.len() + name.len(),
}]; }];
@ -790,7 +790,7 @@ impl<'hir> Sig for hir::ForeignItem<'hir> {
let mut text = "type ".to_owned(); let mut text = "type ".to_owned();
let name = self.ident.to_string(); let name = self.ident.to_string();
let defs = vec![SigElement { let defs = vec![SigElement {
id: id_from_hir_id(self.hir_id, scx), id: id_from_def_id(self.def_id.to_def_id()),
start: offset + text.len(), start: offset + text.len(),
end: offset + text.len() + name.len(), end: offset + text.len() + name.len(),
}]; }];

View file

@ -227,6 +227,8 @@ pub struct LocalDefId {
pub local_def_index: DefIndex, pub local_def_index: DefIndex,
} }
pub const CRATE_DEF_ID: LocalDefId = LocalDefId { local_def_index: CRATE_DEF_INDEX };
impl Idx for LocalDefId { impl Idx for LocalDefId {
#[inline] #[inline]
fn new(idx: usize) -> Self { fn new(idx: usize) -> Self {
@ -268,6 +270,8 @@ impl<D: Decoder> Decodable<D> for LocalDefId {
} }
} }
rustc_data_structures::define_id_collections!(LocalDefIdMap, LocalDefIdSet, LocalDefId);
impl<CTX: HashStableContext> HashStable<CTX> for DefId { impl<CTX: HashStableContext> HashStable<CTX> for DefId {
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
hcx.hash_def_id(*self, hasher) hcx.hash_def_id(*self, hasher)

View file

@ -5,6 +5,7 @@
//! paths etc in all kinds of annoying scenarios. //! paths etc in all kinds of annoying scenarios.
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::LocalDefId;
use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::{subst::InternalSubsts, Instance, TyCtxt}; use rustc_middle::ty::{subst::InternalSubsts, Instance, TyCtxt};
use rustc_span::symbol::{sym, Symbol}; use rustc_span::symbol::{sym, Symbol};
@ -31,9 +32,8 @@ struct SymbolNamesTest<'tcx> {
} }
impl SymbolNamesTest<'tcx> { impl SymbolNamesTest<'tcx> {
fn process_attrs(&mut self, hir_id: hir::HirId) { fn process_attrs(&mut self, def_id: LocalDefId) {
let tcx = self.tcx; let tcx = self.tcx;
let def_id = tcx.hir().local_def_id(hir_id);
for attr in tcx.get_attrs(def_id.to_def_id()).iter() { for attr in tcx.get_attrs(def_id.to_def_id()).iter() {
if tcx.sess.check_name(attr, SYMBOL_NAME) { if tcx.sess.check_name(attr, SYMBOL_NAME) {
let def_id = def_id.to_def_id(); let def_id = def_id.to_def_id();
@ -61,18 +61,18 @@ impl SymbolNamesTest<'tcx> {
impl hir::itemlikevisit::ItemLikeVisitor<'tcx> for SymbolNamesTest<'tcx> { impl hir::itemlikevisit::ItemLikeVisitor<'tcx> for SymbolNamesTest<'tcx> {
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
self.process_attrs(item.hir_id); self.process_attrs(item.def_id);
} }
fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) { fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) {
self.process_attrs(trait_item.hir_id); self.process_attrs(trait_item.def_id);
} }
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) { fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
self.process_attrs(impl_item.hir_id); self.process_attrs(impl_item.def_id);
} }
fn visit_foreign_item(&mut self, foreign_item: &'tcx hir::ForeignItem<'tcx>) { fn visit_foreign_item(&mut self, foreign_item: &'tcx hir::ForeignItem<'tcx>) {
self.process_attrs(foreign_item.hir_id); self.process_attrs(foreign_item.def_id);
} }
} }

View file

@ -82,7 +82,7 @@ fn associated_item_from_trait_item_ref(
parent_def_id: LocalDefId, parent_def_id: LocalDefId,
trait_item_ref: &hir::TraitItemRef, trait_item_ref: &hir::TraitItemRef,
) -> ty::AssocItem { ) -> ty::AssocItem {
let def_id = tcx.hir().local_def_id(trait_item_ref.id.hir_id); let def_id = trait_item_ref.id.def_id;
let (kind, has_self) = match trait_item_ref.kind { let (kind, has_self) = match trait_item_ref.kind {
hir::AssocItemKind::Const => (ty::AssocKind::Const, false), hir::AssocItemKind::Const => (ty::AssocKind::Const, false),
hir::AssocItemKind::Fn { has_self } => (ty::AssocKind::Fn, has_self), hir::AssocItemKind::Fn { has_self } => (ty::AssocKind::Fn, has_self),
@ -105,7 +105,7 @@ fn associated_item_from_impl_item_ref(
parent_def_id: LocalDefId, parent_def_id: LocalDefId,
impl_item_ref: &hir::ImplItemRef<'_>, impl_item_ref: &hir::ImplItemRef<'_>,
) -> ty::AssocItem { ) -> ty::AssocItem {
let def_id = tcx.hir().local_def_id(impl_item_ref.id.hir_id); let def_id = impl_item_ref.id.def_id;
let (kind, has_self) = match impl_item_ref.kind { let (kind, has_self) = match impl_item_ref.kind {
hir::AssocItemKind::Const => (ty::AssocKind::Const, false), hir::AssocItemKind::Const => (ty::AssocKind::Const, false),
hir::AssocItemKind::Fn { has_self } => (ty::AssocKind::Fn, has_self), hir::AssocItemKind::Fn { has_self } => (ty::AssocKind::Fn, has_self),
@ -130,7 +130,9 @@ fn associated_item(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AssocItem {
let parent_item = tcx.hir().expect_item(parent_id); let parent_item = tcx.hir().expect_item(parent_id);
match parent_item.kind { match parent_item.kind {
hir::ItemKind::Impl(ref impl_) => { hir::ItemKind::Impl(ref impl_) => {
if let Some(impl_item_ref) = impl_.items.iter().find(|i| i.id.hir_id == id) { if let Some(impl_item_ref) =
impl_.items.iter().find(|i| i.id.def_id.to_def_id() == def_id)
{
let assoc_item = let assoc_item =
associated_item_from_impl_item_ref(tcx, parent_def_id, impl_item_ref); associated_item_from_impl_item_ref(tcx, parent_def_id, impl_item_ref);
debug_assert_eq!(assoc_item.def_id, def_id); debug_assert_eq!(assoc_item.def_id, def_id);
@ -139,7 +141,9 @@ fn associated_item(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AssocItem {
} }
hir::ItemKind::Trait(.., ref trait_item_refs) => { hir::ItemKind::Trait(.., ref trait_item_refs) => {
if let Some(trait_item_ref) = trait_item_refs.iter().find(|i| i.id.hir_id == id) { if let Some(trait_item_ref) =
trait_item_refs.iter().find(|i| i.id.def_id.to_def_id() == def_id)
{
let assoc_item = let assoc_item =
associated_item_from_trait_item_ref(tcx, parent_def_id, trait_item_ref); associated_item_from_trait_item_ref(tcx, parent_def_id, trait_item_ref);
debug_assert_eq!(assoc_item.def_id, def_id); debug_assert_eq!(assoc_item.def_id, def_id);
@ -196,17 +200,10 @@ fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: DefId) -> &[DefId] {
let item = tcx.hir().expect_item(id); let item = tcx.hir().expect_item(id);
match item.kind { match item.kind {
hir::ItemKind::Trait(.., ref trait_item_refs) => tcx.arena.alloc_from_iter( hir::ItemKind::Trait(.., ref trait_item_refs) => tcx.arena.alloc_from_iter(
trait_item_refs trait_item_refs.iter().map(|trait_item_ref| trait_item_ref.id.def_id.to_def_id()),
.iter()
.map(|trait_item_ref| trait_item_ref.id)
.map(|id| tcx.hir().local_def_id(id.hir_id).to_def_id()),
), ),
hir::ItemKind::Impl(ref impl_) => tcx.arena.alloc_from_iter( hir::ItemKind::Impl(ref impl_) => tcx.arena.alloc_from_iter(
impl_ impl_.items.iter().map(|impl_item_ref| impl_item_ref.id.def_id.to_def_id()),
.items
.iter()
.map(|impl_item_ref| impl_item_ref.id)
.map(|id| tcx.hir().local_def_id(id.hir_id).to_def_id()),
), ),
hir::ItemKind::TraitAlias(..) => &[], hir::ItemKind::TraitAlias(..) => &[],
_ => span_bug!(item.span, "associated_item_def_ids: not impl or trait"), _ => span_bug!(item.span, "associated_item_def_ids: not impl or trait"),

View file

@ -2210,8 +2210,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
self.res_to_ty(opt_self_ty, path, false) self.res_to_ty(opt_self_ty, path, false)
} }
hir::TyKind::OpaqueDef(item_id, ref lifetimes) => { hir::TyKind::OpaqueDef(item_id, ref lifetimes) => {
let opaque_ty = tcx.hir().expect_item(item_id.id); let opaque_ty = tcx.hir().item(item_id);
let def_id = tcx.hir().local_def_id(item_id.id).to_def_id(); let def_id = item_id.def_id.to_def_id();
match opaque_ty.kind { match opaque_ty.kind {
hir::ItemKind::OpaqueTy(hir::OpaqueTy { impl_trait_fn, .. }) => { hir::ItemKind::OpaqueTy(hir::OpaqueTy { impl_trait_fn, .. }) => {

View file

@ -373,8 +373,7 @@ pub(super) fn check_fn<'a, 'tcx>(
(fcx, gen_ty) (fcx, gen_ty)
} }
pub(super) fn check_struct(tcx: TyCtxt<'_>, id: hir::HirId, span: Span) { fn check_struct(tcx: TyCtxt<'_>, def_id: LocalDefId, span: Span) {
let def_id = tcx.hir().local_def_id(id);
let def = tcx.adt_def(def_id); let def = tcx.adt_def(def_id);
def.destructor(tcx); // force the destructor to be evaluated def.destructor(tcx); // force the destructor to be evaluated
check_representable(tcx, span, def_id); check_representable(tcx, span, def_id);
@ -387,8 +386,7 @@ pub(super) fn check_struct(tcx: TyCtxt<'_>, id: hir::HirId, span: Span) {
check_packed(tcx, span, def); check_packed(tcx, span, def);
} }
fn check_union(tcx: TyCtxt<'_>, id: hir::HirId, span: Span) { fn check_union(tcx: TyCtxt<'_>, def_id: LocalDefId, span: Span) {
let def_id = tcx.hir().local_def_id(id);
let def = tcx.adt_def(def_id); let def = tcx.adt_def(def_id);
def.destructor(tcx); // force the destructor to be evaluated def.destructor(tcx); // force the destructor to be evaluated
check_representable(tcx, span, def_id); check_representable(tcx, span, def_id);
@ -683,34 +681,32 @@ fn check_opaque_meets_bounds<'tcx>(
pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) { pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) {
debug!( debug!(
"check_item_type(it.hir_id={}, it.name={})", "check_item_type(it.def_id={:?}, it.name={})",
it.hir_id, it.def_id,
tcx.def_path_str(tcx.hir().local_def_id(it.hir_id).to_def_id()) tcx.def_path_str(it.def_id.to_def_id())
); );
let _indenter = indenter(); let _indenter = indenter();
match it.kind { match it.kind {
// Consts can play a role in type-checking, so they are included here. // Consts can play a role in type-checking, so they are included here.
hir::ItemKind::Static(..) => { hir::ItemKind::Static(..) => {
let def_id = tcx.hir().local_def_id(it.hir_id); tcx.ensure().typeck(it.def_id);
tcx.ensure().typeck(def_id); maybe_check_static_with_link_section(tcx, it.def_id, it.span);
maybe_check_static_with_link_section(tcx, def_id, it.span); check_static_inhabited(tcx, it.def_id, it.span);
check_static_inhabited(tcx, def_id, it.span);
} }
hir::ItemKind::Const(..) => { hir::ItemKind::Const(..) => {
tcx.ensure().typeck(tcx.hir().local_def_id(it.hir_id)); tcx.ensure().typeck(it.def_id);
} }
hir::ItemKind::Enum(ref enum_definition, _) => { hir::ItemKind::Enum(ref enum_definition, _) => {
check_enum(tcx, it.span, &enum_definition.variants, it.hir_id); check_enum(tcx, it.span, &enum_definition.variants, it.def_id);
} }
hir::ItemKind::Fn(..) => {} // entirely within check_item_body hir::ItemKind::Fn(..) => {} // entirely within check_item_body
hir::ItemKind::Impl(ref impl_) => { hir::ItemKind::Impl(ref impl_) => {
debug!("ItemKind::Impl {} with id {}", it.ident, it.hir_id); debug!("ItemKind::Impl {} with id {:?}", it.ident, it.def_id);
let impl_def_id = tcx.hir().local_def_id(it.hir_id); if let Some(impl_trait_ref) = tcx.impl_trait_ref(it.def_id) {
if let Some(impl_trait_ref) = tcx.impl_trait_ref(impl_def_id) {
check_impl_items_against_trait( check_impl_items_against_trait(
tcx, tcx,
it.span, it.span,
impl_def_id, it.def_id,
impl_trait_ref, impl_trait_ref,
&impl_.items, &impl_.items,
); );
@ -719,8 +715,7 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) {
} }
} }
hir::ItemKind::Trait(_, _, _, _, ref items) => { hir::ItemKind::Trait(_, _, _, _, ref items) => {
let def_id = tcx.hir().local_def_id(it.hir_id); check_on_unimplemented(tcx, it.def_id.to_def_id(), it);
check_on_unimplemented(tcx, def_id.to_def_id(), it);
for item in items.iter() { for item in items.iter() {
let item = tcx.hir().trait_item(item.id); let item = tcx.hir().trait_item(item.id);
@ -730,16 +725,15 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) {
fn_maybe_err(tcx, item.ident.span, abi); fn_maybe_err(tcx, item.ident.span, abi);
} }
hir::TraitItemKind::Type(.., Some(_default)) => { hir::TraitItemKind::Type(.., Some(_default)) => {
let item_def_id = tcx.hir().local_def_id(item.hir_id).to_def_id(); let assoc_item = tcx.associated_item(item.def_id);
let assoc_item = tcx.associated_item(item_def_id);
let trait_substs = let trait_substs =
InternalSubsts::identity_for_item(tcx, def_id.to_def_id()); InternalSubsts::identity_for_item(tcx, it.def_id.to_def_id());
let _: Result<_, rustc_errors::ErrorReported> = check_type_bounds( let _: Result<_, rustc_errors::ErrorReported> = check_type_bounds(
tcx, tcx,
assoc_item, assoc_item,
assoc_item, assoc_item,
item.span, item.span,
ty::TraitRef { def_id: def_id.to_def_id(), substs: trait_substs }, ty::TraitRef { def_id: it.def_id.to_def_id(), substs: trait_substs },
); );
} }
_ => {} _ => {}
@ -747,10 +741,10 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) {
} }
} }
hir::ItemKind::Struct(..) => { hir::ItemKind::Struct(..) => {
check_struct(tcx, it.hir_id, it.span); check_struct(tcx, it.def_id, it.span);
} }
hir::ItemKind::Union(..) => { hir::ItemKind::Union(..) => {
check_union(tcx, it.hir_id, it.span); check_union(tcx, it.def_id, it.span);
} }
hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) => { hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) => {
// HACK(jynelson): trying to infer the type of `impl trait` breaks documenting // HACK(jynelson): trying to infer the type of `impl trait` breaks documenting
@ -758,16 +752,13 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) {
// Since rustdoc doesn't care about the concrete type behind `impl Trait`, just don't look at it! // Since rustdoc doesn't care about the concrete type behind `impl Trait`, just don't look at it!
// See https://github.com/rust-lang/rust/issues/75100 // See https://github.com/rust-lang/rust/issues/75100
if !tcx.sess.opts.actually_rustdoc { if !tcx.sess.opts.actually_rustdoc {
let def_id = tcx.hir().local_def_id(it.hir_id); let substs = InternalSubsts::identity_for_item(tcx, it.def_id.to_def_id());
check_opaque(tcx, it.def_id, substs, it.span, &origin);
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
check_opaque(tcx, def_id, substs, it.span, &origin);
} }
} }
hir::ItemKind::TyAlias(..) => { hir::ItemKind::TyAlias(..) => {
let def_id = tcx.hir().local_def_id(it.hir_id); let pty_ty = tcx.type_of(it.def_id);
let pty_ty = tcx.type_of(def_id); let generics = tcx.generics_of(it.def_id);
let generics = tcx.generics_of(def_id);
check_type_params_are_used(tcx, &generics, pty_ty); check_type_params_are_used(tcx, &generics, pty_ty);
} }
hir::ItemKind::ForeignMod { abi, items } => { hir::ItemKind::ForeignMod { abi, items } => {
@ -785,7 +776,7 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) {
} }
} else { } else {
for item in items { for item in items {
let def_id = tcx.hir().local_def_id(item.id.hir_id); let def_id = item.id.def_id;
let generics = tcx.generics_of(def_id); let generics = tcx.generics_of(def_id);
let own_counts = generics.own_counts(); let own_counts = generics.own_counts();
if generics.params.len() - own_counts.lifetimes != 0 { if generics.params.len() - own_counts.lifetimes != 0 {
@ -835,9 +826,8 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) {
} }
pub(super) fn check_on_unimplemented(tcx: TyCtxt<'_>, trait_def_id: DefId, item: &hir::Item<'_>) { pub(super) fn check_on_unimplemented(tcx: TyCtxt<'_>, trait_def_id: DefId, item: &hir::Item<'_>) {
let item_def_id = tcx.hir().local_def_id(item.hir_id);
// an error would be reported if this fails. // an error would be reported if this fails.
let _ = traits::OnUnimplementedDirective::of_item(tcx, trait_def_id, item_def_id.to_def_id()); let _ = traits::OnUnimplementedDirective::of_item(tcx, trait_def_id, item.def_id.to_def_id());
} }
pub(super) fn check_specialization_validity<'tcx>( pub(super) fn check_specialization_validity<'tcx>(
@ -938,7 +928,7 @@ pub(super) fn check_impl_items_against_trait<'tcx>(
// Check existing impl methods to see if they are both present in trait // Check existing impl methods to see if they are both present in trait
// and compatible with trait signature // and compatible with trait signature
for impl_item in impl_items { for impl_item in impl_items {
let ty_impl_item = tcx.associated_item(tcx.hir().local_def_id(impl_item.hir_id)); let ty_impl_item = tcx.associated_item(impl_item.def_id);
let mut items = let mut items =
associated_items.filter_by_name(tcx, ty_impl_item.ident, impl_trait_ref.def_id); associated_items.filter_by_name(tcx, ty_impl_item.ident, impl_trait_ref.def_id);
@ -1345,13 +1335,12 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, sp: Span, adt: &'tcx ty
} }
#[allow(trivial_numeric_casts)] #[allow(trivial_numeric_casts)]
pub fn check_enum<'tcx>( fn check_enum<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
sp: Span, sp: Span,
vs: &'tcx [hir::Variant<'tcx>], vs: &'tcx [hir::Variant<'tcx>],
id: hir::HirId, def_id: LocalDefId,
) { ) {
let def_id = tcx.hir().local_def_id(id);
let def = tcx.adt_def(def_id); let def = tcx.adt_def(def_id);
def.destructor(tcx); // force the destructor to be evaluated def.destructor(tcx); // force the destructor to be evaluated

View file

@ -823,11 +823,11 @@ fn compare_synthetic_generics<'tcx>(
// FIXME: this is obviously suboptimal since the name can already be used // FIXME: this is obviously suboptimal since the name can already be used
// as another generic argument // as another generic argument
let new_name = tcx.sess.source_map().span_to_snippet(trait_span).ok()?; let new_name = tcx.sess.source_map().span_to_snippet(trait_span).ok()?;
let trait_m = tcx.hir().local_def_id_to_hir_id(trait_m.def_id.as_local()?); let trait_m = trait_m.def_id.as_local()?;
let trait_m = tcx.hir().trait_item(hir::TraitItemId { hir_id: trait_m }); let trait_m = tcx.hir().trait_item(hir::TraitItemId { def_id: trait_m });
let impl_m = tcx.hir().local_def_id_to_hir_id(impl_m.def_id.as_local()?); let impl_m = impl_m.def_id.as_local()?;
let impl_m = tcx.hir().impl_item(hir::ImplItemId { hir_id: impl_m }); let impl_m = tcx.hir().impl_item(hir::ImplItemId { def_id: impl_m });
// in case there are no generics, take the spot between the function name // in case there are no generics, take the spot between the function name
// and the opening paren of the argument list // and the opening paren of the argument list
@ -860,8 +860,8 @@ fn compare_synthetic_generics<'tcx>(
(None, Some(hir::SyntheticTyParamKind::ImplTrait)) => { (None, Some(hir::SyntheticTyParamKind::ImplTrait)) => {
err.span_label(impl_span, "expected `impl Trait`, found generic parameter"); err.span_label(impl_span, "expected `impl Trait`, found generic parameter");
(|| { (|| {
let impl_m = tcx.hir().local_def_id_to_hir_id(impl_m.def_id.as_local()?); let impl_m = impl_m.def_id.as_local()?;
let impl_m = tcx.hir().impl_item(hir::ImplItemId { hir_id: impl_m }); let impl_m = tcx.hir().impl_item(hir::ImplItemId { def_id: impl_m });
let input_tys = match impl_m.kind { let input_tys = match impl_m.kind {
hir::ImplItemKind::Fn(ref sig, _) => sig.decl.inputs, hir::ImplItemKind::Fn(ref sig, _) => sig.decl.inputs,
_ => unreachable!(), _ => unreachable!(),

View file

@ -9,7 +9,6 @@ use crate::require_same_types;
use rustc_errors::struct_span_err; use rustc_errors::struct_span_err;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_middle::traits::{ObligationCause, ObligationCauseCode}; use rustc_middle::traits::{ObligationCause, ObligationCauseCode};
use rustc_middle::ty::subst::Subst; use rustc_middle::ty::subst::Subst;
use rustc_middle::ty::{self, TyCtxt}; use rustc_middle::ty::{self, TyCtxt};
@ -21,7 +20,6 @@ use std::iter;
fn equate_intrinsic_type<'tcx>( fn equate_intrinsic_type<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
it: &hir::ForeignItem<'_>, it: &hir::ForeignItem<'_>,
def_id: DefId,
n_tps: usize, n_tps: usize,
sig: ty::PolyFnSig<'tcx>, sig: ty::PolyFnSig<'tcx>,
) { ) {
@ -35,7 +33,7 @@ fn equate_intrinsic_type<'tcx>(
} }
} }
let i_n_tps = tcx.generics_of(def_id).own_counts().types; let i_n_tps = tcx.generics_of(it.def_id).own_counts().types;
if i_n_tps != n_tps { if i_n_tps != n_tps {
let span = match it.kind { let span = match it.kind {
hir::ForeignItemKind::Fn(_, _, ref generics) => generics.span, hir::ForeignItemKind::Fn(_, _, ref generics) => generics.span,
@ -51,8 +49,8 @@ fn equate_intrinsic_type<'tcx>(
} }
let fty = tcx.mk_fn_ptr(sig); let fty = tcx.mk_fn_ptr(sig);
let cause = ObligationCause::new(it.span, it.hir_id, ObligationCauseCode::IntrinsicType); let cause = ObligationCause::new(it.span, it.hir_id(), ObligationCauseCode::IntrinsicType);
require_same_types(tcx, &cause, tcx.mk_fn_ptr(tcx.fn_sig(def_id)), fty); require_same_types(tcx, &cause, tcx.mk_fn_ptr(tcx.fn_sig(it.def_id)), fty);
} }
/// Returns `true` if the given intrinsic is unsafe to call or not. /// Returns `true` if the given intrinsic is unsafe to call or not.
@ -100,8 +98,7 @@ pub fn intrinsic_operation_unsafety(intrinsic: Symbol) -> hir::Unsafety {
/// and in `library/core/src/intrinsics.rs`. /// and in `library/core/src/intrinsics.rs`.
pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) { pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
let param = |n| tcx.mk_ty_param(n, Symbol::intern(&format!("P{}", n))); let param = |n| tcx.mk_ty_param(n, Symbol::intern(&format!("P{}", n)));
let def_id = tcx.hir().local_def_id(it.hir_id).to_def_id(); let intrinsic_name = tcx.item_name(it.def_id.to_def_id());
let intrinsic_name = tcx.item_name(def_id);
let name_str = intrinsic_name.as_str(); let name_str = intrinsic_name.as_str();
let mk_va_list_ty = |mutbl| { let mk_va_list_ty = |mutbl| {
@ -370,7 +367,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
}; };
let sig = tcx.mk_fn_sig(inputs.into_iter(), output, false, unsafety, Abi::RustIntrinsic); let sig = tcx.mk_fn_sig(inputs.into_iter(), output, false, unsafety, Abi::RustIntrinsic);
let sig = ty::Binder::bind(sig); let sig = ty::Binder::bind(sig);
equate_intrinsic_type(tcx, it, def_id, n_tps, sig) equate_intrinsic_type(tcx, it, n_tps, sig)
} }
/// Type-check `extern "platform-intrinsic" { ... }` functions. /// Type-check `extern "platform-intrinsic" { ... }` functions.
@ -380,7 +377,6 @@ pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>)
tcx.mk_ty_param(n, name) tcx.mk_ty_param(n, name)
}; };
let def_id = tcx.hir().local_def_id(it.hir_id).to_def_id();
let name = it.ident.name; let name = it.ident.name;
let (n_tps, inputs, output) = match name { let (n_tps, inputs, output) = match name {
@ -464,5 +460,5 @@ pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>)
Abi::PlatformIntrinsic, Abi::PlatformIntrinsic,
); );
let sig = ty::Binder::dummy(sig); let sig = ty::Binder::dummy(sig);
equate_intrinsic_type(tcx, it, def_id, n_tps, sig) equate_intrinsic_type(tcx, it, n_tps, sig)
} }

View file

@ -11,7 +11,6 @@ use rustc_hir::intravisit;
use rustc_hir::lang_items::LangItem; use rustc_hir::lang_items::LangItem;
use rustc_hir::{ExprKind, Node, QPath}; use rustc_hir::{ExprKind, Node, QPath};
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use rustc_middle::hir::map as hir_map;
use rustc_middle::ty::fast_reject::simplify_type; use rustc_middle::ty::fast_reject::simplify_type;
use rustc_middle::ty::print::with_crate_prefix; use rustc_middle::ty::print::with_crate_prefix;
use rustc_middle::ty::{ use rustc_middle::ty::{
@ -1352,17 +1351,15 @@ fn compute_all_traits(tcx: TyCtxt<'_>) -> Vec<DefId> {
// Crate-local: // Crate-local:
struct Visitor<'a, 'tcx> { struct Visitor<'a> {
map: &'a hir_map::Map<'tcx>,
traits: &'a mut Vec<DefId>, traits: &'a mut Vec<DefId>,
} }
impl<'v, 'a, 'tcx> itemlikevisit::ItemLikeVisitor<'v> for Visitor<'a, 'tcx> { impl<'v, 'a> itemlikevisit::ItemLikeVisitor<'v> for Visitor<'a> {
fn visit_item(&mut self, i: &'v hir::Item<'v>) { fn visit_item(&mut self, i: &'v hir::Item<'v>) {
match i.kind { match i.kind {
hir::ItemKind::Trait(..) | hir::ItemKind::TraitAlias(..) => { hir::ItemKind::Trait(..) | hir::ItemKind::TraitAlias(..) => {
let def_id = self.map.local_def_id(i.hir_id); self.traits.push(i.def_id.to_def_id());
self.traits.push(def_id.to_def_id());
} }
_ => (), _ => (),
} }
@ -1375,7 +1372,7 @@ fn compute_all_traits(tcx: TyCtxt<'_>) -> Vec<DefId> {
fn visit_foreign_item(&mut self, _foreign_item: &hir::ForeignItem<'_>) {} fn visit_foreign_item(&mut self, _foreign_item: &hir::ForeignItem<'_>) {}
} }
tcx.hir().krate().visit_all_item_likes(&mut Visitor { map: &tcx.hir(), traits: &mut traits }); tcx.hir().krate().visit_all_item_likes(&mut Visitor { traits: &mut traits });
// Cross-crate: // Cross-crate:
@ -1445,8 +1442,8 @@ impl intravisit::Visitor<'tcx> for UsePlacementFinder<'tcx> {
return; return;
} }
// Find a `use` statement. // Find a `use` statement.
for item_id in module.item_ids { for &item_id in module.item_ids {
let item = self.tcx.hir().expect_item(item_id.id); let item = self.tcx.hir().item(item_id);
match item.kind { match item.kind {
hir::ItemKind::Use(..) => { hir::ItemKind::Use(..) => {
// Don't suggest placing a `use` before the prelude // Don't suggest placing a `use` before the prelude

View file

@ -80,8 +80,8 @@ pub fn check_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) {
let item = tcx.hir().expect_item(hir_id); let item = tcx.hir().expect_item(hir_id);
debug!( debug!(
"check_item_well_formed(it.hir_id={:?}, it.name={})", "check_item_well_formed(it.def_id={:?}, it.name={})",
item.hir_id, item.def_id,
tcx.def_path_str(def_id.to_def_id()) tcx.def_path_str(def_id.to_def_id())
); );
@ -105,7 +105,7 @@ pub fn check_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) {
// for `T` // for `T`
hir::ItemKind::Impl(ref impl_) => { hir::ItemKind::Impl(ref impl_) => {
let is_auto = tcx let is_auto = tcx
.impl_trait_ref(tcx.hir().local_def_id(item.hir_id)) .impl_trait_ref(item.def_id)
.map_or(false, |trait_ref| tcx.trait_is_auto(trait_ref.def_id)); .map_or(false, |trait_ref| tcx.trait_is_auto(trait_ref.def_id));
if let (hir::Defaultness::Default { .. }, true) = (impl_.defaultness, is_auto) { if let (hir::Defaultness::Default { .. }, true) = (impl_.defaultness, is_auto) {
let sp = impl_.of_trait.as_ref().map_or(item.span, |t| t.path.span); let sp = impl_.of_trait.as_ref().map_or(item.span, |t| t.path.span);
@ -141,23 +141,23 @@ pub fn check_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) {
} }
} }
hir::ItemKind::Fn(ref sig, ..) => { hir::ItemKind::Fn(ref sig, ..) => {
check_item_fn(tcx, item.hir_id, item.ident, item.span, sig.decl); check_item_fn(tcx, item.hir_id(), item.ident, item.span, sig.decl);
} }
hir::ItemKind::Static(ref ty, ..) => { hir::ItemKind::Static(ref ty, ..) => {
check_item_type(tcx, item.hir_id, ty.span, false); check_item_type(tcx, item.hir_id(), ty.span, false);
} }
hir::ItemKind::Const(ref ty, ..) => { hir::ItemKind::Const(ref ty, ..) => {
check_item_type(tcx, item.hir_id, ty.span, false); check_item_type(tcx, item.hir_id(), ty.span, false);
} }
hir::ItemKind::ForeignMod { items, .. } => { hir::ItemKind::ForeignMod { items, .. } => {
for it in items.iter() { for it in items.iter() {
let it = tcx.hir().foreign_item(it.id); let it = tcx.hir().foreign_item(it.id);
match it.kind { match it.kind {
hir::ForeignItemKind::Fn(ref decl, ..) => { hir::ForeignItemKind::Fn(ref decl, ..) => {
check_item_fn(tcx, it.hir_id, it.ident, it.span, decl) check_item_fn(tcx, it.hir_id(), it.ident, it.span, decl)
} }
hir::ForeignItemKind::Static(ref ty, ..) => { hir::ForeignItemKind::Static(ref ty, ..) => {
check_item_type(tcx, it.hir_id, ty.span, true) check_item_type(tcx, it.hir_id(), ty.span, true)
} }
hir::ForeignItemKind::Type => (), hir::ForeignItemKind::Type => (),
} }
@ -197,7 +197,7 @@ pub fn check_trait_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
_ => None, _ => None,
}; };
check_object_unsafe_self_trait_by_name(tcx, &trait_item); check_object_unsafe_self_trait_by_name(tcx, &trait_item);
check_associated_item(tcx, trait_item.hir_id, trait_item.span, method_sig); check_associated_item(tcx, trait_item.hir_id(), trait_item.span, method_sig);
} }
fn could_be_self(trait_def_id: LocalDefId, ty: &hir::Ty<'_>) -> bool { fn could_be_self(trait_def_id: LocalDefId, ty: &hir::Ty<'_>) -> bool {
@ -213,9 +213,9 @@ fn could_be_self(trait_def_id: LocalDefId, ty: &hir::Ty<'_>) -> bool {
/// Detect when an object unsafe trait is referring to itself in one of its associated items. /// Detect when an object unsafe trait is referring to itself in one of its associated items.
/// When this is done, suggest using `Self` instead. /// When this is done, suggest using `Self` instead.
fn check_object_unsafe_self_trait_by_name(tcx: TyCtxt<'_>, item: &hir::TraitItem<'_>) { fn check_object_unsafe_self_trait_by_name(tcx: TyCtxt<'_>, item: &hir::TraitItem<'_>) {
let (trait_name, trait_def_id) = match tcx.hir().get(tcx.hir().get_parent_item(item.hir_id)) { let (trait_name, trait_def_id) = match tcx.hir().get(tcx.hir().get_parent_item(item.hir_id())) {
hir::Node::Item(item) => match item.kind { hir::Node::Item(item) => match item.kind {
hir::ItemKind::Trait(..) => (item.ident, tcx.hir().local_def_id(item.hir_id)), hir::ItemKind::Trait(..) => (item.ident, item.def_id),
_ => return, _ => return,
}, },
_ => return, _ => return,
@ -271,7 +271,7 @@ pub fn check_impl_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
_ => None, _ => None,
}; };
check_associated_item(tcx, impl_item.hir_id, impl_item.span, method_sig); check_associated_item(tcx, impl_item.hir_id(), impl_item.span, method_sig);
} }
fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) { fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) {
@ -432,7 +432,7 @@ fn check_associated_item(
} }
fn for_item<'tcx>(tcx: TyCtxt<'tcx>, item: &hir::Item<'_>) -> CheckWfFcxBuilder<'tcx> { fn for_item<'tcx>(tcx: TyCtxt<'tcx>, item: &hir::Item<'_>) -> CheckWfFcxBuilder<'tcx> {
for_id(tcx, item.hir_id, item.span) for_id(tcx, item.hir_id(), item.span)
} }
fn for_id(tcx: TyCtxt<'_>, id: hir::HirId, span: Span) -> CheckWfFcxBuilder<'_> { fn for_id(tcx: TyCtxt<'_>, id: hir::HirId, span: Span) -> CheckWfFcxBuilder<'_> {
@ -465,8 +465,7 @@ fn check_type_defn<'tcx, F>(
{ {
for_item(tcx, item).with_fcx(|fcx, fcx_tcx| { for_item(tcx, item).with_fcx(|fcx, fcx_tcx| {
let variants = lookup_fields(fcx); let variants = lookup_fields(fcx);
let def_id = fcx.tcx.hir().local_def_id(item.hir_id); let packed = fcx.tcx.adt_def(item.def_id).repr.packed();
let packed = fcx.tcx.adt_def(def_id).repr.packed();
for variant in &variants { for variant in &variants {
// For DST, or when drop needs to copy things around, all // For DST, or when drop needs to copy things around, all
@ -482,7 +481,7 @@ fn check_type_defn<'tcx, F>(
// Just treat unresolved type expression as if it needs drop. // Just treat unresolved type expression as if it needs drop.
true true
} else { } else {
ty.needs_drop(fcx_tcx, fcx_tcx.param_env(def_id)) ty.needs_drop(fcx_tcx, fcx_tcx.param_env(item.def_id))
} }
} }
}; };
@ -541,7 +540,7 @@ fn check_type_defn<'tcx, F>(
} }
} }
check_where_clauses(tcx, fcx, item.span, def_id.to_def_id(), None); check_where_clauses(tcx, fcx, item.span, item.def_id.to_def_id(), None);
// No implied bounds in a struct definition. // No implied bounds in a struct definition.
vec![] vec![]
@ -549,15 +548,13 @@ fn check_type_defn<'tcx, F>(
} }
fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item<'_>) { fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item<'_>) {
debug!("check_trait: {:?}", item.hir_id); debug!("check_trait: {:?}", item.def_id);
let trait_def_id = tcx.hir().local_def_id(item.hir_id); let trait_def = tcx.trait_def(item.def_id);
let trait_def = tcx.trait_def(trait_def_id);
if trait_def.is_marker if trait_def.is_marker
|| matches!(trait_def.specialization_kind, TraitSpecializationKind::Marker) || matches!(trait_def.specialization_kind, TraitSpecializationKind::Marker)
{ {
for associated_def_id in &*tcx.associated_item_def_ids(trait_def_id) { for associated_def_id in &*tcx.associated_item_def_ids(item.def_id) {
struct_span_err!( struct_span_err!(
tcx.sess, tcx.sess,
tcx.def_span(*associated_def_id), tcx.def_span(*associated_def_id),
@ -569,7 +566,7 @@ fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item<'_>) {
} }
for_item(tcx, item).with_fcx(|fcx, _| { for_item(tcx, item).with_fcx(|fcx, _| {
check_where_clauses(tcx, fcx, item.span, trait_def_id.to_def_id(), None); check_where_clauses(tcx, fcx, item.span, item.def_id.to_def_id(), None);
vec![] vec![]
}); });
@ -665,14 +662,12 @@ fn check_impl<'tcx>(
debug!("check_impl: {:?}", item); debug!("check_impl: {:?}", item);
for_item(tcx, item).with_fcx(|fcx, tcx| { for_item(tcx, item).with_fcx(|fcx, tcx| {
let item_def_id = fcx.tcx.hir().local_def_id(item.hir_id);
match *ast_trait_ref { match *ast_trait_ref {
Some(ref ast_trait_ref) => { Some(ref ast_trait_ref) => {
// `#[rustc_reservation_impl]` impls are not real impls and // `#[rustc_reservation_impl]` impls are not real impls and
// therefore don't need to be WF (the trait's `Self: Trait` predicate // therefore don't need to be WF (the trait's `Self: Trait` predicate
// won't hold). // won't hold).
let trait_ref = fcx.tcx.impl_trait_ref(item_def_id).unwrap(); let trait_ref = fcx.tcx.impl_trait_ref(item.def_id).unwrap();
let trait_ref = let trait_ref =
fcx.normalize_associated_types_in(ast_trait_ref.path.span, trait_ref); fcx.normalize_associated_types_in(ast_trait_ref.path.span, trait_ref);
let obligations = traits::wf::trait_obligations( let obligations = traits::wf::trait_obligations(
@ -688,7 +683,7 @@ fn check_impl<'tcx>(
} }
} }
None => { None => {
let self_ty = fcx.tcx.type_of(item_def_id); let self_ty = fcx.tcx.type_of(item.def_id);
let self_ty = fcx.normalize_associated_types_in(item.span, self_ty); let self_ty = fcx.normalize_associated_types_in(item.span, self_ty);
fcx.register_wf_obligation( fcx.register_wf_obligation(
self_ty.into(), self_ty.into(),
@ -698,9 +693,9 @@ fn check_impl<'tcx>(
} }
} }
check_where_clauses(tcx, fcx, item.span, item_def_id.to_def_id(), None); check_where_clauses(tcx, fcx, item.span, item.def_id.to_def_id(), None);
fcx.impl_implied_bounds(item_def_id.to_def_id(), item.span) fcx.impl_implied_bounds(item.def_id.to_def_id(), item.span)
}); });
} }
@ -1238,15 +1233,14 @@ fn check_variances_for_type_defn<'tcx>(
item: &hir::Item<'tcx>, item: &hir::Item<'tcx>,
hir_generics: &hir::Generics<'_>, hir_generics: &hir::Generics<'_>,
) { ) {
let item_def_id = tcx.hir().local_def_id(item.hir_id); let ty = tcx.type_of(item.def_id);
let ty = tcx.type_of(item_def_id);
if tcx.has_error_field(ty) { if tcx.has_error_field(ty) {
return; return;
} }
let ty_predicates = tcx.predicates_of(item_def_id); let ty_predicates = tcx.predicates_of(item.def_id);
assert_eq!(ty_predicates.parent, None); assert_eq!(ty_predicates.parent, None);
let variances = tcx.variances_of(item_def_id); let variances = tcx.variances_of(item.def_id);
let mut constrained_parameters: FxHashSet<_> = variances let mut constrained_parameters: FxHashSet<_> = variances
.iter() .iter()
@ -1354,22 +1348,19 @@ impl Visitor<'tcx> for CheckTypeWellFormedVisitor<'tcx> {
fn visit_item(&mut self, i: &'tcx hir::Item<'tcx>) { fn visit_item(&mut self, i: &'tcx hir::Item<'tcx>) {
debug!("visit_item: {:?}", i); debug!("visit_item: {:?}", i);
let def_id = self.tcx.hir().local_def_id(i.hir_id); self.tcx.ensure().check_item_well_formed(i.def_id);
self.tcx.ensure().check_item_well_formed(def_id);
hir_visit::walk_item(self, i); hir_visit::walk_item(self, i);
} }
fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) { fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) {
debug!("visit_trait_item: {:?}", trait_item); debug!("visit_trait_item: {:?}", trait_item);
let def_id = self.tcx.hir().local_def_id(trait_item.hir_id); self.tcx.ensure().check_trait_item_well_formed(trait_item.def_id);
self.tcx.ensure().check_trait_item_well_formed(def_id);
hir_visit::walk_trait_item(self, trait_item); hir_visit::walk_trait_item(self, trait_item);
} }
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) { fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
debug!("visit_impl_item: {:?}", impl_item); debug!("visit_impl_item: {:?}", impl_item);
let def_id = self.tcx.hir().local_def_id(impl_item.hir_id); self.tcx.ensure().check_impl_item_well_formed(impl_item.def_id);
self.tcx.ensure().check_impl_item_well_formed(def_id);
hir_visit::walk_impl_item(self, impl_item); hir_visit::walk_impl_item(self, impl_item);
} }

View file

@ -28,7 +28,7 @@ impl ItemLikeVisitor<'v> for CheckVisitor<'tcx> {
return; return;
} }
if let hir::ItemKind::Use(ref path, _) = item.kind { if let hir::ItemKind::Use(ref path, _) = item.kind {
self.check_import(item.hir_id, path.span); self.check_import(item.item_id(), path.span);
} }
} }
@ -45,24 +45,28 @@ struct CheckVisitor<'tcx> {
} }
impl CheckVisitor<'tcx> { impl CheckVisitor<'tcx> {
fn check_import(&self, id: hir::HirId, span: Span) { fn check_import(&self, item_id: hir::ItemId, span: Span) {
let def_id = self.tcx.hir().local_def_id(id); if !self.tcx.maybe_unused_trait_import(item_id.def_id) {
if !self.tcx.maybe_unused_trait_import(def_id) {
return; return;
} }
if self.used_trait_imports.contains(&def_id) { if self.used_trait_imports.contains(&item_id.def_id) {
return; return;
} }
self.tcx.struct_span_lint_hir(lint::builtin::UNUSED_IMPORTS, id, span, |lint| { self.tcx.struct_span_lint_hir(
let msg = if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) { lint::builtin::UNUSED_IMPORTS,
format!("unused import: `{}`", snippet) item_id.hir_id(),
} else { span,
"unused import".to_owned() |lint| {
}; let msg = if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
lint.build(&msg).emit(); format!("unused import: `{}`", snippet)
}); } else {
"unused import".to_owned()
};
lint.build(&msg).emit();
},
);
} }
} }
@ -109,7 +113,6 @@ fn unused_crates_lint(tcx: TyCtxt<'_>) {
// Collect all the extern crates (in a reliable order). // Collect all the extern crates (in a reliable order).
let mut crates_to_lint = vec![]; let mut crates_to_lint = vec![];
tcx.hir().krate().visit_all_item_likes(&mut CollectExternCrateVisitor { tcx.hir().krate().visit_all_item_likes(&mut CollectExternCrateVisitor {
tcx,
crates_to_lint: &mut crates_to_lint, crates_to_lint: &mut crates_to_lint,
}); });
@ -189,8 +192,7 @@ fn unused_crates_lint(tcx: TyCtxt<'_>) {
} }
} }
struct CollectExternCrateVisitor<'a, 'tcx> { struct CollectExternCrateVisitor<'a> {
tcx: TyCtxt<'tcx>,
crates_to_lint: &'a mut Vec<ExternCrateToLint>, crates_to_lint: &'a mut Vec<ExternCrateToLint>,
} }
@ -211,12 +213,11 @@ struct ExternCrateToLint {
warn_if_unused: bool, warn_if_unused: bool,
} }
impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for CollectExternCrateVisitor<'a, 'tcx> { impl<'a, 'v> ItemLikeVisitor<'v> for CollectExternCrateVisitor<'a> {
fn visit_item(&mut self, item: &hir::Item<'_>) { fn visit_item(&mut self, item: &hir::Item<'_>) {
if let hir::ItemKind::ExternCrate(orig_name) = item.kind { if let hir::ItemKind::ExternCrate(orig_name) = item.kind {
let extern_crate_def_id = self.tcx.hir().local_def_id(item.hir_id);
self.crates_to_lint.push(ExternCrateToLint { self.crates_to_lint.push(ExternCrateToLint {
def_id: extern_crate_def_id.to_def_id(), def_id: item.def_id.to_def_id(),
span: item.span, span: item.span,
orig_name, orig_name,
warn_if_unused: !item.ident.as_str().starts_with('_'), warn_if_unused: !item.ident.as_str().starts_with('_'),

View file

@ -38,8 +38,7 @@ impl<'tcx> Checker<'tcx> {
F: FnMut(TyCtxt<'tcx>, LocalDefId), F: FnMut(TyCtxt<'tcx>, LocalDefId),
{ {
if Some(self.trait_def_id) == trait_def_id { if Some(self.trait_def_id) == trait_def_id {
for &impl_id in self.tcx.hir().trait_impls(self.trait_def_id) { for &impl_def_id in self.tcx.hir().trait_impls(self.trait_def_id) {
let impl_def_id = self.tcx.hir().local_def_id(impl_id);
f(self.tcx, impl_def_id); f(self.tcx, impl_def_id);
} }
} }

View file

@ -50,8 +50,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
_ => return, _ => return,
}; };
let def_id = self.tcx.hir().local_def_id(item.hir_id); let self_ty = self.tcx.type_of(item.def_id);
let self_ty = self.tcx.type_of(def_id);
let lang_items = self.tcx.lang_items(); let lang_items = self.tcx.lang_items();
match *self_ty.kind() { match *self_ty.kind() {
ty::Adt(def, _) => { ty::Adt(def, _) => {
@ -65,7 +64,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
} }
ty::Bool => { ty::Bool => {
self.check_primitive_impl( self.check_primitive_impl(
def_id, item.def_id,
lang_items.bool_impl(), lang_items.bool_impl(),
None, None,
"bool", "bool",
@ -76,7 +75,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
} }
ty::Char => { ty::Char => {
self.check_primitive_impl( self.check_primitive_impl(
def_id, item.def_id,
lang_items.char_impl(), lang_items.char_impl(),
None, None,
"char", "char",
@ -87,7 +86,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
} }
ty::Str => { ty::Str => {
self.check_primitive_impl( self.check_primitive_impl(
def_id, item.def_id,
lang_items.str_impl(), lang_items.str_impl(),
lang_items.str_alloc_impl(), lang_items.str_alloc_impl(),
"str", "str",
@ -98,7 +97,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
} }
ty::Slice(slice_item) if slice_item == self.tcx.types.u8 => { ty::Slice(slice_item) if slice_item == self.tcx.types.u8 => {
self.check_primitive_impl( self.check_primitive_impl(
def_id, item.def_id,
lang_items.slice_u8_impl(), lang_items.slice_u8_impl(),
lang_items.slice_u8_alloc_impl(), lang_items.slice_u8_alloc_impl(),
"slice_u8", "slice_u8",
@ -109,7 +108,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
} }
ty::Slice(_) => { ty::Slice(_) => {
self.check_primitive_impl( self.check_primitive_impl(
def_id, item.def_id,
lang_items.slice_impl(), lang_items.slice_impl(),
lang_items.slice_alloc_impl(), lang_items.slice_alloc_impl(),
"slice", "slice",
@ -120,7 +119,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
} }
ty::Array(_, _) => { ty::Array(_, _) => {
self.check_primitive_impl( self.check_primitive_impl(
def_id, item.def_id,
lang_items.array_impl(), lang_items.array_impl(),
None, None,
"array", "array",
@ -133,7 +132,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
if matches!(inner.kind(), ty::Slice(_)) => if matches!(inner.kind(), ty::Slice(_)) =>
{ {
self.check_primitive_impl( self.check_primitive_impl(
def_id, item.def_id,
lang_items.const_slice_ptr_impl(), lang_items.const_slice_ptr_impl(),
None, None,
"const_slice_ptr", "const_slice_ptr",
@ -146,7 +145,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
if matches!(inner.kind(), ty::Slice(_)) => if matches!(inner.kind(), ty::Slice(_)) =>
{ {
self.check_primitive_impl( self.check_primitive_impl(
def_id, item.def_id,
lang_items.mut_slice_ptr_impl(), lang_items.mut_slice_ptr_impl(),
None, None,
"mut_slice_ptr", "mut_slice_ptr",
@ -157,7 +156,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
} }
ty::RawPtr(ty::TypeAndMut { ty: _, mutbl: hir::Mutability::Not }) => { ty::RawPtr(ty::TypeAndMut { ty: _, mutbl: hir::Mutability::Not }) => {
self.check_primitive_impl( self.check_primitive_impl(
def_id, item.def_id,
lang_items.const_ptr_impl(), lang_items.const_ptr_impl(),
None, None,
"const_ptr", "const_ptr",
@ -168,7 +167,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
} }
ty::RawPtr(ty::TypeAndMut { ty: _, mutbl: hir::Mutability::Mut }) => { ty::RawPtr(ty::TypeAndMut { ty: _, mutbl: hir::Mutability::Mut }) => {
self.check_primitive_impl( self.check_primitive_impl(
def_id, item.def_id,
lang_items.mut_ptr_impl(), lang_items.mut_ptr_impl(),
None, None,
"mut_ptr", "mut_ptr",
@ -179,7 +178,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
} }
ty::Int(ty::IntTy::I8) => { ty::Int(ty::IntTy::I8) => {
self.check_primitive_impl( self.check_primitive_impl(
def_id, item.def_id,
lang_items.i8_impl(), lang_items.i8_impl(),
None, None,
"i8", "i8",
@ -190,7 +189,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
} }
ty::Int(ty::IntTy::I16) => { ty::Int(ty::IntTy::I16) => {
self.check_primitive_impl( self.check_primitive_impl(
def_id, item.def_id,
lang_items.i16_impl(), lang_items.i16_impl(),
None, None,
"i16", "i16",
@ -201,7 +200,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
} }
ty::Int(ty::IntTy::I32) => { ty::Int(ty::IntTy::I32) => {
self.check_primitive_impl( self.check_primitive_impl(
def_id, item.def_id,
lang_items.i32_impl(), lang_items.i32_impl(),
None, None,
"i32", "i32",
@ -212,7 +211,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
} }
ty::Int(ty::IntTy::I64) => { ty::Int(ty::IntTy::I64) => {
self.check_primitive_impl( self.check_primitive_impl(
def_id, item.def_id,
lang_items.i64_impl(), lang_items.i64_impl(),
None, None,
"i64", "i64",
@ -223,7 +222,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
} }
ty::Int(ty::IntTy::I128) => { ty::Int(ty::IntTy::I128) => {
self.check_primitive_impl( self.check_primitive_impl(
def_id, item.def_id,
lang_items.i128_impl(), lang_items.i128_impl(),
None, None,
"i128", "i128",
@ -234,7 +233,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
} }
ty::Int(ty::IntTy::Isize) => { ty::Int(ty::IntTy::Isize) => {
self.check_primitive_impl( self.check_primitive_impl(
def_id, item.def_id,
lang_items.isize_impl(), lang_items.isize_impl(),
None, None,
"isize", "isize",
@ -245,7 +244,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
} }
ty::Uint(ty::UintTy::U8) => { ty::Uint(ty::UintTy::U8) => {
self.check_primitive_impl( self.check_primitive_impl(
def_id, item.def_id,
lang_items.u8_impl(), lang_items.u8_impl(),
None, None,
"u8", "u8",
@ -256,7 +255,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
} }
ty::Uint(ty::UintTy::U16) => { ty::Uint(ty::UintTy::U16) => {
self.check_primitive_impl( self.check_primitive_impl(
def_id, item.def_id,
lang_items.u16_impl(), lang_items.u16_impl(),
None, None,
"u16", "u16",
@ -267,7 +266,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
} }
ty::Uint(ty::UintTy::U32) => { ty::Uint(ty::UintTy::U32) => {
self.check_primitive_impl( self.check_primitive_impl(
def_id, item.def_id,
lang_items.u32_impl(), lang_items.u32_impl(),
None, None,
"u32", "u32",
@ -278,7 +277,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
} }
ty::Uint(ty::UintTy::U64) => { ty::Uint(ty::UintTy::U64) => {
self.check_primitive_impl( self.check_primitive_impl(
def_id, item.def_id,
lang_items.u64_impl(), lang_items.u64_impl(),
None, None,
"u64", "u64",
@ -289,7 +288,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
} }
ty::Uint(ty::UintTy::U128) => { ty::Uint(ty::UintTy::U128) => {
self.check_primitive_impl( self.check_primitive_impl(
def_id, item.def_id,
lang_items.u128_impl(), lang_items.u128_impl(),
None, None,
"u128", "u128",
@ -300,7 +299,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
} }
ty::Uint(ty::UintTy::Usize) => { ty::Uint(ty::UintTy::Usize) => {
self.check_primitive_impl( self.check_primitive_impl(
def_id, item.def_id,
lang_items.usize_impl(), lang_items.usize_impl(),
None, None,
"usize", "usize",
@ -311,7 +310,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
} }
ty::Float(ty::FloatTy::F32) => { ty::Float(ty::FloatTy::F32) => {
self.check_primitive_impl( self.check_primitive_impl(
def_id, item.def_id,
lang_items.f32_impl(), lang_items.f32_impl(),
lang_items.f32_runtime_impl(), lang_items.f32_runtime_impl(),
"f32", "f32",
@ -322,7 +321,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
} }
ty::Float(ty::FloatTy::F64) => { ty::Float(ty::FloatTy::F64) => {
self.check_primitive_impl( self.check_primitive_impl(
def_id, item.def_id,
lang_items.f64_impl(), lang_items.f64_impl(),
lang_items.f64_runtime_impl(), lang_items.f64_runtime_impl(),
"f64", "f64",
@ -369,9 +368,8 @@ impl InherentCollect<'tcx> {
// Add the implementation to the mapping from implementation to base // Add the implementation to the mapping from implementation to base
// type def ID, if there is a base type for this implementation and // type def ID, if there is a base type for this implementation and
// the implementation does not have any associated traits. // the implementation does not have any associated traits.
let impl_def_id = self.tcx.hir().local_def_id(item.hir_id);
let vec = self.impls_map.inherent_impls.entry(def_id).or_default(); let vec = self.impls_map.inherent_impls.entry(def_id).or_default();
vec.push(impl_def_id.to_def_id()); vec.push(item.def_id.to_def_id());
} else { } else {
struct_span_err!( struct_span_err!(
self.tcx.sess, self.tcx.sess,

View file

@ -123,8 +123,7 @@ impl ItemLikeVisitor<'v> for InherentOverlapChecker<'tcx> {
| hir::ItemKind::Struct(..) | hir::ItemKind::Struct(..)
| hir::ItemKind::Trait(..) | hir::ItemKind::Trait(..)
| hir::ItemKind::Union(..) => { | hir::ItemKind::Union(..) => {
let ty_def_id = self.tcx.hir().local_def_id(item.hir_id); let impls = self.tcx.inherent_impls(item.def_id);
let impls = self.tcx.inherent_impls(ty_def_id);
// If there is only one inherent impl block, // If there is only one inherent impl block,
// there is nothing to overlap check it with // there is nothing to overlap check it with

View file

@ -172,8 +172,7 @@ fn coherent_trait(tcx: TyCtxt<'_>, def_id: DefId) {
tcx.ensure().specialization_graph_of(def_id); tcx.ensure().specialization_graph_of(def_id);
let impls = tcx.hir().trait_impls(def_id); let impls = tcx.hir().trait_impls(def_id);
for &hir_id in impls { for &impl_def_id in impls {
let impl_def_id = tcx.hir().local_def_id(hir_id);
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap(); let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
check_impl(tcx, impl_def_id, trait_ref); check_impl(tcx, impl_def_id, trait_ref);

View file

@ -24,7 +24,6 @@ impl ItemLikeVisitor<'v> for OrphanChecker<'tcx> {
/// to prevent inundating the user with a bunch of similar error /// to prevent inundating the user with a bunch of similar error
/// reports. /// reports.
fn visit_item(&mut self, item: &hir::Item<'_>) { fn visit_item(&mut self, item: &hir::Item<'_>) {
let def_id = self.tcx.hir().local_def_id(item.hir_id);
// "Trait" impl // "Trait" impl
if let hir::ItemKind::Impl(hir::Impl { if let hir::ItemKind::Impl(hir::Impl {
generics, of_trait: Some(ref tr), self_ty, .. generics, of_trait: Some(ref tr), self_ty, ..
@ -32,13 +31,13 @@ impl ItemLikeVisitor<'v> for OrphanChecker<'tcx> {
{ {
debug!( debug!(
"coherence2::orphan check: trait impl {}", "coherence2::orphan check: trait impl {}",
self.tcx.hir().node_to_string(item.hir_id) self.tcx.hir().node_to_string(item.hir_id())
); );
let trait_ref = self.tcx.impl_trait_ref(def_id).unwrap(); let trait_ref = self.tcx.impl_trait_ref(item.def_id).unwrap();
let trait_def_id = trait_ref.def_id; let trait_def_id = trait_ref.def_id;
let sm = self.tcx.sess.source_map(); let sm = self.tcx.sess.source_map();
let sp = sm.guess_head_span(item.span); let sp = sm.guess_head_span(item.span);
match traits::orphan_check(self.tcx, def_id.to_def_id()) { match traits::orphan_check(self.tcx, item.def_id.to_def_id()) {
Ok(()) => {} Ok(()) => {}
Err(traits::OrphanCheckErr::NonLocalInputType(tys)) => { Err(traits::OrphanCheckErr::NonLocalInputType(tys)) => {
let mut err = struct_span_err!( let mut err = struct_span_err!(

View file

@ -24,8 +24,7 @@ impl UnsafetyChecker<'tcx> {
unsafety: hir::Unsafety, unsafety: hir::Unsafety,
polarity: hir::ImplPolarity, polarity: hir::ImplPolarity,
) { ) {
let local_did = self.tcx.hir().local_def_id(item.hir_id); if let Some(trait_ref) = self.tcx.impl_trait_ref(item.def_id) {
if let Some(trait_ref) = self.tcx.impl_trait_ref(local_did) {
let trait_def = self.tcx.trait_def(trait_ref.def_id); let trait_def = self.tcx.trait_def(trait_ref.def_id);
let unsafe_attr = impl_generics.and_then(|generics| { let unsafe_attr = impl_generics.and_then(|generics| {
generics.params.iter().find(|p| p.pure_wrt_drop).map(|_| "may_dangle") generics.params.iter().find(|p| p.pure_wrt_drop).map(|_| "may_dangle")

View file

@ -240,7 +240,7 @@ impl Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
} }
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
convert_item(self.tcx, item.hir_id); convert_item(self.tcx, item.item_id());
reject_placeholder_type_signatures_in_item(self.tcx, item); reject_placeholder_type_signatures_in_item(self.tcx, item);
intravisit::walk_item(self, item); intravisit::walk_item(self, item);
} }
@ -274,12 +274,12 @@ impl Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
} }
fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) { fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) {
convert_trait_item(self.tcx, trait_item.hir_id); convert_trait_item(self.tcx, trait_item.trait_item_id());
intravisit::walk_trait_item(self, trait_item); intravisit::walk_trait_item(self, trait_item);
} }
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) { fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
convert_impl_item(self.tcx, impl_item.hir_id); convert_impl_item(self.tcx, impl_item.impl_item_id());
intravisit::walk_impl_item(self, impl_item); intravisit::walk_impl_item(self, impl_item);
} }
} }
@ -707,10 +707,10 @@ fn is_param(tcx: TyCtxt<'_>, ast_ty: &hir::Ty<'_>, param_id: hir::HirId) -> bool
} }
} }
fn convert_item(tcx: TyCtxt<'_>, item_id: hir::HirId) { fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
let it = tcx.hir().expect_item(item_id); let it = tcx.hir().item(item_id);
debug!("convert: item {} with id {}", it.ident, it.hir_id); debug!("convert: item {} with id {}", it.ident, it.hir_id());
let def_id = tcx.hir().local_def_id(item_id); let def_id = item_id.def_id;
match it.kind { match it.kind {
// These don't define types. // These don't define types.
@ -721,12 +721,11 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::HirId) {
hir::ItemKind::ForeignMod { items, .. } => { hir::ItemKind::ForeignMod { items, .. } => {
for item in items { for item in items {
let item = tcx.hir().foreign_item(item.id); let item = tcx.hir().foreign_item(item.id);
let def_id = tcx.hir().local_def_id(item.hir_id); tcx.ensure().generics_of(item.def_id);
tcx.ensure().generics_of(def_id); tcx.ensure().type_of(item.def_id);
tcx.ensure().type_of(def_id); tcx.ensure().predicates_of(item.def_id);
tcx.ensure().predicates_of(def_id);
if let hir::ForeignItemKind::Fn(..) = item.kind { if let hir::ForeignItemKind::Fn(..) = item.kind {
tcx.ensure().fn_sig(def_id); tcx.ensure().fn_sig(item.def_id);
} }
} }
} }
@ -797,23 +796,22 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::HirId) {
} }
} }
fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::HirId) { fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
let trait_item = tcx.hir().expect_trait_item(trait_item_id); let trait_item = tcx.hir().trait_item(trait_item_id);
let def_id = tcx.hir().local_def_id(trait_item.hir_id); tcx.ensure().generics_of(trait_item_id.def_id);
tcx.ensure().generics_of(def_id);
match trait_item.kind { match trait_item.kind {
hir::TraitItemKind::Fn(..) => { hir::TraitItemKind::Fn(..) => {
tcx.ensure().type_of(def_id); tcx.ensure().type_of(trait_item_id.def_id);
tcx.ensure().fn_sig(def_id); tcx.ensure().fn_sig(trait_item_id.def_id);
} }
hir::TraitItemKind::Const(.., Some(_)) => { hir::TraitItemKind::Const(.., Some(_)) => {
tcx.ensure().type_of(def_id); tcx.ensure().type_of(trait_item_id.def_id);
} }
hir::TraitItemKind::Const(..) => { hir::TraitItemKind::Const(..) => {
tcx.ensure().type_of(def_id); tcx.ensure().type_of(trait_item_id.def_id);
// Account for `const C: _;`. // Account for `const C: _;`.
let mut visitor = PlaceholderHirTyCollector::default(); let mut visitor = PlaceholderHirTyCollector::default();
visitor.visit_trait_item(trait_item); visitor.visit_trait_item(trait_item);
@ -821,8 +819,8 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::HirId) {
} }
hir::TraitItemKind::Type(_, Some(_)) => { hir::TraitItemKind::Type(_, Some(_)) => {
tcx.ensure().item_bounds(def_id); tcx.ensure().item_bounds(trait_item_id.def_id);
tcx.ensure().type_of(def_id); tcx.ensure().type_of(trait_item_id.def_id);
// Account for `type T = _;`. // Account for `type T = _;`.
let mut visitor = PlaceholderHirTyCollector::default(); let mut visitor = PlaceholderHirTyCollector::default();
visitor.visit_trait_item(trait_item); visitor.visit_trait_item(trait_item);
@ -830,7 +828,7 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::HirId) {
} }
hir::TraitItemKind::Type(_, None) => { hir::TraitItemKind::Type(_, None) => {
tcx.ensure().item_bounds(def_id); tcx.ensure().item_bounds(trait_item_id.def_id);
// #74612: Visit and try to find bad placeholders // #74612: Visit and try to find bad placeholders
// even if there is no concrete type. // even if there is no concrete type.
let mut visitor = PlaceholderHirTyCollector::default(); let mut visitor = PlaceholderHirTyCollector::default();
@ -840,15 +838,15 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::HirId) {
} }
}; };
tcx.ensure().predicates_of(def_id); tcx.ensure().predicates_of(trait_item_id.def_id);
} }
fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::HirId) { fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) {
let def_id = tcx.hir().local_def_id(impl_item_id); let def_id = impl_item_id.def_id;
tcx.ensure().generics_of(def_id); tcx.ensure().generics_of(def_id);
tcx.ensure().type_of(def_id); tcx.ensure().type_of(def_id);
tcx.ensure().predicates_of(def_id); tcx.ensure().predicates_of(def_id);
let impl_item = tcx.hir().expect_impl_item(impl_item_id); let impl_item = tcx.hir().impl_item(impl_item_id);
match impl_item.kind { match impl_item.kind {
hir::ImplItemKind::Fn(..) => { hir::ImplItemKind::Fn(..) => {
tcx.ensure().fn_sig(def_id); tcx.ensure().fn_sig(def_id);
@ -1115,7 +1113,7 @@ fn super_predicates_that_define_assoc_type(
let is_trait_alias = tcx.is_trait_alias(trait_def_id); let is_trait_alias = tcx.is_trait_alias(trait_def_id);
let superbounds2 = icx.type_parameter_bounds_in_generics( let superbounds2 = icx.type_parameter_bounds_in_generics(
generics, generics,
item.hir_id, item.hir_id(),
self_param_ty, self_param_ty,
OnlySelfBounds(!is_trait_alias), OnlySelfBounds(!is_trait_alias),
assoc_name, assoc_name,
@ -1439,12 +1437,12 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
// //
// Something of a hack: use the node id for the trait, also as // Something of a hack: use the node id for the trait, also as
// the node id for the Self type parameter. // the node id for the Self type parameter.
let param_id = item.hir_id; let param_id = item.def_id;
opt_self = Some(ty::GenericParamDef { opt_self = Some(ty::GenericParamDef {
index: 0, index: 0,
name: kw::SelfUpper, name: kw::SelfUpper,
def_id: tcx.hir().local_def_id(param_id).to_def_id(), def_id: param_id.to_def_id(),
pure_wrt_drop: false, pure_wrt_drop: false,
kind: ty::GenericParamDefKind::Type { kind: ty::GenericParamDefKind::Type {
has_default: false, has_default: false,

View file

@ -582,26 +582,23 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
} }
fn visit_item(&mut self, it: &'tcx Item<'tcx>) { fn visit_item(&mut self, it: &'tcx Item<'tcx>) {
debug!("find_existential_constraints: visiting {:?}", it); debug!("find_existential_constraints: visiting {:?}", it);
let def_id = self.tcx.hir().local_def_id(it.hir_id);
// The opaque type itself or its children are not within its reveal scope. // The opaque type itself or its children are not within its reveal scope.
if def_id.to_def_id() != self.def_id { if it.def_id.to_def_id() != self.def_id {
self.check(def_id); self.check(it.def_id);
intravisit::walk_item(self, it); intravisit::walk_item(self, it);
} }
} }
fn visit_impl_item(&mut self, it: &'tcx ImplItem<'tcx>) { fn visit_impl_item(&mut self, it: &'tcx ImplItem<'tcx>) {
debug!("find_existential_constraints: visiting {:?}", it); debug!("find_existential_constraints: visiting {:?}", it);
let def_id = self.tcx.hir().local_def_id(it.hir_id);
// The opaque type itself or its children are not within its reveal scope. // The opaque type itself or its children are not within its reveal scope.
if def_id.to_def_id() != self.def_id { if it.def_id.to_def_id() != self.def_id {
self.check(def_id); self.check(it.def_id);
intravisit::walk_impl_item(self, it); intravisit::walk_impl_item(self, it);
} }
} }
fn visit_trait_item(&mut self, it: &'tcx TraitItem<'tcx>) { fn visit_trait_item(&mut self, it: &'tcx TraitItem<'tcx>) {
debug!("find_existential_constraints: visiting {:?}", it); debug!("find_existential_constraints: visiting {:?}", it);
let def_id = self.tcx.hir().local_def_id(it.hir_id); self.check(it.def_id);
self.check(def_id);
intravisit::walk_trait_item(self, it); intravisit::walk_trait_item(self, it);
} }
} }

View file

@ -59,7 +59,7 @@ pub fn impl_wf_check(tcx: TyCtxt<'_>) {
// but it's one that we must perform earlier than the rest of // but it's one that we must perform earlier than the rest of
// WfCheck. // WfCheck.
for &module in tcx.hir().krate().modules.keys() { for &module in tcx.hir().krate().modules.keys() {
tcx.ensure().check_mod_impl_wf(tcx.hir().local_def_id(module)); tcx.ensure().check_mod_impl_wf(module);
} }
} }
@ -81,11 +81,10 @@ struct ImplWfCheck<'tcx> {
impl ItemLikeVisitor<'tcx> for ImplWfCheck<'tcx> { impl ItemLikeVisitor<'tcx> for ImplWfCheck<'tcx> {
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
if let hir::ItemKind::Impl(ref impl_) = item.kind { if let hir::ItemKind::Impl(ref impl_) = item.kind {
let impl_def_id = self.tcx.hir().local_def_id(item.hir_id); enforce_impl_params_are_constrained(self.tcx, item.def_id, impl_.items);
enforce_impl_params_are_constrained(self.tcx, impl_def_id, impl_.items);
enforce_impl_items_are_distinct(self.tcx, impl_.items); enforce_impl_items_are_distinct(self.tcx, impl_.items);
if self.min_specialization { if self.min_specialization {
check_min_specialization(self.tcx, impl_def_id.to_def_id(), item.span); check_min_specialization(self.tcx, item.def_id.to_def_id(), item.span);
} }
} }
} }
@ -131,7 +130,7 @@ fn enforce_impl_params_are_constrained(
// Disallow unconstrained lifetimes, but only if they appear in assoc types. // Disallow unconstrained lifetimes, but only if they appear in assoc types.
let lifetimes_in_associated_types: FxHashSet<_> = impl_item_refs let lifetimes_in_associated_types: FxHashSet<_> = impl_item_refs
.iter() .iter()
.map(|item_ref| tcx.hir().local_def_id(item_ref.id.hir_id)) .map(|item_ref| item_ref.id.def_id)
.flat_map(|def_id| { .flat_map(|def_id| {
let item = tcx.associated_item(def_id); let item = tcx.associated_item(def_id);
match item.kind { match item.kind {

View file

@ -369,7 +369,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorReported> {
tcx.sess.track_errors(|| { tcx.sess.track_errors(|| {
tcx.sess.time("type_collecting", || { tcx.sess.time("type_collecting", || {
for &module in tcx.hir().krate().modules.keys() { for &module in tcx.hir().krate().modules.keys() {
tcx.ensure().collect_mod_item_types(tcx.hir().local_def_id(module)); tcx.ensure().collect_mod_item_types(module);
} }
}); });
})?; })?;
@ -401,7 +401,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorReported> {
// NOTE: This is copy/pasted in librustdoc/core.rs and should be kept in sync. // NOTE: This is copy/pasted in librustdoc/core.rs and should be kept in sync.
tcx.sess.time("item_types_checking", || { tcx.sess.time("item_types_checking", || {
for &module in tcx.hir().krate().modules.keys() { for &module in tcx.hir().krate().modules.keys() {
tcx.ensure().check_mod_item_types(tcx.hir().local_def_id(module)); tcx.ensure().check_mod_item_types(module);
} }
}); });

View file

@ -2,7 +2,6 @@ use rustc_data_structures::fx::FxHashMap;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::itemlikevisit::ItemLikeVisitor;
use rustc_hir::Node;
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst}; use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst};
use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_span::Span; use rustc_span::Span;
@ -53,16 +52,10 @@ pub struct InferVisitor<'cx, 'tcx> {
impl<'cx, 'tcx> ItemLikeVisitor<'tcx> for InferVisitor<'cx, 'tcx> { impl<'cx, 'tcx> ItemLikeVisitor<'tcx> for InferVisitor<'cx, 'tcx> {
fn visit_item(&mut self, item: &hir::Item<'_>) { fn visit_item(&mut self, item: &hir::Item<'_>) {
let item_did = self.tcx.hir().local_def_id(item.hir_id); let item_did = item.def_id;
debug!("InferVisitor::visit_item(item={:?})", item_did); debug!("InferVisitor::visit_item(item={:?})", item_did);
let hir_id = self.tcx.hir().local_def_id_to_hir_id(item_did);
let item = match self.tcx.hir().get(hir_id) {
Node::Item(item) => item,
_ => bug!(),
};
let mut item_required_predicates = RequiredPredicates::default(); let mut item_required_predicates = RequiredPredicates::default();
match item.kind { match item.kind {
hir::ItemKind::Union(..) | hir::ItemKind::Enum(..) | hir::ItemKind::Struct(..) => { hir::ItemKind::Union(..) | hir::ItemKind::Enum(..) | hir::ItemKind::Struct(..) => {

View file

@ -14,12 +14,10 @@ struct OutlivesTest<'tcx> {
impl ItemLikeVisitor<'tcx> for OutlivesTest<'tcx> { impl ItemLikeVisitor<'tcx> for OutlivesTest<'tcx> {
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
let item_def_id = self.tcx.hir().local_def_id(item.hir_id);
// For unit testing: check for a special "rustc_outlives" // For unit testing: check for a special "rustc_outlives"
// attribute and report an error with various results if found. // attribute and report an error with various results if found.
if self.tcx.has_attr(item_def_id.to_def_id(), sym::rustc_outlives) { if self.tcx.has_attr(item.def_id.to_def_id(), sym::rustc_outlives) {
let inferred_outlives_of = self.tcx.inferred_outlives_of(item_def_id); let inferred_outlives_of = self.tcx.inferred_outlives_of(item.def_id);
struct_span_err!(self.tcx.sess, item.span, E0640, "{:?}", inferred_outlives_of).emit(); struct_span_err!(self.tcx.sess, item.span, E0640, "{:?}", inferred_outlives_of).emit();
} }
} }

View file

@ -71,7 +71,7 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for ConstraintContext<'a, 'tcx> {
fn visit_item(&mut self, item: &hir::Item<'_>) { fn visit_item(&mut self, item: &hir::Item<'_>) {
match item.kind { match item.kind {
hir::ItemKind::Struct(ref struct_def, _) | hir::ItemKind::Union(ref struct_def, _) => { hir::ItemKind::Struct(ref struct_def, _) | hir::ItemKind::Union(ref struct_def, _) => {
self.visit_node_helper(item.hir_id); self.visit_node_helper(item.hir_id());
if let hir::VariantData::Tuple(..) = *struct_def { if let hir::VariantData::Tuple(..) = *struct_def {
self.visit_node_helper(struct_def.ctor_hir_id().unwrap()); self.visit_node_helper(struct_def.ctor_hir_id().unwrap());
@ -79,7 +79,7 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for ConstraintContext<'a, 'tcx> {
} }
hir::ItemKind::Enum(ref enum_def, _) => { hir::ItemKind::Enum(ref enum_def, _) => {
self.visit_node_helper(item.hir_id); self.visit_node_helper(item.hir_id());
for variant in enum_def.variants { for variant in enum_def.variants {
if let hir::VariantData::Tuple(..) = variant.data { if let hir::VariantData::Tuple(..) = variant.data {
@ -89,7 +89,7 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for ConstraintContext<'a, 'tcx> {
} }
hir::ItemKind::Fn(..) => { hir::ItemKind::Fn(..) => {
self.visit_node_helper(item.hir_id); self.visit_node_helper(item.hir_id());
} }
_ => {} _ => {}
@ -98,19 +98,19 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for ConstraintContext<'a, 'tcx> {
fn visit_trait_item(&mut self, trait_item: &hir::TraitItem<'_>) { fn visit_trait_item(&mut self, trait_item: &hir::TraitItem<'_>) {
if let hir::TraitItemKind::Fn(..) = trait_item.kind { if let hir::TraitItemKind::Fn(..) = trait_item.kind {
self.visit_node_helper(trait_item.hir_id); self.visit_node_helper(trait_item.hir_id());
} }
} }
fn visit_impl_item(&mut self, impl_item: &hir::ImplItem<'_>) { fn visit_impl_item(&mut self, impl_item: &hir::ImplItem<'_>) {
if let hir::ImplItemKind::Fn(..) = impl_item.kind { if let hir::ImplItemKind::Fn(..) = impl_item.kind {
self.visit_node_helper(impl_item.hir_id); self.visit_node_helper(impl_item.hir_id());
} }
} }
fn visit_foreign_item(&mut self, foreign_item: &hir::ForeignItem<'_>) { fn visit_foreign_item(&mut self, foreign_item: &hir::ForeignItem<'_>) {
if let hir::ForeignItemKind::Fn(..) = foreign_item.kind { if let hir::ForeignItemKind::Fn(..) = foreign_item.kind {
self.visit_node_helper(foreign_item.hir_id); self.visit_node_helper(foreign_item.hir_id());
} }
} }
} }

View file

@ -128,11 +128,11 @@ impl<'a, 'tcx> TermsContext<'a, 'tcx> {
impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for TermsContext<'a, 'tcx> { impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for TermsContext<'a, 'tcx> {
fn visit_item(&mut self, item: &hir::Item<'_>) { fn visit_item(&mut self, item: &hir::Item<'_>) {
debug!("add_inferreds for item {}", self.tcx.hir().node_to_string(item.hir_id)); debug!("add_inferreds for item {}", self.tcx.hir().node_to_string(item.hir_id()));
match item.kind { match item.kind {
hir::ItemKind::Struct(ref struct_def, _) | hir::ItemKind::Union(ref struct_def, _) => { hir::ItemKind::Struct(ref struct_def, _) | hir::ItemKind::Union(ref struct_def, _) => {
self.add_inferreds_for_item(item.hir_id); self.add_inferreds_for_item(item.hir_id());
if let hir::VariantData::Tuple(..) = *struct_def { if let hir::VariantData::Tuple(..) = *struct_def {
self.add_inferreds_for_item(struct_def.ctor_hir_id().unwrap()); self.add_inferreds_for_item(struct_def.ctor_hir_id().unwrap());
@ -140,7 +140,7 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for TermsContext<'a, 'tcx> {
} }
hir::ItemKind::Enum(ref enum_def, _) => { hir::ItemKind::Enum(ref enum_def, _) => {
self.add_inferreds_for_item(item.hir_id); self.add_inferreds_for_item(item.hir_id());
for variant in enum_def.variants { for variant in enum_def.variants {
if let hir::VariantData::Tuple(..) = variant.data { if let hir::VariantData::Tuple(..) = variant.data {
@ -150,7 +150,7 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for TermsContext<'a, 'tcx> {
} }
hir::ItemKind::Fn(..) => { hir::ItemKind::Fn(..) => {
self.add_inferreds_for_item(item.hir_id); self.add_inferreds_for_item(item.hir_id());
} }
_ => {} _ => {}
@ -159,19 +159,19 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for TermsContext<'a, 'tcx> {
fn visit_trait_item(&mut self, trait_item: &hir::TraitItem<'_>) { fn visit_trait_item(&mut self, trait_item: &hir::TraitItem<'_>) {
if let hir::TraitItemKind::Fn(..) = trait_item.kind { if let hir::TraitItemKind::Fn(..) = trait_item.kind {
self.add_inferreds_for_item(trait_item.hir_id); self.add_inferreds_for_item(trait_item.hir_id());
} }
} }
fn visit_impl_item(&mut self, impl_item: &hir::ImplItem<'_>) { fn visit_impl_item(&mut self, impl_item: &hir::ImplItem<'_>) {
if let hir::ImplItemKind::Fn(..) = impl_item.kind { if let hir::ImplItemKind::Fn(..) = impl_item.kind {
self.add_inferreds_for_item(impl_item.hir_id); self.add_inferreds_for_item(impl_item.hir_id());
} }
} }
fn visit_foreign_item(&mut self, foreign_item: &hir::ForeignItem<'_>) { fn visit_foreign_item(&mut self, foreign_item: &hir::ForeignItem<'_>) {
if let hir::ForeignItemKind::Fn(..) = foreign_item.kind { if let hir::ForeignItemKind::Fn(..) = foreign_item.kind {
self.add_inferreds_for_item(foreign_item.hir_id); self.add_inferreds_for_item(foreign_item.hir_id());
} }
} }
} }

View file

@ -14,12 +14,10 @@ struct VarianceTest<'tcx> {
impl ItemLikeVisitor<'tcx> for VarianceTest<'tcx> { impl ItemLikeVisitor<'tcx> for VarianceTest<'tcx> {
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
let item_def_id = self.tcx.hir().local_def_id(item.hir_id);
// For unit testing: check for a special "rustc_variance" // For unit testing: check for a special "rustc_variance"
// attribute and report an error with various results if found. // attribute and report an error with various results if found.
if self.tcx.has_attr(item_def_id.to_def_id(), sym::rustc_variance) { if self.tcx.has_attr(item.def_id.to_def_id(), sym::rustc_variance) {
let variances_of = self.tcx.variances_of(item_def_id); let variances_of = self.tcx.variances_of(item.def_id);
struct_span_err!(self.tcx.sess, item.span, E0208, "{:?}", variances_of).emit(); struct_span_err!(self.tcx.sess, item.span, E0208, "{:?}", variances_of).emit();
} }
} }

View file

@ -133,18 +133,17 @@ impl Clean<ExternalCrate> for CrateNum {
.item_ids .item_ids
.iter() .iter()
.filter_map(|&id| { .filter_map(|&id| {
let item = cx.tcx.hir().expect_item(id.id); let item = cx.tcx.hir().item(id);
match item.kind { match item.kind {
hir::ItemKind::Mod(_) => as_primitive(Res::Def( hir::ItemKind::Mod(_) => {
DefKind::Mod, as_primitive(Res::Def(DefKind::Mod, id.def_id.to_def_id()))
cx.tcx.hir().local_def_id(id.id).to_def_id(), }
)),
hir::ItemKind::Use(ref path, hir::UseKind::Single) hir::ItemKind::Use(ref path, hir::UseKind::Single)
if item.vis.node.is_pub() => if item.vis.node.is_pub() =>
{ {
as_primitive(path.res).map(|(_, prim)| { as_primitive(path.res).map(|(_, prim)| {
// Pretend the primitive is local. // Pretend the primitive is local.
(cx.tcx.hir().local_def_id(id.id).to_def_id(), prim) (id.def_id.to_def_id(), prim)
}) })
} }
_ => None, _ => None,
@ -185,18 +184,15 @@ impl Clean<ExternalCrate> for CrateNum {
.item_ids .item_ids
.iter() .iter()
.filter_map(|&id| { .filter_map(|&id| {
let item = cx.tcx.hir().expect_item(id.id); let item = cx.tcx.hir().item(id);
match item.kind { match item.kind {
hir::ItemKind::Mod(_) => as_keyword(Res::Def( hir::ItemKind::Mod(_) => {
DefKind::Mod, as_keyword(Res::Def(DefKind::Mod, id.def_id.to_def_id()))
cx.tcx.hir().local_def_id(id.id).to_def_id(), }
)),
hir::ItemKind::Use(ref path, hir::UseKind::Single) hir::ItemKind::Use(ref path, hir::UseKind::Single)
if item.vis.node.is_pub() => if item.vis.node.is_pub() =>
{ {
as_keyword(path.res).map(|(_, prim)| { as_keyword(path.res).map(|(_, prim)| (id.def_id.to_def_id(), prim))
(cx.tcx.hir().local_def_id(id.id).to_def_id(), prim)
})
} }
_ => None, _ => None,
} }
@ -912,7 +908,7 @@ fn clean_fn_or_proc_macro(
} }
None => { None => {
let mut func = (sig, generics, body_id).clean(cx); let mut func = (sig, generics, body_id).clean(cx);
let def_id = cx.tcx.hir().local_def_id(item.hir_id).to_def_id(); let def_id = item.def_id.to_def_id();
func.header.constness = func.header.constness =
if is_const_fn(cx.tcx, def_id) && is_unstable_const_fn(cx.tcx, def_id).is_none() { if is_const_fn(cx.tcx, def_id) && is_unstable_const_fn(cx.tcx, def_id).is_none() {
hir::Constness::Const hir::Constness::Const
@ -1048,7 +1044,7 @@ impl Clean<TypeKind> for hir::def::DefKind {
impl Clean<Item> for hir::TraitItem<'_> { impl Clean<Item> for hir::TraitItem<'_> {
fn clean(&self, cx: &DocContext<'_>) -> Item { fn clean(&self, cx: &DocContext<'_>) -> Item {
let local_did = cx.tcx.hir().local_def_id(self.hir_id).to_def_id(); let local_did = self.def_id.to_def_id();
cx.with_param_env(local_did, || { cx.with_param_env(local_did, || {
let inner = match self.kind { let inner = match self.kind {
hir::TraitItemKind::Const(ref ty, default) => { hir::TraitItemKind::Const(ref ty, default) => {
@ -1089,7 +1085,7 @@ impl Clean<Item> for hir::TraitItem<'_> {
impl Clean<Item> for hir::ImplItem<'_> { impl Clean<Item> for hir::ImplItem<'_> {
fn clean(&self, cx: &DocContext<'_>) -> Item { fn clean(&self, cx: &DocContext<'_>) -> Item {
let local_did = cx.tcx.hir().local_def_id(self.hir_id).to_def_id(); let local_did = self.def_id.to_def_id();
cx.with_param_env(local_did, || { cx.with_param_env(local_did, || {
let inner = match self.kind { let inner = match self.kind {
hir::ImplItemKind::Const(ref ty, expr) => { hir::ImplItemKind::Const(ref ty, expr) => {
@ -1120,7 +1116,7 @@ impl Clean<Item> for hir::ImplItem<'_> {
let what_rustc_thinks = let what_rustc_thinks =
Item::from_def_id_and_parts(local_did, Some(self.ident.name), inner, cx); Item::from_def_id_and_parts(local_did, Some(self.ident.name), inner, cx);
let parent_item = cx.tcx.hir().expect_item(cx.tcx.hir().get_parent_item(self.hir_id)); let parent_item = cx.tcx.hir().expect_item(cx.tcx.hir().get_parent_item(self.hir_id()));
if let hir::ItemKind::Impl(impl_) = &parent_item.kind { if let hir::ItemKind::Impl(impl_) = &parent_item.kind {
if impl_.of_trait.is_some() { if impl_.of_trait.is_some() {
// Trait impl items always inherit the impl's visibility -- // Trait impl items always inherit the impl's visibility --
@ -1475,7 +1471,7 @@ impl Clean<Type> for hir::Ty<'_> {
} }
TyKind::Tup(ref tys) => Tuple(tys.clean(cx)), TyKind::Tup(ref tys) => Tuple(tys.clean(cx)),
TyKind::OpaqueDef(item_id, _) => { TyKind::OpaqueDef(item_id, _) => {
let item = cx.tcx.hir().expect_item(item_id.id); let item = cx.tcx.hir().item(item_id);
if let hir::ItemKind::OpaqueTy(ref ty) = item.kind { if let hir::ItemKind::OpaqueTy(ref ty) = item.kind {
ImplTrait(ty.bounds.clean(cx)) ImplTrait(ty.bounds.clean(cx))
} else { } else {
@ -1950,8 +1946,8 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Symbol>) {
use hir::ItemKind; use hir::ItemKind;
let (item, renamed) = self; let (item, renamed) = self;
let def_id = cx.tcx.hir().local_def_id(item.hir_id).to_def_id(); let def_id = item.def_id.to_def_id();
let mut name = renamed.unwrap_or_else(|| cx.tcx.hir().name(item.hir_id)); let mut name = renamed.unwrap_or_else(|| cx.tcx.hir().name(item.hir_id()));
cx.with_param_env(def_id, || { cx.with_param_env(def_id, || {
let kind = match item.kind { let kind = match item.kind {
ItemKind::Static(ty, mutability, body_id) => { ItemKind::Static(ty, mutability, body_id) => {
@ -1999,7 +1995,7 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Symbol>) {
fields: variant_data.fields().clean(cx), fields: variant_data.fields().clean(cx),
fields_stripped: false, fields_stripped: false,
}), }),
ItemKind::Impl(ref impl_) => return clean_impl(impl_, item.hir_id, cx), ItemKind::Impl(ref impl_) => return clean_impl(impl_, item.hir_id(), cx),
// proc macros can have a name set by attributes // proc macros can have a name set by attributes
ItemKind::Fn(ref sig, ref generics, body_id) => { ItemKind::Fn(ref sig, ref generics, body_id) => {
clean_fn_or_proc_macro(item, sig, generics, body_id, &mut name, cx) clean_fn_or_proc_macro(item, sig, generics, body_id, &mut name, cx)
@ -2107,8 +2103,7 @@ fn clean_extern_crate(
cx: &DocContext<'_>, cx: &DocContext<'_>,
) -> Vec<Item> { ) -> Vec<Item> {
// this is the ID of the `extern crate` statement // this is the ID of the `extern crate` statement
let def_id = cx.tcx.hir().local_def_id(krate.hir_id); let cnum = cx.tcx.extern_mod_stmt_cnum(krate.def_id).unwrap_or(LOCAL_CRATE);
let cnum = cx.tcx.extern_mod_stmt_cnum(def_id).unwrap_or(LOCAL_CRATE);
// this is the ID of the crate itself // this is the ID of the crate itself
let crate_def_id = DefId { krate: cnum, index: CRATE_DEF_INDEX }; let crate_def_id = DefId { krate: cnum, index: CRATE_DEF_INDEX };
let please_inline = krate.vis.node.is_pub() let please_inline = krate.vis.node.is_pub()
@ -2127,7 +2122,7 @@ fn clean_extern_crate(
if let Some(items) = inline::try_inline( if let Some(items) = inline::try_inline(
cx, cx,
cx.tcx.parent_module(krate.hir_id).to_def_id(), cx.tcx.parent_module(krate.hir_id()).to_def_id(),
res, res,
name, name,
Some(krate.attrs), Some(krate.attrs),
@ -2196,7 +2191,6 @@ fn clean_use_statement(
// Also check whether imports were asked to be inlined, in case we're trying to re-export a // Also check whether imports were asked to be inlined, in case we're trying to re-export a
// crate in Rust 2018+ // crate in Rust 2018+
let def_id = cx.tcx.hir().local_def_id(import.hir_id).to_def_id();
let path = path.clean(cx); let path = path.clean(cx);
let inner = if kind == hir::UseKind::Glob { let inner = if kind == hir::UseKind::Glob {
if !denied { if !denied {
@ -2221,14 +2215,14 @@ fn clean_use_statement(
if let Some(mut items) = inline::try_inline( if let Some(mut items) = inline::try_inline(
cx, cx,
cx.tcx.parent_module(import.hir_id).to_def_id(), cx.tcx.parent_module(import.hir_id()).to_def_id(),
path.res, path.res,
name, name,
Some(import.attrs), Some(import.attrs),
&mut visited, &mut visited,
) { ) {
items.push(Item::from_def_id_and_parts( items.push(Item::from_def_id_and_parts(
def_id, import.def_id.to_def_id(),
None, None,
ImportItem(Import::new_simple(name, resolve_use_source(cx, path), false)), ImportItem(Import::new_simple(name, resolve_use_source(cx, path), false)),
cx, cx,
@ -2239,16 +2233,16 @@ fn clean_use_statement(
Import::new_simple(name, resolve_use_source(cx, path), true) Import::new_simple(name, resolve_use_source(cx, path), true)
}; };
vec![Item::from_def_id_and_parts(def_id, None, ImportItem(inner), cx)] vec![Item::from_def_id_and_parts(import.def_id.to_def_id(), None, ImportItem(inner), cx)]
} }
impl Clean<Item> for (&hir::ForeignItem<'_>, Option<Symbol>) { impl Clean<Item> for (&hir::ForeignItem<'_>, Option<Symbol>) {
fn clean(&self, cx: &DocContext<'_>) -> Item { fn clean(&self, cx: &DocContext<'_>) -> Item {
let (item, renamed) = self; let (item, renamed) = self;
cx.with_param_env(cx.tcx.hir().local_def_id(item.hir_id).to_def_id(), || { cx.with_param_env(item.def_id.to_def_id(), || {
let kind = match item.kind { let kind = match item.kind {
hir::ForeignItemKind::Fn(ref decl, ref names, ref generics) => { hir::ForeignItemKind::Fn(ref decl, ref names, ref generics) => {
let abi = cx.tcx.hir().get_foreign_abi(item.hir_id); let abi = cx.tcx.hir().get_foreign_abi(item.hir_id());
let (generics, decl) = enter_impl_trait(cx, || { let (generics, decl) = enter_impl_trait(cx, || {
(generics.clean(cx), (&**decl, &names[..]).clean(cx)) (generics.clean(cx), (&**decl, &names[..]).clean(cx))
}); });
@ -2270,7 +2264,7 @@ impl Clean<Item> for (&hir::ForeignItem<'_>, Option<Symbol>) {
}; };
Item::from_hir_id_and_parts( Item::from_hir_id_and_parts(
item.hir_id, item.hir_id(),
Some(renamed.unwrap_or(item.ident.name)), Some(renamed.unwrap_or(item.ident.name)),
kind, kind,
cx, cx,
@ -2297,7 +2291,7 @@ impl Clean<Item> for (&hir::MacroDef<'_>, Option<Symbol>) {
) )
} else { } else {
let vis = item.vis.clean(cx); let vis = item.vis.clean(cx);
let def_id = cx.tcx.hir().local_def_id(item.hir_id).to_def_id(); let def_id = item.def_id.to_def_id();
if matchers.len() <= 1 { if matchers.len() <= 1 {
format!( format!(
@ -2320,7 +2314,7 @@ impl Clean<Item> for (&hir::MacroDef<'_>, Option<Symbol>) {
}; };
Item::from_hir_id_and_parts( Item::from_hir_id_and_parts(
item.hir_id, item.hir_id(),
Some(name), Some(name),
MacroItem(Macro { source, imported_from: None }), MacroItem(Macro { source, imported_from: None }),
cx, cx,

View file

@ -479,7 +479,7 @@ crate fn run_global_ctxt(
// NOTE: This is copy/pasted from typeck/lib.rs and should be kept in sync with those changes. // NOTE: This is copy/pasted from typeck/lib.rs and should be kept in sync with those changes.
tcx.sess.time("item_types_checking", || { tcx.sess.time("item_types_checking", || {
for &module in tcx.hir().krate().modules.keys() { for &module in tcx.hir().krate().modules.keys() {
tcx.ensure().check_mod_item_types(tcx.hir().local_def_id(module)); tcx.ensure().check_mod_item_types(module);
} }
}); });
tcx.sess.abort_if_errors(); tcx.sess.abort_if_errors();
@ -488,8 +488,7 @@ crate fn run_global_ctxt(
}); });
tcx.sess.time("check_mod_attrs", || { tcx.sess.time("check_mod_attrs", || {
for &module in tcx.hir().krate().modules.keys() { for &module in tcx.hir().krate().modules.keys() {
let local_def_id = tcx.hir().local_def_id(module); tcx.ensure().check_mod_attrs(module);
tcx.ensure().check_mod_attrs(local_def_id);
} }
}); });

View file

@ -1050,27 +1050,45 @@ impl<'a, 'hir, 'tcx> intravisit::Visitor<'hir> for HirCollector<'a, 'hir, 'tcx>
item.ident.to_string() item.ident.to_string()
}; };
self.visit_testable(name, &item.attrs, item.hir_id, item.span, |this| { self.visit_testable(name, &item.attrs, item.hir_id(), item.span, |this| {
intravisit::walk_item(this, item); intravisit::walk_item(this, item);
}); });
} }
fn visit_trait_item(&mut self, item: &'hir hir::TraitItem<'_>) { fn visit_trait_item(&mut self, item: &'hir hir::TraitItem<'_>) {
self.visit_testable(item.ident.to_string(), &item.attrs, item.hir_id, item.span, |this| { self.visit_testable(
intravisit::walk_trait_item(this, item); item.ident.to_string(),
}); &item.attrs,
item.hir_id(),
item.span,
|this| {
intravisit::walk_trait_item(this, item);
},
);
} }
fn visit_impl_item(&mut self, item: &'hir hir::ImplItem<'_>) { fn visit_impl_item(&mut self, item: &'hir hir::ImplItem<'_>) {
self.visit_testable(item.ident.to_string(), &item.attrs, item.hir_id, item.span, |this| { self.visit_testable(
intravisit::walk_impl_item(this, item); item.ident.to_string(),
}); &item.attrs,
item.hir_id(),
item.span,
|this| {
intravisit::walk_impl_item(this, item);
},
);
} }
fn visit_foreign_item(&mut self, item: &'hir hir::ForeignItem<'_>) { fn visit_foreign_item(&mut self, item: &'hir hir::ForeignItem<'_>) {
self.visit_testable(item.ident.to_string(), &item.attrs, item.hir_id, item.span, |this| { self.visit_testable(
intravisit::walk_foreign_item(this, item); item.ident.to_string(),
}); &item.attrs,
item.hir_id(),
item.span,
|this| {
intravisit::walk_foreign_item(this, item);
},
);
} }
fn visit_variant( fn visit_variant(
@ -1094,7 +1112,7 @@ impl<'a, 'hir, 'tcx> intravisit::Visitor<'hir> for HirCollector<'a, 'hir, 'tcx>
self.visit_testable( self.visit_testable(
macro_def.ident.to_string(), macro_def.ident.to_string(),
&macro_def.attrs, &macro_def.attrs,
macro_def.hir_id, macro_def.hir_id(),
macro_def.span, macro_def.span,
|_| (), |_| (),
); );

View file

@ -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 // doesn't work with it anyway, so pull them from the HIR map instead
let mut extra_attrs = Vec::new(); let mut extra_attrs = Vec::new();
for &trait_did in cx.tcx.all_traits(LOCAL_CRATE).iter() { for &trait_did in cx.tcx.all_traits(LOCAL_CRATE).iter() {
for &impl_node in cx.tcx.hir().trait_impls(trait_did) { for &impl_did in cx.tcx.hir().trait_impls(trait_did) {
let impl_did = cx.tcx.hir().local_def_id(impl_node).to_def_id(); let impl_did = impl_did.to_def_id();
cx.tcx.sess.prof.generic_activity("build_local_trait_impl").run(|| { cx.tcx.sess.prof.generic_activity("build_local_trait_impl").run(|| {
let mut parent = cx.tcx.parent(impl_did); let mut parent = cx.tcx.parent(impl_did);
while let Some(did) = parent { while let Some(did) = parent {

View file

@ -89,7 +89,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
// (since a direct parent isn't necessarily a module, c.f. #77828). // (since a direct parent isn't necessarily a module, c.f. #77828).
let macro_parent_def_id = { let macro_parent_def_id = {
use rustc_middle::ty::DefIdTree; use rustc_middle::ty::DefIdTree;
tcx.parent(tcx.hir().local_def_id(def.hir_id).to_def_id()).unwrap() tcx.parent(def.def_id.to_def_id()).unwrap()
}; };
let macro_parent_path = tcx.def_path(macro_parent_def_id); let macro_parent_path = tcx.def_path(macro_parent_def_id);
// HACK: rustdoc has no way to lookup `doctree::Module`s by their HirId. Instead, // HACK: rustdoc has no way to lookup `doctree::Module`s by their HirId. Instead,
@ -132,8 +132,8 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
// Keep track of if there were any private modules in the path. // Keep track of if there were any private modules in the path.
let orig_inside_public_path = self.inside_public_path; let orig_inside_public_path = self.inside_public_path;
self.inside_public_path &= vis.node.is_pub(); self.inside_public_path &= vis.node.is_pub();
for i in m.item_ids { for &i in m.item_ids {
let item = self.cx.tcx.hir().expect_item(i.id); let item = self.cx.tcx.hir().item(i);
self.visit_item(item, None, &mut om); self.visit_item(item, None, &mut om);
} }
self.inside_public_path = orig_inside_public_path; self.inside_public_path = orig_inside_public_path;
@ -231,8 +231,8 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
let ret = match tcx.hir().get(res_hir_id) { let ret = match tcx.hir().get(res_hir_id) {
Node::Item(&hir::Item { kind: hir::ItemKind::Mod(ref m), .. }) if glob => { Node::Item(&hir::Item { kind: hir::ItemKind::Mod(ref m), .. }) if glob => {
let prev = mem::replace(&mut self.inlining, true); let prev = mem::replace(&mut self.inlining, true);
for i in m.item_ids { for &i in m.item_ids {
let i = self.cx.tcx.hir().expect_item(i.id); let i = self.cx.tcx.hir().item(i);
self.visit_item(i, None, om); self.visit_item(i, None, om);
} }
self.inlining = prev; self.inlining = prev;
@ -270,8 +270,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
let name = renamed.unwrap_or(item.ident.name); let name = renamed.unwrap_or(item.ident.name);
if item.vis.node.is_pub() { if item.vis.node.is_pub() {
let def_id = self.cx.tcx.hir().local_def_id(item.hir_id); self.store_path(item.def_id.to_def_id());
self.store_path(def_id.to_def_id());
} }
match item.kind { match item.kind {
@ -305,7 +304,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
}); });
let ident = if is_glob { None } else { Some(name) }; let ident = if is_glob { None } else { Some(name) };
if self.maybe_inline_local( if self.maybe_inline_local(
item.hir_id, item.hir_id(),
path.res, path.res,
ident, ident,
is_glob, is_glob,
@ -322,7 +321,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
om.mods.push(self.visit_mod_contents( om.mods.push(self.visit_mod_contents(
item.span, item.span,
&item.vis, &item.vis,
item.hir_id, item.hir_id(),
m, m,
Some(name), Some(name),
)); ));

View file

@ -38,7 +38,7 @@ impl<'tcx> LateLintPass<'tcx> for CopyIterator {
.. ..
}) = item.kind }) = item.kind
{ {
let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id(item.hir_id)); let ty = cx.tcx.type_of(item.def_id);
if is_copy(cx, ty) && match_path(&trait_ref.path, &paths::ITERATOR) { if is_copy(cx, ty) && match_path(&trait_ref.path, &paths::ITERATOR) {
span_lint_and_note( span_lint_and_note(

View file

@ -169,7 +169,7 @@ impl<'tcx> LateLintPass<'tcx> for Derive {
.. ..
}) = item.kind }) = item.kind
{ {
let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id(item.hir_id)); let ty = cx.tcx.type_of(item.def_id);
let is_automatically_derived = is_automatically_derived(&*item.attrs); let is_automatically_derived = is_automatically_derived(&*item.attrs);
check_hash_peq(cx, item.span, trait_ref, ty, is_automatically_derived); check_hash_peq(cx, item.span, trait_ref, ty, is_automatically_derived);

View file

@ -216,18 +216,17 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
let headers = check_attrs(cx, &self.valid_idents, &item.attrs); let headers = check_attrs(cx, &self.valid_idents, &item.attrs);
match item.kind { match item.kind {
hir::ItemKind::Fn(ref sig, _, body_id) => { hir::ItemKind::Fn(ref sig, _, body_id) => {
if !(is_entrypoint_fn(cx, cx.tcx.hir().local_def_id(item.hir_id).to_def_id()) if !(is_entrypoint_fn(cx, item.def_id.to_def_id())
|| in_external_macro(cx.tcx.sess, item.span)) || in_external_macro(cx.tcx.sess, item.span))
{ {
let body = cx.tcx.hir().body(body_id); let body = cx.tcx.hir().body(body_id);
let impl_item_def_id = cx.tcx.hir().local_def_id(item.hir_id);
let mut fpu = FindPanicUnwrap { let mut fpu = FindPanicUnwrap {
cx, cx,
typeck_results: cx.tcx.typeck(impl_item_def_id), typeck_results: cx.tcx.typeck(item.def_id),
panic_span: None, panic_span: None,
}; };
fpu.visit_expr(&body.value); fpu.visit_expr(&body.value);
lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers, Some(body_id), fpu.panic_span); lint_for_missing_headers(cx, item.hir_id(), item.span, sig, headers, Some(body_id), fpu.panic_span);
} }
}, },
hir::ItemKind::Impl(ref impl_) => { hir::ItemKind::Impl(ref impl_) => {
@ -247,7 +246,7 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
let headers = check_attrs(cx, &self.valid_idents, &item.attrs); let headers = check_attrs(cx, &self.valid_idents, &item.attrs);
if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind { if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind {
if !in_external_macro(cx.tcx.sess, item.span) { if !in_external_macro(cx.tcx.sess, item.span) {
lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers, None, None); lint_for_missing_headers(cx, item.hir_id(), item.span, sig, headers, None, None);
} }
} }
} }
@ -259,14 +258,13 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
} }
if let hir::ImplItemKind::Fn(ref sig, body_id) = item.kind { if let hir::ImplItemKind::Fn(ref sig, body_id) = item.kind {
let body = cx.tcx.hir().body(body_id); let body = cx.tcx.hir().body(body_id);
let impl_item_def_id = cx.tcx.hir().local_def_id(item.hir_id);
let mut fpu = FindPanicUnwrap { let mut fpu = FindPanicUnwrap {
cx, cx,
typeck_results: cx.tcx.typeck(impl_item_def_id), typeck_results: cx.tcx.typeck(item.def_id),
panic_span: None, panic_span: None,
}; };
fpu.visit_expr(&body.value); fpu.visit_expr(&body.value);
lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers, Some(body_id), fpu.panic_span); lint_for_missing_headers(cx, item.hir_id(), item.span, sig, headers, Some(body_id), fpu.panic_span);
} }
} }
} }

View file

@ -49,9 +49,8 @@ impl<'tcx> LateLintPass<'tcx> for EmptyEnum {
return; return;
} }
let did = cx.tcx.hir().local_def_id(item.hir_id);
if let ItemKind::Enum(..) = item.kind { if let ItemKind::Enum(..) = item.kind {
let ty = cx.tcx.type_of(did); let ty = cx.tcx.type_of(item.def_id);
let adt = ty.ty_adt_def().expect("already checked whether this is an enum"); let adt = ty.ty_adt_def().expect("already checked whether this is an enum");
if adt.variants.is_empty() { if adt.variants.is_empty() {
span_lint_and_help( span_lint_and_help(

View file

@ -87,11 +87,11 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
// find `self` ty for this trait if relevant // find `self` ty for this trait if relevant
if let ItemKind::Trait(_, _, _, _, items) = item.kind { if let ItemKind::Trait(_, _, _, _, items) = item.kind {
for trait_item in items { for trait_item in items {
if trait_item.id.hir_id == hir_id { if trait_item.id.hir_id() == hir_id {
// be sure we have `self` parameter in this function // be sure we have `self` parameter in this function
if let AssocItemKind::Fn { has_self: true } = trait_item.kind { if let AssocItemKind::Fn { has_self: true } = trait_item.kind {
trait_self_ty = trait_self_ty =
Some(TraitRef::identity(cx.tcx, trait_item.id.hir_id.owner.to_def_id()).self_ty()); Some(TraitRef::identity(cx.tcx, trait_item.id.def_id.to_def_id()).self_ty());
} }
} }
} }

View file

@ -72,7 +72,7 @@ impl LateLintPass<'_> for ExhaustiveItems {
fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) { fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
if_chain! { if_chain! {
if let ItemKind::Enum(..) | ItemKind::Struct(..) = item.kind; if let ItemKind::Enum(..) | ItemKind::Struct(..) = item.kind;
if cx.access_levels.is_exported(item.hir_id); if cx.access_levels.is_exported(item.hir_id());
if !item.attrs.iter().any(|a| a.has_name(sym::non_exhaustive)); if !item.attrs.iter().any(|a| a.has_name(sym::non_exhaustive));
then { then {
let (lint, msg) = if let ItemKind::Struct(ref v, ..) = item.kind { let (lint, msg) = if let ItemKind::Struct(ref v, ..) = item.kind {

View file

@ -52,10 +52,9 @@ declare_lint_pass!(FallibleImplFrom => [FALLIBLE_IMPL_FROM]);
impl<'tcx> LateLintPass<'tcx> for FallibleImplFrom { impl<'tcx> LateLintPass<'tcx> for FallibleImplFrom {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
// check for `impl From<???> for ..` // check for `impl From<???> for ..`
let impl_def_id = cx.tcx.hir().local_def_id(item.hir_id);
if_chain! { if_chain! {
if let hir::ItemKind::Impl(impl_) = &item.kind; if let hir::ItemKind::Impl(impl_) = &item.kind;
if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(impl_def_id); if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(item.def_id);
if cx.tcx.is_diagnostic_item(sym::from_trait, impl_trait_ref.def_id); if cx.tcx.is_diagnostic_item(sym::from_trait, impl_trait_ref.def_id);
then { then {
lint_impl_body(cx, item.span, impl_.items); lint_impl_body(cx, item.span, impl_.items);
@ -117,10 +116,9 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[h
then { then {
// check the body for `begin_panic` or `unwrap` // check the body for `begin_panic` or `unwrap`
let body = cx.tcx.hir().body(body_id); let body = cx.tcx.hir().body(body_id);
let impl_item_def_id = cx.tcx.hir().local_def_id(impl_item.id.hir_id);
let mut fpu = FindPanicUnwrap { let mut fpu = FindPanicUnwrap {
lcx: cx, lcx: cx,
typeck_results: cx.tcx.typeck(impl_item_def_id), typeck_results: cx.tcx.typeck(impl_item.id.def_id),
result: Vec::new(), result: Vec::new(),
}; };
fpu.visit_expr(&body.value); fpu.visit_expr(&body.value);

View file

@ -60,10 +60,9 @@ impl LateLintPass<'_> for FromOverInto {
return; return;
} }
let impl_def_id = cx.tcx.hir().local_def_id(item.hir_id);
if_chain! { if_chain! {
if let hir::ItemKind::Impl{ .. } = &item.kind; if let hir::ItemKind::Impl{ .. } = &item.kind;
if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(impl_def_id); if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(item.def_id);
if match_def_path(cx, impl_trait_ref.def_id, &INTO); if match_def_path(cx, impl_trait_ref.def_id, &INTO);
then { then {

View file

@ -283,13 +283,13 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
let attr = must_use_attr(&item.attrs); let attr = must_use_attr(&item.attrs);
if let hir::ItemKind::Fn(ref sig, ref _generics, ref body_id) = item.kind { if let hir::ItemKind::Fn(ref sig, ref _generics, ref body_id) = item.kind {
let is_public = cx.access_levels.is_exported(item.hir_id); let is_public = cx.access_levels.is_exported(item.hir_id());
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
if is_public { if is_public {
check_result_unit_err(cx, &sig.decl, item.span, fn_header_span); check_result_unit_err(cx, &sig.decl, item.span, fn_header_span);
} }
if let Some(attr) = attr { if let Some(attr) = attr {
check_needless_must_use(cx, &sig.decl, item.hir_id, item.span, fn_header_span, attr); check_needless_must_use(cx, &sig.decl, item.hir_id(), item.span, fn_header_span, attr);
return; return;
} }
if is_public && !is_proc_macro(cx.sess(), &item.attrs) && attr_by_name(&item.attrs, "no_mangle").is_none() { if is_public && !is_proc_macro(cx.sess(), &item.attrs) && attr_by_name(&item.attrs, "no_mangle").is_none() {
@ -298,7 +298,7 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
&sig.decl, &sig.decl,
cx.tcx.hir().body(*body_id), cx.tcx.hir().body(*body_id),
item.span, item.span,
item.hir_id, item.hir_id(),
item.span.with_hi(sig.decl.output.span().hi()), item.span.with_hi(sig.decl.output.span().hi()),
"this function could have a `#[must_use]` attribute", "this function could have a `#[must_use]` attribute",
); );
@ -308,24 +308,24 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) {
if let hir::ImplItemKind::Fn(ref sig, ref body_id) = item.kind { if let hir::ImplItemKind::Fn(ref sig, ref body_id) = item.kind {
let is_public = cx.access_levels.is_exported(item.hir_id); let is_public = cx.access_levels.is_exported(item.hir_id());
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
if is_public && trait_ref_of_method(cx, item.hir_id).is_none() { if is_public && trait_ref_of_method(cx, item.hir_id()).is_none() {
check_result_unit_err(cx, &sig.decl, item.span, fn_header_span); check_result_unit_err(cx, &sig.decl, item.span, fn_header_span);
} }
let attr = must_use_attr(&item.attrs); let attr = must_use_attr(&item.attrs);
if let Some(attr) = attr { if let Some(attr) = attr {
check_needless_must_use(cx, &sig.decl, item.hir_id, item.span, fn_header_span, attr); check_needless_must_use(cx, &sig.decl, item.hir_id(), item.span, fn_header_span, attr);
} else if is_public } else if is_public
&& !is_proc_macro(cx.sess(), &item.attrs) && !is_proc_macro(cx.sess(), &item.attrs)
&& trait_ref_of_method(cx, item.hir_id).is_none() && trait_ref_of_method(cx, item.hir_id()).is_none()
{ {
check_must_use_candidate( check_must_use_candidate(
cx, cx,
&sig.decl, &sig.decl,
cx.tcx.hir().body(*body_id), cx.tcx.hir().body(*body_id),
item.span, item.span,
item.hir_id, item.hir_id(),
item.span.with_hi(sig.decl.output.span().hi()), item.span.with_hi(sig.decl.output.span().hi()),
"this method could have a `#[must_use]` attribute", "this method could have a `#[must_use]` attribute",
); );
@ -339,7 +339,7 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
if sig.header.abi == Abi::Rust { if sig.header.abi == Abi::Rust {
self.check_arg_number(cx, &sig.decl, item.span.with_hi(sig.decl.output.span().hi())); self.check_arg_number(cx, &sig.decl, item.span.with_hi(sig.decl.output.span().hi()));
} }
let is_public = cx.access_levels.is_exported(item.hir_id); let is_public = cx.access_levels.is_exported(item.hir_id());
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
if is_public { if is_public {
check_result_unit_err(cx, &sig.decl, item.span, fn_header_span); check_result_unit_err(cx, &sig.decl, item.span, fn_header_span);
@ -347,11 +347,11 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
let attr = must_use_attr(&item.attrs); let attr = must_use_attr(&item.attrs);
if let Some(attr) = attr { if let Some(attr) = attr {
check_needless_must_use(cx, &sig.decl, item.hir_id, item.span, fn_header_span, attr); check_needless_must_use(cx, &sig.decl, item.hir_id(), item.span, fn_header_span, attr);
} }
if let hir::TraitFn::Provided(eid) = *eid { if let hir::TraitFn::Provided(eid) = *eid {
let body = cx.tcx.hir().body(eid); let body = cx.tcx.hir().body(eid);
Self::check_raw_ptr(cx, sig.header.unsafety, &sig.decl, body, item.hir_id); Self::check_raw_ptr(cx, sig.header.unsafety, &sig.decl, body, item.hir_id());
if attr.is_none() && is_public && !is_proc_macro(cx.sess(), &item.attrs) { if attr.is_none() && is_public && !is_proc_macro(cx.sess(), &item.attrs) {
check_must_use_candidate( check_must_use_candidate(
@ -359,7 +359,7 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
&sig.decl, &sig.decl,
body, body,
item.span, item.span,
item.hir_id, item.hir_id(),
item.span.with_hi(sig.decl.output.span().hi()), item.span.with_hi(sig.decl.output.span().hi()),
"this method could have a `#[must_use]` attribute", "this method could have a `#[must_use]` attribute",
); );

View file

@ -59,20 +59,15 @@ impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl {
// but filter out implementations that have generic params (type or lifetime) // but filter out implementations that have generic params (type or lifetime)
// or are derived from a macro // or are derived from a macro
if !in_macro(item.span) && generics.params.is_empty() { if !in_macro(item.span) && generics.params.is_empty() {
self.impls.insert(item.hir_id.owner.to_def_id(), item.span); self.impls.insert(item.def_id.to_def_id(), item.span);
} }
} }
} }
fn check_crate_post(&mut self, cx: &LateContext<'tcx>, krate: &'tcx Crate<'_>) { fn check_crate_post(&mut self, cx: &LateContext<'tcx>, krate: &'tcx Crate<'_>) {
if let Some(item) = krate.items.values().next() { if !krate.items.is_empty() {
// Retrieve all inherent implementations from the crate, grouped by type // Retrieve all inherent implementations from the crate, grouped by type
for impls in cx for impls in cx.tcx.crate_inherent_impls(def_id::LOCAL_CRATE).inherent_impls.values() {
.tcx
.crate_inherent_impls(item.hir_id.owner.to_def_id().krate)
.inherent_impls
.values()
{
// Filter out implementations that have generic params (type or lifetime) // Filter out implementations that have generic params (type or lifetime)
let mut impl_spans = impls.iter().filter_map(|impl_def| self.impls.get(impl_def)); let mut impl_spans = impls.iter().filter_map(|impl_def| self.impls.get(impl_def));
if let Some(initial_span) = impl_spans.next() { if let Some(initial_span) = impl_spans.next() {

View file

@ -108,10 +108,10 @@ impl<'tcx> LateLintPass<'tcx> for InherentToString {
if decl.inputs.len() == 1; if decl.inputs.len() == 1;
// Check if return type is String // Check if return type is String
if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id), sym::string_type); if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::string_type);
// Filters instances of to_string which are required by a trait // Filters instances of to_string which are required by a trait
if trait_ref_of_method(cx, impl_item.hir_id).is_none(); if trait_ref_of_method(cx, impl_item.hir_id()).is_none();
then { then {
show_lint(cx, impl_item); show_lint(cx, impl_item);
@ -124,8 +124,7 @@ fn show_lint(cx: &LateContext<'_>, item: &ImplItem<'_>) {
let display_trait_id = get_trait_def_id(cx, &paths::DISPLAY_TRAIT).expect("Failed to get trait ID of `Display`!"); let display_trait_id = get_trait_def_id(cx, &paths::DISPLAY_TRAIT).expect("Failed to get trait ID of `Display`!");
// Get the real type of 'self' // Get the real type of 'self'
let fn_def_id = cx.tcx.hir().local_def_id(item.hir_id); let self_type = cx.tcx.fn_sig(item.def_id).input(0);
let self_type = cx.tcx.fn_sig(fn_def_id).input(0);
let self_type = self_type.skip_binder().peel_refs(); let self_type = self_type.skip_binder().peel_refs();
// Emit either a warning or an error // Emit either a warning or an error

View file

@ -62,9 +62,8 @@ impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant {
if in_external_macro(cx.tcx.sess, item.span) { if in_external_macro(cx.tcx.sess, item.span) {
return; return;
} }
let did = cx.tcx.hir().local_def_id(item.hir_id);
if let ItemKind::Enum(ref def, _) = item.kind { if let ItemKind::Enum(ref def, _) = item.kind {
let ty = cx.tcx.type_of(did); let ty = cx.tcx.type_of(item.def_id);
let adt = ty.ty_adt_def().expect("already checked whether this is an enum"); let adt = ty.ty_adt_def().expect("already checked whether this is an enum");
let mut largest_variant: Option<(_, _)> = None; let mut largest_variant: Option<(_, _)> = None;

View file

@ -159,10 +159,7 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, trait_items
fn is_named_self(cx: &LateContext<'_>, item: &TraitItemRef, name: &str) -> bool { fn is_named_self(cx: &LateContext<'_>, item: &TraitItemRef, name: &str) -> bool {
item.ident.name.as_str() == name item.ident.name.as_str() == name
&& if let AssocItemKind::Fn { has_self } = item.kind { && if let AssocItemKind::Fn { has_self } = item.kind {
has_self && { has_self && { cx.tcx.fn_sig(item.id.def_id).inputs().skip_binder().len() == 1 }
let did = cx.tcx.hir().local_def_id(item.id.hir_id);
cx.tcx.fn_sig(did).inputs().skip_binder().len() == 1
}
} else { } else {
false false
} }
@ -177,10 +174,9 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, trait_items
} }
} }
if cx.access_levels.is_exported(visited_trait.hir_id) && trait_items.iter().any(|i| is_named_self(cx, i, "len")) { if cx.access_levels.is_exported(visited_trait.hir_id()) && trait_items.iter().any(|i| is_named_self(cx, i, "len")) {
let mut current_and_super_traits = FxHashSet::default(); let mut current_and_super_traits = FxHashSet::default();
let visited_trait_def_id = cx.tcx.hir().local_def_id(visited_trait.hir_id); fill_trait_set(visited_trait.def_id.to_def_id(), &mut current_and_super_traits, cx);
fill_trait_set(visited_trait_def_id.to_def_id(), &mut current_and_super_traits, cx);
let is_empty_method_found = current_and_super_traits let is_empty_method_found = current_and_super_traits
.iter() .iter()
@ -210,17 +206,14 @@ fn check_impl_items(cx: &LateContext<'_>, item: &Item<'_>, impl_items: &[ImplIte
fn is_named_self(cx: &LateContext<'_>, item: &ImplItemRef<'_>, name: &str) -> bool { fn is_named_self(cx: &LateContext<'_>, item: &ImplItemRef<'_>, name: &str) -> bool {
item.ident.name.as_str() == name item.ident.name.as_str() == name
&& if let AssocItemKind::Fn { has_self } = item.kind { && if let AssocItemKind::Fn { has_self } = item.kind {
has_self && { has_self && cx.tcx.fn_sig(item.id.def_id).inputs().skip_binder().len() == 1
let did = cx.tcx.hir().local_def_id(item.id.hir_id);
cx.tcx.fn_sig(did).inputs().skip_binder().len() == 1
}
} else { } else {
false false
} }
} }
let is_empty = if let Some(is_empty) = impl_items.iter().find(|i| is_named_self(cx, i, "is_empty")) { let is_empty = if let Some(is_empty) = impl_items.iter().find(|i| is_named_self(cx, i, "is_empty")) {
if cx.access_levels.is_exported(is_empty.id.hir_id) { if cx.access_levels.is_exported(is_empty.id.hir_id()) {
return; return;
} }
"a private" "a private"
@ -229,9 +222,8 @@ fn check_impl_items(cx: &LateContext<'_>, item: &Item<'_>, impl_items: &[ImplIte
}; };
if let Some(i) = impl_items.iter().find(|i| is_named_self(cx, i, "len")) { if let Some(i) = impl_items.iter().find(|i| is_named_self(cx, i, "len")) {
if cx.access_levels.is_exported(i.id.hir_id) { if cx.access_levels.is_exported(i.id.hir_id()) {
let def_id = cx.tcx.hir().local_def_id(item.hir_id); let ty = cx.tcx.type_of(item.def_id);
let ty = cx.tcx.type_of(def_id);
span_lint( span_lint(
cx, cx,

View file

@ -87,7 +87,7 @@ impl<'tcx> LateLintPass<'tcx> for Lifetimes {
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) {
if let ImplItemKind::Fn(ref sig, id) = item.kind { if let ImplItemKind::Fn(ref sig, id) = item.kind {
let report_extra_lifetimes = trait_ref_of_method(cx, item.hir_id).is_none(); let report_extra_lifetimes = trait_ref_of_method(cx, item.hir_id()).is_none();
check_fn_inner( check_fn_inner(
cx, cx,
&sig.decl, &sig.decl,
@ -375,7 +375,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> {
match ty.kind { match ty.kind {
TyKind::OpaqueDef(item, _) => { TyKind::OpaqueDef(item, _) => {
let map = self.cx.tcx.hir(); let map = self.cx.tcx.hir();
let item = map.expect_item(item.id); let item = map.item(item);
walk_item(self, item); walk_item(self, item);
walk_ty(self, ty); walk_ty(self, ty);
}, },

View file

@ -102,7 +102,7 @@ fn future_trait_ref<'tcx>(
) -> Option<(&'tcx TraitRef<'tcx>, Vec<LifetimeName>)> { ) -> Option<(&'tcx TraitRef<'tcx>, Vec<LifetimeName>)> {
if_chain! { if_chain! {
if let TyKind::OpaqueDef(item_id, bounds) = ty.kind; if let TyKind::OpaqueDef(item_id, bounds) = ty.kind;
let item = cx.tcx.hir().item(item_id.id); let item = cx.tcx.hir().item(item_id);
if let ItemKind::OpaqueTy(opaque) = &item.kind; if let ItemKind::OpaqueTy(opaque) = &item.kind;
if let Some(trait_ref) = opaque.bounds.iter().find_map(|bound| { if let Some(trait_ref) = opaque.bounds.iter().find_map(|bound| {
if let GenericBound::Trait(poly, _) = bound { if let GenericBound::Trait(poly, _) = bound {

View file

@ -1685,10 +1685,9 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
return; return;
} }
let name = impl_item.ident.name.as_str(); let name = impl_item.ident.name.as_str();
let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id); let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id());
let item = cx.tcx.hir().expect_item(parent); let item = cx.tcx.hir().expect_item(parent);
let def_id = cx.tcx.hir().local_def_id(item.hir_id); let self_ty = cx.tcx.type_of(item.def_id);
let self_ty = cx.tcx.type_of(def_id);
// if this impl block implements a trait, lint in trait definition instead // if this impl block implements a trait, lint in trait definition instead
if let hir::ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }) = item.kind { if let hir::ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }) = item.kind {
@ -1699,8 +1698,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
if let hir::ImplItemKind::Fn(ref sig, id) = impl_item.kind; if let hir::ImplItemKind::Fn(ref sig, id) = impl_item.kind;
if let Some(first_arg) = iter_input_pats(&sig.decl, cx.tcx.hir().body(id)).next(); if let Some(first_arg) = iter_input_pats(&sig.decl, cx.tcx.hir().body(id)).next();
let method_def_id = cx.tcx.hir().local_def_id(impl_item.hir_id); let method_sig = cx.tcx.fn_sig(impl_item.def_id);
let method_sig = cx.tcx.fn_sig(method_def_id);
let method_sig = cx.tcx.erase_late_bound_regions(method_sig); let method_sig = cx.tcx.erase_late_bound_regions(method_sig);
let first_arg_ty = &method_sig.inputs().iter().next(); let first_arg_ty = &method_sig.inputs().iter().next();
@ -1709,7 +1707,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
if let Some(first_arg_ty) = first_arg_ty; if let Some(first_arg_ty) = first_arg_ty;
then { then {
if cx.access_levels.is_exported(impl_item.hir_id) { if cx.access_levels.is_exported(impl_item.hir_id()) {
// check missing trait implementations // check missing trait implementations
for method_config in &TRAIT_METHODS { for method_config in &TRAIT_METHODS {
if name == method_config.method_name && if name == method_config.method_name &&
@ -1751,7 +1749,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
} }
if let hir::ImplItemKind::Fn(_, _) = impl_item.kind { if let hir::ImplItemKind::Fn(_, _) = impl_item.kind {
let ret_ty = return_ty(cx, impl_item.hir_id); let ret_ty = return_ty(cx, impl_item.hir_id());
// walk the return type and check for Self (this does not check associated types) // walk the return type and check for Self (this does not check associated types)
if contains_ty(ret_ty, self_ty) { if contains_ty(ret_ty, self_ty) {
@ -1792,7 +1790,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
if let Some(first_arg_ty) = sig.decl.inputs.iter().next(); if let Some(first_arg_ty) = sig.decl.inputs.iter().next();
let first_arg_span = first_arg_ty.span; let first_arg_span = first_arg_ty.span;
let first_arg_ty = hir_ty_to_ty(cx.tcx, first_arg_ty); let first_arg_ty = hir_ty_to_ty(cx.tcx, first_arg_ty);
let self_ty = TraitRef::identity(cx.tcx, item.hir_id.owner.to_def_id()).self_ty(); let self_ty = TraitRef::identity(cx.tcx, item.def_id.to_def_id()).self_ty();
then { then {
lint_wrong_self_convention(cx, &item.ident.name.as_str(), false, self_ty, first_arg_ty, first_arg_span); lint_wrong_self_convention(cx, &item.ident.name.as_str(), false, self_ty, first_arg_ty, first_arg_span);
@ -1802,8 +1800,8 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
if_chain! { if_chain! {
if item.ident.name == sym::new; if item.ident.name == sym::new;
if let TraitItemKind::Fn(_, _) = item.kind; if let TraitItemKind::Fn(_, _) = item.kind;
let ret_ty = return_ty(cx, item.hir_id); let ret_ty = return_ty(cx, item.hir_id());
let self_ty = TraitRef::identity(cx.tcx, item.hir_id.owner.to_def_id()).self_ty(); let self_ty = TraitRef::identity(cx.tcx, item.def_id.to_def_id()).self_ty();
if !contains_ty(ret_ty, self_ty); if !contains_ty(ret_ty, self_ty);
then { then {

Some files were not shown because too many files have changed in this diff Show more