Only store a LocalDefId in hir::Item.

Items are guaranteed to be HIR owner.
This commit is contained in:
Camille GILLOT 2021-01-30 17:47:51 +01:00
parent bd3cd5dbed
commit cebbba081e
86 changed files with 483 additions and 565 deletions

View File

@ -197,7 +197,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
node_ids
.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()
}
@ -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);
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(
@ -557,7 +566,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let vis = this.rebuild_vis(&vis);
this.insert_item(hir::Item {
hir_id: new_id,
def_id: new_id.expect_owner(),
ident,
attrs,
kind,
@ -629,7 +638,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
this.lower_use_tree(use_tree, &prefix, id, &mut vis, &mut ident, attrs);
this.insert_item(hir::Item {
hir_id: new_hir_id,
def_id: new_hir_id.expect_owner(),
ident,
attrs,
kind,

View File

@ -606,10 +606,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
fn insert_item(&mut self, item: hir::Item<'hir>) -> hir::ItemId {
let id = item.hir_id;
// FIXME: Use `debug_asset-rt`.
assert_eq!(id.local_id, hir::ItemLocalId::from_u32(0));
let id = hir::ItemId { id };
let id = hir::ItemId { def_id: item.def_id };
self.items.insert(id, item);
self.modules.get_mut(&self.current_module).unwrap().items.insert(id);
id
@ -1549,11 +1546,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
};
trace!("lower_opaque_impl_trait: {:#?}", opaque_ty_def_id);
let opaque_ty_id =
lctx.generate_opaque_type(opaque_ty_node_id, opaque_ty_item, span, opaque_ty_span);
lctx.generate_opaque_type(opaque_ty_def_id, opaque_ty_item, span, opaque_ty_span);
// `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)
})
}
@ -1561,17 +1557,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
/// returns the lowered node-ID for the opaque type.
fn generate_opaque_type(
&mut self,
opaque_ty_node_id: NodeId,
opaque_ty_id: LocalDefId,
opaque_ty_item: hir::OpaqueTy<'hir>,
span: Span,
opaque_ty_span: Span,
) -> hir::HirId {
) {
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.
trace!("registering opaque type with id {:#?}", opaque_ty_id);
let opaque_ty_item = hir::Item {
hir_id: opaque_ty_id,
def_id: opaque_ty_id,
ident: Ident::invalid(),
attrs: Default::default(),
kind: opaque_ty_item_kind,
@ -1583,7 +1578,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// automatically for all AST items. But this opaque type item
// does not actually exist in the AST.
self.insert_item(opaque_ty_item);
opaque_ty_id
}
fn lifetimes_from_impl_trait_bounds(
@ -2012,7 +2006,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// grow.
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
// idea is that we create a lifetime parameter for each
// lifetime in the return type. So, given a return type
@ -2063,10 +2057,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
};
trace!("exist ty from async fn def id: {:#?}", opaque_ty_def_id);
let opaque_ty_id =
this.generate_opaque_type(opaque_ty_node_id, opaque_ty_item, span, opaque_ty_span);
this.generate_opaque_type(opaque_ty_def_id, opaque_ty_item, span, opaque_ty_span);
(opaque_ty_id, lifetime_params)
lifetime_params
});
// As documented above on the variable
@ -2109,7 +2102,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// Foo = impl Trait` is, internally, created as a child of the
// async fn, so the *type parameters* are inherited. It's
// 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);
hir::FnRetTy::Return(self.arena.alloc(opaque_ty))
}
@ -2434,7 +2428,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let mut ids: SmallVec<[hir::Stmt<'hir>; 1]> = item_ids
.into_iter()
.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))
})
.collect();

View File

@ -237,7 +237,7 @@ impl<'hir> pprust_hir::PpAnn for IdentifiedAnnotation<'hir> {
pprust_hir::AnnNode::Name(_) => {}
pprust_hir::AnnNode::Item(item) => {
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) => {
s.s.space();

View File

@ -2543,12 +2543,13 @@ impl VariantData<'hir> {
// so it can fetched later.
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Encodable, Debug, Hash)]
pub struct ItemId {
pub id: HirId,
pub def_id: LocalDefId,
}
impl ItemId {
pub fn hir_id(&self) -> HirId {
self.id
// Items are always HIR owners.
HirId::make_owner(self.def_id)
}
}
@ -2558,7 +2559,7 @@ impl ItemId {
#[derive(Debug)]
pub struct Item<'hir> {
pub ident: Ident,
pub hir_id: HirId,
pub def_id: LocalDefId,
pub attrs: &'hir [Attribute],
pub kind: ItemKind<'hir>,
pub vis: Visibility<'hir>,
@ -2566,8 +2567,13 @@ pub struct Item<'hir> {
}
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 { id: self.hir_id }
ItemId { def_id: self.def_id }
}
}
@ -2879,8 +2885,8 @@ impl<'hir> Node<'hir> {
pub fn hir_id(&self) -> Option<HirId> {
match self {
Node::Item(Item { hir_id, .. })
| Node::ForeignItem(ForeignItem { hir_id, .. })
Node::Item(Item { def_id, .. }) => Some(HirId::make_owner(*def_id)),
Node::ForeignItem(ForeignItem { hir_id, .. })
| Node::TraitItem(TraitItem { hir_id, .. })
| Node::ImplItem(ImplItem { hir_id, .. })
| Node::Field(StructField { hir_id, .. })
@ -2915,7 +2921,7 @@ mod size_asserts {
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>, 208);
rustc_data_structures::static_assert_size!(super::Item<'static>, 200);
rustc_data_structures::static_assert_size!(super::TraitItem<'static>, 152);
rustc_data_structures::static_assert_size!(super::ImplItem<'static>, 168);
rustc_data_structures::static_assert_size!(super::ForeignItem<'static>, 160);

View File

@ -18,6 +18,21 @@ pub struct HirId {
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 {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self)

View File

@ -565,16 +565,16 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
visitor.visit_ident(item.ident);
match item.kind {
ItemKind::ExternCrate(orig_name) => {
visitor.visit_id(item.hir_id);
visitor.visit_id(item.hir_id());
if let Some(orig_name) = orig_name {
visitor.visit_name(item.span, orig_name);
}
}
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) => {
visitor.visit_id(item.hir_id);
visitor.visit_id(item.hir_id());
visitor.visit_ty(typ);
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,
body_id,
item.span,
item.hir_id,
item.hir_id(),
),
ItemKind::Mod(ref module) => {
// `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 } => {
visitor.visit_id(item.hir_id);
visitor.visit_id(item.hir_id());
walk_list!(visitor, visit_foreign_item_ref, items);
}
ItemKind::GlobalAsm(_) => {
visitor.visit_id(item.hir_id);
visitor.visit_id(item.hir_id());
}
ItemKind::TyAlias(ref ty, ref generics) => {
visitor.visit_id(item.hir_id);
visitor.visit_id(item.hir_id());
visitor.visit_ty(ty);
visitor.visit_generics(generics)
}
ItemKind::OpaqueTy(OpaqueTy { ref generics, bounds, .. }) => {
visitor.visit_id(item.hir_id);
visitor.visit_id(item.hir_id());
walk_generics(visitor, generics);
walk_list!(visitor, visit_param_bound, bounds);
}
ItemKind::Enum(ref enum_definition, ref generics) => {
visitor.visit_generics(generics);
// `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 {
unsafety: _,
@ -622,7 +622,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
ref self_ty,
items,
}) => {
visitor.visit_id(item.hir_id);
visitor.visit_id(item.hir_id());
visitor.visit_generics(generics);
walk_list!(visitor, visit_trait_ref, of_trait);
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::Union(ref struct_definition, ref generics) => {
visitor.visit_generics(generics);
visitor.visit_id(item.hir_id);
visitor.visit_id(item.hir_id());
visitor.visit_variant_data(
struct_definition,
item.ident.name,
generics,
item.hir_id,
item.hir_id(),
item.span,
);
}
ItemKind::Trait(.., ref generics, bounds, trait_item_refs) => {
visitor.visit_id(item.hir_id);
visitor.visit_id(item.hir_id());
visitor.visit_generics(generics);
walk_list!(visitor, visit_param_bound, bounds);
walk_list!(visitor, visit_trait_item_ref, trait_item_refs);
}
ItemKind::TraitAlias(ref generics, bounds) => {
visitor.visit_id(item.hir_id);
visitor.visit_id(item.hir_id());
visitor.visit_generics(generics);
walk_list!(visitor, visit_param_bound, bounds);
}

View File

@ -35,11 +35,11 @@ impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for HirId {
}
impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ItemId {
type KeyType = (DefPathHash, ItemLocalId);
type KeyType = DefPathHash;
#[inline]
fn to_stable_hash_key(&self, hcx: &HirCtx) -> (DefPathHash, ItemLocalId) {
self.id.to_stable_hash_key(hcx)
fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash {
hcx.local_def_path_hash(self.def_id)
}
}
@ -91,7 +91,7 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for BodyId {
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ItemId {
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)
}
}
@ -178,7 +178,7 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ImplItem<'_> {
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for Item<'_> {
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| {
ident.name.hash_stable(hcx, hasher);

View File

@ -167,7 +167,7 @@ impl Visitor<'tcx> for IfThisChanged<'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);
}

View File

@ -450,7 +450,7 @@ impl DirtyCleanVisitor<'tcx> {
impl ItemLikeVisitor<'tcx> for DirtyCleanVisitor<'tcx> {
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
self.check_item(item.hir_id, item.span);
self.check_item(item.hir_id(), item.span);
}
fn visit_trait_item(&mut self, item: &hir::TraitItem<'_>) {

View File

@ -26,7 +26,7 @@ struct Finder<'tcx> {
impl<'v> ItemLikeVisitor<'v> for Finder<'_> {
fn visit_item(&mut self, item: &hir::Item<'_>) {
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_hir as hir;
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::{HirId, HirIdSet, Node};
use rustc_hir::{HirId, Node};
use rustc_index::vec::Idx;
use rustc_middle::lint::LintDiagnosticBuilder;
use rustc_middle::ty::print::with_no_trimmed_paths;
@ -173,8 +173,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxPointers {
| hir::ItemKind::Enum(..)
| hir::ItemKind::Struct(..)
| 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(def_id))
self.check_heap_type(cx, it.span, cx.tcx.type_of(it.def_id))
}
_ => (),
}
@ -585,7 +584,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
hir::ItemKind::Trait(.., trait_item_refs) => {
// Issue #11592: traits are always considered exported, even when private.
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 {
self.private_traits.insert(trait_item_ref.id.hir_id);
}
@ -621,10 +620,9 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
_ => return,
};
let def_id = cx.tcx.hir().local_def_id(it.hir_id);
let (article, desc) = cx.tcx.article_and_description(def_id.to_def_id());
let (article, desc) = cx.tcx.article_and_description(it.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<'_>) {
@ -732,7 +730,7 @@ declare_lint_pass!(MissingCopyImplementations => [MISSING_COPY_IMPLEMENTATIONS])
impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations {
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;
}
let (def, ty) = match item.kind {
@ -740,21 +738,21 @@ impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations {
if !ast_generics.params.is_empty() {
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(&[])))
}
hir::ItemKind::Union(_, ref ast_generics) => {
if !ast_generics.params.is_empty() {
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(&[])))
}
hir::ItemKind::Enum(_, ref ast_generics) => {
if !ast_generics.params.is_empty() {
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(&[])))
}
_ => return,
@ -812,14 +810,14 @@ declare_lint! {
#[derive(Default)]
pub struct MissingDebugImplementations {
impling_types: Option<HirIdSet>,
impling_types: Option<LocalDefIdSet>,
}
impl_lint_pass!(MissingDebugImplementations => [MISSING_DEBUG_IMPLEMENTATIONS]);
impl<'tcx> LateLintPass<'tcx> for MissingDebugImplementations {
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;
}
@ -834,11 +832,11 @@ impl<'tcx> LateLintPass<'tcx> for MissingDebugImplementations {
};
if self.impling_types.is_none() {
let mut impls = HirIdSet::default();
let mut impls = LocalDefIdSet::default();
cx.tcx.for_each_impl(debug, |d| {
if let Some(ty_def) = cx.tcx.type_of(d).ty_adt_def() {
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 +845,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDebugImplementations {
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| {
lint.build(&format!(
"type does not implement `{}`; consider adding `#[derive(Debug)]` \
@ -1362,7 +1360,7 @@ impl UnreachablePub {
impl<'tcx> LateLintPass<'tcx> for UnreachablePub {
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>) {
@ -1603,8 +1601,7 @@ impl<'tcx> LateLintPass<'tcx> for TrivialConstraints {
use rustc_middle::ty::PredicateKind::*;
if cx.tcx.features().trivial_bounds {
let def_id = cx.tcx.hir().local_def_id(item.hir_id);
let predicates = cx.tcx.predicates_of(def_id);
let predicates = cx.tcx.predicates_of(item.def_id);
for &(predicate, span) in predicates.predicates {
let predicate_kind_name = match predicate.kind().skip_binder() {
Trait(..) => "Trait",
@ -1810,7 +1807,7 @@ declare_lint! {
}
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,
}
@ -1828,7 +1825,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnameableTestItems {
if let hir::ItemKind::Mod(..) = it.kind {
} else {
self.items_nameable = false;
self.boundary = Some(it.hir_id);
self.boundary = Some(it.def_id);
}
return;
}
@ -1841,7 +1838,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnameableTestItems {
}
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;
}
}
@ -2125,7 +2122,7 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
use rustc_middle::middle::resolve_lifetime::Region;
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)
| hir::ItemKind::Enum(_, ref hir_generics)
| hir::ItemKind::Union(_, ref hir_generics) = item.kind

View File

@ -142,8 +142,8 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
self.context.generics = it.kind.generics();
let old_cached_typeck_results = self.context.cached_typeck_results.take();
let old_enclosing_body = self.context.enclosing_body.take();
self.with_lint_attrs(it.hir_id, &it.attrs, |cx| {
cx.with_param_env(it.hir_id, |cx| {
self.with_lint_attrs(it.hir_id(), &it.attrs, |cx| {
cx.with_param_env(it.hir_id(), |cx| {
lint_callback!(cx, check_item, it);
hir_visit::walk_item(cx, it);
lint_callback!(cx, check_item_post, it);

View File

@ -577,7 +577,7 @@ impl<'tcx> intravisit::Visitor<'tcx> for LintLevelMapBuilder<'_, '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);
});
}

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>) {
use rustc_middle::ty::PredicateKind::*;
let def_id = cx.tcx.hir().local_def_id(item.hir_id);
let predicates = cx.tcx.explicit_predicates_of(def_id);
let predicates = cx.tcx.explicit_predicates_of(item.def_id);
for &(predicate, span) in predicates.predicates {
let trait_predicate = match predicate.kind().skip_binder() {
Trait(trait_predicate, _constness) => trait_predicate,

View File

@ -1308,8 +1308,7 @@ declare_lint_pass!(VariantSizeDifferences => [VARIANT_SIZE_DIFFERENCES]);
impl<'tcx> LateLintPass<'tcx> for VariantSizeDifferences {
fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
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(item_def_id);
let t = cx.tcx.type_of(it.def_id);
let ty = cx.tcx.erase_regions(t);
let layout = match cx.layout_of(ty) {
Ok(layout) => layout,

View File

@ -23,10 +23,7 @@ impl ItemLikeVisitor<'tcx> for Collector<'tcx> {
let foreign_items =
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: self.tcx.hir().local_def_id(it.hir_id).to_def_id(),
});
self.modules.push(ForeignModule { foreign_items, def_id: it.def_id.to_def_id() });
}
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,
kind: NativeLibKind::Unspecified,
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,
};
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_hir as hir;
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::intravisit::{self, NestedVisitorMap, Visitor};
use rustc_hir::itemlikevisit::ItemLikeVisitor;
@ -431,7 +433,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
fn encode_info_for_items(&mut self) {
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
// up using `proc_macro_data`
@ -932,9 +934,8 @@ impl EncodeContext<'a, 'tcx> {
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 local_def_id = tcx.hir().local_def_id(id);
let def_id = local_def_id.to_def_id();
debug!("EncodeContext::encode_info_for_mod({:?})", def_id);
@ -969,7 +970,7 @@ impl EncodeContext<'a, 'tcx> {
record!(self.tables.children[def_id] <- &[]);
} else {
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))
}
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::GlobalAsm(..) => EntryKind::GlobalAsm,
@ -1850,10 +1851,9 @@ impl Visitor<'tcx> for EncodeContext<'a, 'tcx> {
}
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
intravisit::walk_item(self, item);
let def_id = self.tcx.hir().local_def_id(item.hir_id);
match item.kind {
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);
}
@ -1920,7 +1920,6 @@ impl EncodeContext<'a, 'tcx> {
/// so it's easier to do that here then to wait until we would encounter
/// normally in the visitor walk.
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 {
hir::ItemKind::Static(..)
| hir::ItemKind::Const(..)
@ -1936,7 +1935,7 @@ impl EncodeContext<'a, 'tcx> {
// no sub-item recording needed in these cases
}
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);
for (i, variant) in def.variants.iter_enumerated() {
@ -1948,7 +1947,7 @@ impl EncodeContext<'a, 'tcx> {
}
}
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);
// If the struct has a constructor, encode it.
@ -1958,18 +1957,19 @@ impl EncodeContext<'a, 'tcx> {
}
}
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);
}
hir::ItemKind::Impl { .. } => {
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);
}
}
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);
}
}
@ -1985,15 +1985,14 @@ struct ImplVisitor<'tcx> {
impl<'tcx, 'v> ItemLikeVisitor<'v> for ImplVisitor<'tcx> {
fn visit_item(&mut self, item: &hir::Item<'_>) {
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(impl_id.to_def_id()) {
if let Some(trait_ref) = self.tcx.impl_trait_ref(item.def_id.to_def_id()) {
let simplified_self_ty =
ty::fast_reject::simplify_type(self.tcx, trait_ref.self_ty(), false);
self.impls
.entry(trait_ref.def_id)
.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 {
Node::Item(i) => match i.kind {
hir::ItemKind::Fn(ref sig, ref generics, block) => item_fn(ItemFnParts {
id: i.hir_id,
id: i.hir_id(),
ident: i.ident,
decl: &sig.decl,
body: block,

View File

@ -338,13 +338,10 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
fn visit_item(&mut self, i: &'hir Item<'hir>) {
debug!("visit_item: {:?}", i);
debug_assert_eq!(
i.hir_id.owner,
self.definitions.opt_hir_id_to_local_def_id(i.hir_id).unwrap()
);
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| {
self.with_dep_node_owner(i.def_id, i, |this, hash| {
let hir_id = i.hir_id();
this.insert_with_hash(i.span, hir_id, Node::Item(i), hash);
this.with_parent(hir_id, |this| {
if let ItemKind::Struct(ref struct_def, _) = i.kind {
// If this is a tuple or unit-like struct, register the constructor.
if let Some(ctor_hir_id) = struct_def.ctor_hir_id() {

View File

@ -301,7 +301,7 @@ impl<'hir> Map<'hir> {
}
pub fn item(&self, id: ItemId) -> &'hir Item<'hir> {
match self.find(id.id).unwrap() {
match self.find(id.hir_id()).unwrap() {
Node::Item(item) => item,
_ => bug!(),
}

View File

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

View File

@ -72,8 +72,7 @@ impl<'tcx> MonoItem<'tcx> {
MonoItem::Fn(instance) => tcx.symbol_name(instance),
MonoItem::Static(def_id) => tcx.symbol_name(Instance::mono(tcx, def_id)),
MonoItem::GlobalAsm(item_id) => {
let def_id = tcx.hir().local_def_id(item_id.hir_id());
SymbolName::new(tcx, &format!("global_asm_{:?}", def_id))
SymbolName::new(tcx, &format!("global_asm_{:?}", item_id.def_id))
}
}
}

View File

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

View File

@ -1013,13 +1013,12 @@ impl ItemLikeVisitor<'v> for RootCollector<'_, 'v> {
| hir::ItemKind::Union(_, ref generics) => {
if generics.params.is_empty() {
if self.mode == MonoItemCollectionMode::Eager {
let def_id = self.tcx.hir().local_def_id(item.hir_id);
debug!(
"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());
visit_drop_use(self.tcx, ty, true, DUMMY_SP, self.output);
}
@ -1028,29 +1027,28 @@ impl ItemLikeVisitor<'v> for RootCollector<'_, 'v> {
hir::ItemKind::GlobalAsm(..) => {
debug!(
"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.item_id())));
}
hir::ItemKind::Static(..) => {
let def_id = self.tcx.hir().local_def_id(item.hir_id).to_def_id();
debug!("RootCollector: ItemKind::Static({})", self.tcx.def_path_str(def_id));
self.output.push(dummy_spanned(MonoItem::Static(def_id)));
debug!(
"RootCollector: ItemKind::Static({})",
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(..) => {
// const items only generate mono items if they are
// actually used somewhere. Just declaring them is insufficient.
// 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(def_id.to_def_id()) {
if let Ok(val) = self.tcx.const_eval_poly(item.def_id.to_def_id()) {
collect_const_value(self.tcx, val, &mut self.output);
}
}
hir::ItemKind::Fn(..) => {
let def_id = self.tcx.hir().local_def_id(item.hir_id);
self.push_if_root(def_id);
self.push_if_root(item.def_id);
}
}
}
@ -1156,14 +1154,12 @@ fn create_mono_items_for_default_impls<'tcx>(
}
}
let impl_def_id = tcx.hir().local_def_id(item.hir_id);
debug!(
"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 trait_ref = tcx.normalize_erasing_regions(param_env, trait_ref);
let overridden_methods: FxHashSet<_> =

View File

@ -314,7 +314,7 @@ fn characteristic_def_id_of_mono_item<'tcx>(
Some(def_id)
}
MonoItem::Static(def_id) => Some(def_id),
MonoItem::GlobalAsm(item_id) => Some(tcx.hir().local_def_id(item_id.hir_id()).to_def_id()),
MonoItem::GlobalAsm(item_id) => Some(item_id.def_id.to_def_id()),
}
}
@ -406,10 +406,9 @@ fn mono_item_visibility(
};
}
MonoItem::GlobalAsm(item_id) => {
let def_id = tcx.hir().local_def_id(item_id.hir_id());
return if tcx.is_reachable_non_generic(def_id) {
return if tcx.is_reachable_non_generic(item_id.def_id) {
*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 {
Visibility::Hidden
};

View File

@ -1058,7 +1058,7 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
fn visit_item(&mut self, item: &'tcx Item<'tcx>) {
let target = Target::from_item(item);
self.check_attributes(
item.hir_id,
item.hir_id(),
item.attrs,
&item.span,
target,

View File

@ -188,8 +188,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
match node {
Node::Item(item) => match item.kind {
hir::ItemKind::Struct(..) | hir::ItemKind::Union(..) => {
let def_id = self.tcx.hir().local_def_id(item.hir_id);
let def = self.tcx.adt_def(def_id);
let def = self.tcx.adt_def(item.def_id);
self.repr_has_repr_c = def.repr.c();
intravisit::walk_item(self, &item);
@ -395,9 +394,10 @@ struct LifeSeeder<'k, 'tcx> {
impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
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 {
self.worklist.push(item.hir_id);
self.worklist.push(item.hir_id());
}
match item.kind {
hir::ItemKind::Enum(ref enum_def, _) => {
@ -413,7 +413,7 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
}
hir::ItemKind::Impl(hir::Impl { ref of_trait, items, .. }) => {
if of_trait.is_some() {
self.worklist.push(item.hir_id);
self.worklist.push(item.hir_id());
}
for impl_item_ref in items {
let impl_item = self.krate.impl_item(impl_item_ref.id);
@ -430,7 +430,7 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
}
hir::ItemKind::Struct(ref variant_data, _) => {
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());
}
}
_ => (),
@ -525,7 +525,7 @@ impl DeadVisitor<'tcx> {
| hir::ItemKind::Struct(..)
| 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 {
@ -627,7 +627,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> {
hir::ItemKind::Struct(..) => "constructed", // Issue #52325
_ => "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 {
// Only continue if we didn't warn
intravisit::walk_item(self, item);

View File

@ -27,7 +27,7 @@ struct DiagnosticItemCollector<'tcx> {
impl<'v, 'tcx> ItemLikeVisitor<'v> for DiagnosticItemCollector<'tcx> {
fn visit_item(&mut self, item: &hir::Item<'_>) {
self.observe_item(&item.attrs, item.hir_id);
self.observe_item(&item.attrs, item.hir_id());
}
fn visit_trait_item(&mut self, trait_item: &hir::TraitItem<'_>) {

View File

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

View File

@ -56,7 +56,7 @@ impl<'a, 'hir> OuterVisitor<'a, 'hir> {
impl<'a, 'hir> ItemLikeVisitor<'hir> for OuterVisitor<'a, 'hir> {
fn visit_item(&mut self, i: &'hir hir::Item<'hir>) {
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>) {

View File

@ -120,7 +120,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'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)
}

View File

@ -30,7 +30,7 @@ struct LanguageItemCollector<'tcx> {
impl ItemLikeVisitor<'v> for LanguageItemCollector<'tcx> {
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 {
for variant in def.variants {

View File

@ -21,16 +21,14 @@ struct LayoutTest<'tcx> {
impl ItemLikeVisitor<'tcx> for LayoutTest<'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 {
ItemKind::TyAlias(..)
| ItemKind::Enum(..)
| ItemKind::Struct(..)
| 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) {
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 {
hir::ItemKind::Fn(ref sig, ..) if sig.header.is_const() => true,
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)
}
_ => false,
@ -218,8 +218,7 @@ impl<'tcx> ReachableContext<'tcx> {
} else {
false
};
let def_id = self.tcx.hir().local_def_id(item.hir_id);
let codegen_attrs = self.tcx.codegen_fn_attrs(def_id);
let codegen_attrs = self.tcx.codegen_fn_attrs(item.def_id);
let is_extern = codegen_attrs.contains_extern_indicator();
let std_internal =
codegen_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL);
@ -239,9 +238,11 @@ impl<'tcx> ReachableContext<'tcx> {
Node::Item(item) => {
match item.kind {
hir::ItemKind::Fn(.., body) => {
let def_id = self.tcx.hir().local_def_id(item.hir_id);
if item_might_be_inlined(self.tcx, &item, self.tcx.codegen_fn_attrs(def_id))
{
if item_might_be_inlined(
self.tcx,
&item,
self.tcx.codegen_fn_attrs(item.def_id),
) {
self.visit_nested_body(body);
}
}
@ -341,19 +342,18 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, 'tcx
// Anything which has custom linkage gets thrown on the worklist no
// matter where it is in the crate, along with "special std 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(def_id);
let codegen_attrs = self.tcx.codegen_fn_attrs(item.def_id);
if codegen_attrs.contains_extern_indicator()
|| 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
if let hir::ItemKind::Impl(hir::Impl { of_trait: Some(ref trait_ref), ref items, .. }) =
item.kind
{
if !self.access_levels.is_reachable(item.hir_id) {
if !self.access_levels.is_reachable(item.hir_id()) {
// FIXME(#53488) remove `let`
let tcx = self.tcx;
self.worklist

View File

@ -376,7 +376,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
}
self.annotate(
i.hir_id,
i.hir_id(),
&i.attrs,
i.span,
kind,
@ -556,7 +556,7 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> {
hir::ItemKind::Impl(hir::Impl { of_trait: None, .. })
| 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
@ -564,7 +564,7 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> {
if self.tcx.features().staged_api
&& 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)
@ -712,13 +712,12 @@ impl Visitor<'tcx> for Checker<'tcx> {
return;
}
let def_id = self.tcx.hir().local_def_id(item.hir_id);
let cnum = match self.tcx.extern_mod_stmt_cnum(def_id) {
let cnum = match self.tcx.extern_mod_stmt_cnum(item.def_id) {
Some(cnum) => cnum,
None => return,
};
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
@ -744,7 +743,7 @@ impl Visitor<'tcx> for Checker<'tcx> {
.map_or(item.span, |a| a.span);
self.tcx.struct_span_lint_hir(
INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
item.hir_id,
item.hir_id(),
span,
|lint| lint
.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,
// so semi-randomly perform it here in stability.rs
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(def_id);
let ty = self.tcx.type_of(item.def_id);
let (adt_def, substs) = match ty.kind() {
ty::Adt(adt_def, substs) => (adt_def, substs),
_ => bug!(),
};
// 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 {
let field_ty = field.ty(self.tcx, substs);
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.
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_middle::ty::query::Providers;
use rustc_middle::ty::TyCtxt;
@ -10,14 +10,14 @@ use rustc_span::Span;
struct RegistrarFinder<'tcx> {
tcx: TyCtxt<'tcx>,
registrars: Vec<(hir::HirId, Span)>,
registrars: Vec<(LocalDefId, Span)>,
}
impl<'v, 'tcx> ItemLikeVisitor<'v> for RegistrarFinder<'tcx> {
fn visit_item(&mut self, item: &hir::Item<'_>) {
if let hir::ItemKind::Fn(..) = item.kind {
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() {
0 => None,
1 => {
let (hir_id, _) = finder.registrars.pop().unwrap();
Some(tcx.hir().local_def_id(hir_id).to_def_id())
let (def_id, _) = finder.registrars.pop().unwrap();
Some(def_id.to_def_id())
}
_ => {
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 = self.tcx.hir().get_module(module_def_id).0;
for item_id in module.item_ids {
let hir_id = item_id.id;
let item_def_id = self.tcx.hir().local_def_id(hir_id);
let def_kind = self.tcx.def_kind(item_def_id);
let vis = self.tcx.visibility(item_def_id);
self.update_macro_reachable_def(hir_id, def_kind, vis, defining_mod);
let def_kind = self.tcx.def_kind(item_id.def_id);
let vis = self.tcx.visibility(item_id.def_id);
self.update_macro_reachable_def(item_id.hir_id(), def_kind, vis, defining_mod);
}
if let Some(exports) = self.tcx.module_exports(module_def_id) {
for export in exports {
@ -590,12 +588,15 @@ impl EmbargoVisitor<'tcx> {
if let hir::ItemKind::Mod(m) = &item.kind {
for &item_id in m.item_ids {
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(segment.ident, item.ident, def_id.to_def_id()) {
if !self.tcx.hygienic_eq(
segment.ident,
item.ident,
item_id.def_id.to_def_id(),
) {
continue;
}
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>) {
let inherited_item_level = match item.kind {
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.
hir::ItemKind::ForeignMod { .. } => self.prev_level,
@ -644,7 +645,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
};
// 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.
match item.kind {
@ -727,7 +728,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
// reachable if they are returned via `impl Trait`, even from private functions.
let exist_level =
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.
@ -736,12 +737,12 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
| hir::ItemKind::Fn(..)
| hir::ItemKind::TyAlias(..) => {
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) => {
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 {
let mut reach = self.reach(trait_item_ref.id.hir_id, item_level);
@ -759,13 +760,13 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
}
hir::ItemKind::TraitAlias(..) => {
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.
hir::ItemKind::Impl(ref impl_) => {
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 {
let impl_item_level = self.get(impl_item_ref.id.hir_id);
@ -782,7 +783,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
// Visit everything, but enum variants have their own levels.
hir::ItemKind::Enum(ref def, _) => {
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 {
let variant_level = self.get(variant.id);
@ -792,7 +793,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
}
// Corner case: if the variant is reachable, but its
// enum is not, make the enum reachable as well.
self.update(item.hir_id, variant_level);
self.update(item.hir_id(), variant_level);
}
}
}
@ -811,7 +812,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
// Visit everything except for private fields.
hir::ItemKind::Struct(ref struct_def, _) | hir::ItemKind::Union(ref struct_def, _) => {
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() {
let field_level = self.get(field.hir_id);
if field_level.is_some() {
@ -1037,7 +1038,7 @@ impl<'tcx> Visitor<'tcx> for NamePrivacyVisitor<'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);
self.current_item = orig_current_item;
}
@ -1322,8 +1323,7 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
// Check types in item interfaces.
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
let orig_current_item =
mem::replace(&mut self.current_item, self.tcx.hir().local_def_id(item.hir_id));
let orig_current_item = mem::replace(&mut self.current_item, item.def_id);
let old_maybe_typeck_results = self.maybe_typeck_results.take();
intravisit::walk_item(self, item);
self.maybe_typeck_results = old_maybe_typeck_results;
@ -1463,7 +1463,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
hir::ItemKind::ForeignMod { .. } => {}
hir::ItemKind::Trait(.., ref bounds, _) => {
if !self.trait_is_public(item.hir_id) {
if !self.trait_is_public(item.hir_id()) {
return;
}
@ -1615,7 +1615,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
hir::ItemKind::TyAlias(..) => return,
// 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;
}
@ -1926,7 +1926,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx>
fn visit_item(&mut self, item: &'tcx hir::Item<'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 {
// Crates are always public.
@ -1942,15 +1942,15 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx>
| hir::ItemKind::Static(..)
| hir::ItemKind::Fn(..)
| 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(..) => {
// `ty()` for opaque types is the underlying type,
// 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) => {
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 {
self.check_assoc_item(
@ -1966,10 +1966,10 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx>
}
}
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, _) => {
self.check(item.hir_id, item_visibility).generics().predicates();
self.check(item.hir_id(), item_visibility).generics().predicates();
for variant in def.variants {
for field in variant.data.fields() {
@ -1986,7 +1986,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx>
}
// Subitems of structs and unions have their own publicity.
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() {
let field_visibility = tcx.visibility(tcx.hir().local_def_id(field.hir_id));
@ -1998,8 +1998,8 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx>
// A trait impl is public when both its type and its trait are public
// Subitems of trait impls have inherited publicity.
hir::ItemKind::Impl(ref impl_) => {
let impl_vis = ty::Visibility::of_impl(item.hir_id, tcx, &Default::default());
self.check(item.hir_id, impl_vis).generics().predicates();
let impl_vis = ty::Visibility::of_impl(item.hir_id(), tcx, &Default::default());
self.check(item.hir_id(), impl_vis).generics().predicates();
for impl_item_ref in impl_.items {
let impl_item_vis = if impl_.of_trait.is_none() {
min(

View File

@ -632,7 +632,8 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
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
let parent_id = self.tcx.hir().get_parent_node(hir_id);
let parent_item_id = hir::ItemId { id: parent_id };
let parent_item_id =
hir::ItemId { def_id: parent_id.expect_owner() };
let parent_impl_id = hir::ImplItemId { hir_id: parent_id };
let parent_trait_id = hir::TraitItemId { hir_id: parent_id };
let krate = self.tcx.hir().krate();
@ -1256,7 +1257,7 @@ fn compute_object_lifetime_defaults(tcx: TyCtxt<'_>) -> HirIdMap<Vec<ObjectLifet
tcx.sess.span_err(item.span, &object_lifetime_default_reprs);
}
map.insert(item.hir_id, result);
map.insert(item.hir_id(), result);
}
_ => {}
}

View File

@ -373,14 +373,14 @@ impl<'tcx> DumpVisitor<'tcx> {
body: hir::BodyId,
) {
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);
if let Some(fn_data) = v.save_ctxt.get_item_data(item) {
down_cast_data!(fn_data, DefData, item.span);
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 {
@ -401,10 +401,10 @@ impl<'tcx> DumpVisitor<'tcx> {
typ: &'tcx hir::Ty<'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) {
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_expr(expr);
@ -465,10 +465,7 @@ impl<'tcx> DumpVisitor<'tcx> {
) {
debug!("process_struct {:?} {:?}", item, item.span);
let name = item.ident.to_string();
let qualname = format!(
"::{}",
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.hir_id).to_def_id())
);
let qualname = format!("::{}", self.tcx.def_path_str(item.def_id.to_def_id()));
let kind = match item.kind {
hir::ItemKind::Struct(_, _) => DefKind::Struct,
@ -500,10 +497,10 @@ impl<'tcx> DumpVisitor<'tcx> {
if !self.span.filter_generated(item.ident.span) {
let span = self.span_from_span(item.ident.span);
self.dumper.dump_def(
&access_from!(self.save_ctxt, item, item.hir_id),
&access_from!(self.save_ctxt, item, item.hir_id()),
Def {
kind,
id: id_from_hir_id(item.hir_id, &self.save_ctxt),
id: id_from_def_id(item.def_id.to_def_id()),
span,
name,
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() {
v.process_struct_field_def(field, item.hir_id);
v.process_struct_field_def(field, item.hir_id());
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);
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 {
let name = variant.ident.name.to_string();
@ -556,7 +553,7 @@ impl<'tcx> DumpVisitor<'tcx> {
if !self.span.filter_generated(name_span) {
let span = self.span_from_span(name_span);
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(
&access,
@ -596,7 +593,7 @@ impl<'tcx> DumpVisitor<'tcx> {
if !self.span.filter_generated(name_span) {
let span = self.span_from_span(name_span);
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(
&access,
@ -627,7 +624,7 @@ impl<'tcx> DumpVisitor<'tcx> {
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);
}
@ -644,17 +641,14 @@ impl<'tcx> DumpVisitor<'tcx> {
}
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);
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_generic_params(&impl_.generics, "", item.hir_id);
v.process_generic_params(&impl_.generics, "", item.hir_id());
for impl_item in impl_.items {
v.process_impl_item(
map.impl_item(impl_item.id),
map.local_def_id(item.hir_id).to_def_id(),
);
v.process_impl_item(map.impl_item(impl_item.id), item.def_id.to_def_id());
}
});
}
@ -667,10 +661,7 @@ impl<'tcx> DumpVisitor<'tcx> {
methods: &'tcx [hir::TraitItemRef],
) {
let name = item.ident.to_string();
let qualname = format!(
"::{}",
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.hir_id).to_def_id())
);
let qualname = format!("::{}", self.tcx.def_path_str(item.def_id.to_def_id()));
let mut val = name.clone();
if !generics.params.is_empty() {
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));
}
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 children =
methods.iter().map(|i| id_from_hir_id(i.id.hir_id, &self.save_ctxt)).collect();
self.dumper.dump_def(
&access_from!(self.save_ctxt, item, item.hir_id),
&access_from!(self.save_ctxt, item, item.hir_id()),
Def {
kind: DefKind::Trait,
id,
@ -729,20 +720,17 @@ impl<'tcx> DumpVisitor<'tcx> {
kind: RelationKind::SuperTrait,
span,
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
self.process_generic_params(generics, &qualname, item.hir_id);
self.process_generic_params(generics, &qualname, item.hir_id());
for method in methods {
let map = &self.tcx.hir();
self.process_trait_item(
map.trait_item(method.id),
map.local_def_id(item.hir_id).to_def_id(),
)
self.process_trait_item(map.trait_item(method.id), item.def_id.to_def_id())
}
}
@ -750,7 +738,7 @@ impl<'tcx> DumpVisitor<'tcx> {
fn process_mod(&mut self, item: &'tcx hir::Item<'tcx>) {
if let Some(mod_data) = self.save_ctxt.get_item_data(item) {
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);
}
}
@ -1130,7 +1118,7 @@ impl<'tcx> DumpVisitor<'tcx> {
.module
.item_ids
.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();
let span = self.span_from_span(krate.item.span);
@ -1179,16 +1167,11 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
hir::ItemKind::Use(path, hir::UseKind::Single) => {
let sub_span = path.segments.last().unwrap().ident.span;
if !self.span.filter_generated(sub_span) {
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 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 span = self.span_from_span(sub_span);
let parent = self
.save_ctxt
.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);
let parent =
self.save_ctxt.tcx.parent(item.def_id.to_def_id()).map(id_from_def_id);
self.dumper.import(
&access,
Import {
@ -1206,23 +1189,17 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
}
hir::ItemKind::Use(path, hir::UseKind::Glob) => {
// 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(def_id);
let names = self.tcx.names_imported_by_glob_use(item.def_id);
let names: Vec<_> = names.iter().map(|n| n.to_string()).collect();
// 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`
if let Some(sub_span) = self.span.sub_span_of_star(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 parent = self
.save_ctxt
.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);
let parent =
self.save_ctxt.tcx.parent(item.def_id.to_def_id()).map(id_from_def_id);
self.dumper.import(
&access,
Import {
@ -1243,13 +1220,8 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
let name_span = item.ident.span;
if !self.span.filter_generated(name_span) {
let span = self.span_from_span(name_span);
let parent = self
.save_ctxt
.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);
let parent =
self.save_ctxt.tcx.parent(item.def_id.to_def_id()).map(id_from_def_id);
self.dumper.import(
&Access { public: false, reachable: false },
Import {
@ -1286,20 +1258,17 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
}
hir::ItemKind::Mod(ref m) => {
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) => {
let qualname = format!(
"::{}",
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.hir_id).to_def_id())
);
let qualname = format!("::{}", self.tcx.def_path_str(item.def_id.to_def_id()));
let value = ty_to_string(&ty);
if !self.span.filter_generated(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(
&access_from!(self.save_ctxt, item, item.hir_id),
&access_from!(self.save_ctxt, item, item.hir_id()),
Def {
kind: DefKind::Type,
id,
@ -1318,7 +1287,7 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
}
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),
}
@ -1383,9 +1352,7 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
}
hir::TyKind::OpaqueDef(item_id, _) => {
let item = self.tcx.hir().item(item_id);
self.nest_typeck_results(self.tcx.hir().local_def_id(item_id.id), |v| {
v.visit_item(item)
});
self.nest_typeck_results(item_id.def_id, |v| v.visit_item(item));
}
_ => intravisit::walk_ty(self, t),
}

View File

@ -201,7 +201,7 @@ impl<'tcx> SaveContext<'tcx> {
}
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 {
hir::ItemKind::Fn(ref sig, ref generics, _) => {
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),
value: filename.to_string(),
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,
docs: self.docs_for_attrs(&item.attrs),
sig: sig::item_signature(item, self),

View File

@ -318,7 +318,7 @@ impl<'hir> Sig for hir::Ty<'hir> {
}
hir::TyKind::OpaqueDef(item_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"),
}
@ -327,7 +327,7 @@ impl<'hir> Sig for hir::Ty<'hir> {
impl<'hir> Sig for hir::Item<'hir> {
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 {
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 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(),
end: offset + text.len() + name.len(),
}];
@ -359,7 +359,7 @@ impl<'hir> Sig for hir::Item<'hir> {
let mut text = "const ".to_owned();
let name = self.ident.to_string();
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(),
end: offset + text.len() + name.len(),
}];
@ -391,7 +391,7 @@ impl<'hir> Sig for hir::Item<'hir> {
text.push_str("fn ");
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('(');
for i in decl.inputs {
@ -420,7 +420,7 @@ impl<'hir> Sig for hir::Item<'hir> {
let mut text = "mod ".to_owned();
let name = self.ident.to_string();
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(),
end: offset + text.len() + name.len(),
}];
@ -433,7 +433,7 @@ impl<'hir> Sig for hir::Item<'hir> {
hir::ItemKind::TyAlias(ref ty, ref generics) => {
let text = "type ".to_owned();
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(" = ");
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) => {
let text = "enum ".to_owned();
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(" {}");
Ok(sig)
}
hir::ItemKind::Struct(_, ref generics) => {
let text = "struct ".to_owned();
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(" {}");
Ok(sig)
}
hir::ItemKind::Union(_, ref generics) => {
let text = "union ".to_owned();
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(" {}");
Ok(sig)
}
@ -475,7 +475,7 @@ impl<'hir> Sig for hir::Item<'hir> {
}
text.push_str("trait ");
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() {
sig.text.push_str(": ");
@ -490,7 +490,7 @@ impl<'hir> Sig for hir::Item<'hir> {
let mut text = String::new();
text.push_str("trait ");
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() {
sig.text.push_str(" = ");

View File

@ -227,6 +227,8 @@ pub struct LocalDefId {
pub local_def_index: DefIndex,
}
pub const CRATE_DEF_ID: LocalDefId = LocalDefId { local_def_index: CRATE_DEF_INDEX };
impl Idx for LocalDefId {
#[inline]
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 {
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
hcx.hash_def_id(*self, hasher)

View File

@ -61,7 +61,7 @@ impl SymbolNamesTest<'tcx> {
impl hir::itemlikevisit::ItemLikeVisitor<'tcx> for SymbolNamesTest<'tcx> {
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
self.process_attrs(item.hir_id);
self.process_attrs(item.hir_id());
}
fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) {

View File

@ -2211,7 +2211,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
}
hir::TyKind::OpaqueDef(item_id, ref lifetimes) => {
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 {
hir::ItemKind::OpaqueTy(hir::OpaqueTy { impl_trait_fn, .. }) => {

View File

@ -373,8 +373,7 @@ pub(super) fn check_fn<'a, 'tcx>(
(fcx, gen_ty)
}
pub(super) fn check_struct(tcx: TyCtxt<'_>, id: hir::HirId, span: Span) {
let def_id = tcx.hir().local_def_id(id);
fn check_struct(tcx: TyCtxt<'_>, def_id: LocalDefId, span: Span) {
let def = tcx.adt_def(def_id);
def.destructor(tcx); // force the destructor to be evaluated
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);
}
fn check_union(tcx: TyCtxt<'_>, id: hir::HirId, span: Span) {
let def_id = tcx.hir().local_def_id(id);
fn check_union(tcx: TyCtxt<'_>, def_id: LocalDefId, span: Span) {
let def = tcx.adt_def(def_id);
def.destructor(tcx); // force the destructor to be evaluated
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>) {
debug!(
"check_item_type(it.hir_id={}, it.name={})",
it.hir_id,
tcx.def_path_str(tcx.hir().local_def_id(it.hir_id).to_def_id())
"check_item_type(it.def_id={:?}, it.name={})",
it.def_id,
tcx.def_path_str(it.def_id.to_def_id())
);
let _indenter = indenter();
match it.kind {
// Consts can play a role in type-checking, so they are included here.
hir::ItemKind::Static(..) => {
let def_id = tcx.hir().local_def_id(it.hir_id);
tcx.ensure().typeck(def_id);
maybe_check_static_with_link_section(tcx, def_id, it.span);
check_static_inhabited(tcx, def_id, it.span);
tcx.ensure().typeck(it.def_id);
maybe_check_static_with_link_section(tcx, it.def_id, it.span);
check_static_inhabited(tcx, it.def_id, it.span);
}
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, _) => {
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::Impl(ref impl_) => {
debug!("ItemKind::Impl {} with id {}", it.ident, it.hir_id);
let impl_def_id = tcx.hir().local_def_id(it.hir_id);
if let Some(impl_trait_ref) = tcx.impl_trait_ref(impl_def_id) {
debug!("ItemKind::Impl {} with id {:?}", it.ident, it.def_id);
if let Some(impl_trait_ref) = tcx.impl_trait_ref(it.def_id) {
check_impl_items_against_trait(
tcx,
it.span,
impl_def_id,
it.def_id,
impl_trait_ref,
&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) => {
let def_id = tcx.hir().local_def_id(it.hir_id);
check_on_unimplemented(tcx, def_id.to_def_id(), it);
check_on_unimplemented(tcx, it.def_id.to_def_id(), it);
for item in items.iter() {
let item = tcx.hir().trait_item(item.id);
@ -733,13 +728,13 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) {
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 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(
tcx,
assoc_item,
assoc_item,
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 +742,10 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) {
}
}
hir::ItemKind::Struct(..) => {
check_struct(tcx, it.hir_id, it.span);
check_struct(tcx, it.def_id, it.span);
}
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, .. }) => {
// HACK(jynelson): trying to infer the type of `impl trait` breaks documenting
@ -758,16 +753,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!
// See https://github.com/rust-lang/rust/issues/75100
if !tcx.sess.opts.actually_rustdoc {
let def_id = tcx.hir().local_def_id(it.hir_id);
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
check_opaque(tcx, def_id, substs, it.span, &origin);
let substs = InternalSubsts::identity_for_item(tcx, it.def_id.to_def_id());
check_opaque(tcx, it.def_id, substs, it.span, &origin);
}
}
hir::ItemKind::TyAlias(..) => {
let def_id = tcx.hir().local_def_id(it.hir_id);
let pty_ty = tcx.type_of(def_id);
let generics = tcx.generics_of(def_id);
let pty_ty = tcx.type_of(it.def_id);
let generics = tcx.generics_of(it.def_id);
check_type_params_are_used(tcx, &generics, pty_ty);
}
hir::ItemKind::ForeignMod { abi, items } => {
@ -835,9 +827,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<'_>) {
let item_def_id = tcx.hir().local_def_id(item.hir_id);
// 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>(
@ -1345,13 +1336,12 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, sp: Span, adt: &'tcx ty
}
#[allow(trivial_numeric_casts)]
pub fn check_enum<'tcx>(
fn check_enum<'tcx>(
tcx: TyCtxt<'tcx>,
sp: Span,
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);
def.destructor(tcx); // force the destructor to be evaluated

View File

@ -11,7 +11,6 @@ use rustc_hir::intravisit;
use rustc_hir::lang_items::LangItem;
use rustc_hir::{ExprKind, Node, QPath};
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::print::with_crate_prefix;
use rustc_middle::ty::{
@ -1352,17 +1351,15 @@ fn compute_all_traits(tcx: TyCtxt<'_>) -> Vec<DefId> {
// Crate-local:
struct Visitor<'a, 'tcx> {
map: &'a hir_map::Map<'tcx>,
struct Visitor<'a> {
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>) {
match i.kind {
hir::ItemKind::Trait(..) | hir::ItemKind::TraitAlias(..) => {
let def_id = self.map.local_def_id(i.hir_id);
self.traits.push(def_id.to_def_id());
self.traits.push(i.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<'_>) {}
}
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:

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);
debug!(
"check_item_well_formed(it.hir_id={:?}, it.name={})",
item.hir_id,
"check_item_well_formed(it.def_id={:?}, it.name={})",
item.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`
hir::ItemKind::Impl(ref impl_) => {
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));
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);
@ -141,13 +141,13 @@ pub fn check_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) {
}
}
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, ..) => {
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, ..) => {
check_item_type(tcx, item.hir_id, ty.span, false);
check_item_type(tcx, item.hir_id(), ty.span, false);
}
hir::ItemKind::ForeignMod { items, .. } => {
for it in items.iter() {
@ -215,7 +215,7 @@ fn could_be_self(trait_def_id: LocalDefId, ty: &hir::Ty<'_>) -> bool {
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)) {
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,
@ -432,7 +432,7 @@ fn check_associated_item(
}
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<'_> {
@ -465,8 +465,7 @@ fn check_type_defn<'tcx, F>(
{
for_item(tcx, item).with_fcx(|fcx, fcx_tcx| {
let variants = lookup_fields(fcx);
let def_id = fcx.tcx.hir().local_def_id(item.hir_id);
let packed = fcx.tcx.adt_def(def_id).repr.packed();
let packed = fcx.tcx.adt_def(item.def_id).repr.packed();
for variant in &variants {
// 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.
true
} 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.
vec![]
@ -549,15 +548,13 @@ fn check_type_defn<'tcx, F>(
}
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(trait_def_id);
let trait_def = tcx.trait_def(item.def_id);
if trait_def.is_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!(
tcx.sess,
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, _| {
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![]
});
@ -665,14 +662,12 @@ fn check_impl<'tcx>(
debug!("check_impl: {:?}", item);
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 {
Some(ref ast_trait_ref) => {
// `#[rustc_reservation_impl]` impls are not real impls and
// therefore don't need to be WF (the trait's `Self: Trait` predicate
// 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 =
fcx.normalize_associated_types_in(ast_trait_ref.path.span, trait_ref);
let obligations = traits::wf::trait_obligations(
@ -688,7 +683,7 @@ fn check_impl<'tcx>(
}
}
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);
fcx.register_wf_obligation(
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>,
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) {
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);
let variances = tcx.variances_of(item_def_id);
let variances = tcx.variances_of(item.def_id);
let mut constrained_parameters: FxHashSet<_> = variances
.iter()
@ -1354,8 +1348,7 @@ impl Visitor<'tcx> for CheckTypeWellFormedVisitor<'tcx> {
fn visit_item(&mut self, i: &'tcx hir::Item<'tcx>) {
debug!("visit_item: {:?}", i);
let def_id = self.tcx.hir().local_def_id(i.hir_id);
self.tcx.ensure().check_item_well_formed(def_id);
self.tcx.ensure().check_item_well_formed(i.def_id);
hir_visit::walk_item(self, i);
}

View File

@ -28,7 +28,7 @@ impl ItemLikeVisitor<'v> for CheckVisitor<'tcx> {
return;
}
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> {
fn check_import(&self, id: hir::HirId, span: Span) {
let def_id = self.tcx.hir().local_def_id(id);
if !self.tcx.maybe_unused_trait_import(def_id) {
fn check_import(&self, item_id: hir::ItemId, span: Span) {
if !self.tcx.maybe_unused_trait_import(item_id.def_id) {
return;
}
if self.used_trait_imports.contains(&def_id) {
if self.used_trait_imports.contains(&item_id.def_id) {
return;
}
self.tcx.struct_span_lint_hir(lint::builtin::UNUSED_IMPORTS, id, span, |lint| {
let msg = if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
format!("unused import: `{}`", snippet)
} else {
"unused import".to_owned()
};
lint.build(&msg).emit();
});
self.tcx.struct_span_lint_hir(
lint::builtin::UNUSED_IMPORTS,
item_id.hir_id(),
span,
|lint| {
let msg = if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
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).
let mut crates_to_lint = vec![];
tcx.hir().krate().visit_all_item_likes(&mut CollectExternCrateVisitor {
tcx,
crates_to_lint: &mut crates_to_lint,
});
@ -189,8 +192,7 @@ fn unused_crates_lint(tcx: TyCtxt<'_>) {
}
}
struct CollectExternCrateVisitor<'a, 'tcx> {
tcx: TyCtxt<'tcx>,
struct CollectExternCrateVisitor<'a> {
crates_to_lint: &'a mut Vec<ExternCrateToLint>,
}
@ -211,12 +213,11 @@ struct ExternCrateToLint {
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<'_>) {
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 {
def_id: extern_crate_def_id.to_def_id(),
def_id: item.def_id.to_def_id(),
span: item.span,
orig_name,
warn_if_unused: !item.ident.as_str().starts_with('_'),

View File

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

View File

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

View File

@ -24,7 +24,6 @@ impl ItemLikeVisitor<'v> for OrphanChecker<'tcx> {
/// to prevent inundating the user with a bunch of similar error
/// reports.
fn visit_item(&mut self, item: &hir::Item<'_>) {
let def_id = self.tcx.hir().local_def_id(item.hir_id);
// "Trait" impl
if let hir::ItemKind::Impl(hir::Impl {
generics, of_trait: Some(ref tr), self_ty, ..
@ -32,13 +31,13 @@ impl ItemLikeVisitor<'v> for OrphanChecker<'tcx> {
{
debug!(
"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 sm = self.tcx.sess.source_map();
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(()) => {}
Err(traits::OrphanCheckErr::NonLocalInputType(tys)) => {
let mut err = struct_span_err!(

View File

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

View File

@ -247,7 +247,7 @@ impl Visitor<'tcx> for CollectItemTypesVisitor<'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);
intravisit::walk_item(self, item);
}
@ -714,10 +714,10 @@ fn is_param(tcx: TyCtxt<'_>, ast_ty: &hir::Ty<'_>, param_id: hir::HirId) -> bool
}
}
fn convert_item(tcx: TyCtxt<'_>, item_id: hir::HirId) {
let it = tcx.hir().expect_item(item_id);
debug!("convert: item {} with id {}", it.ident, it.hir_id);
let def_id = tcx.hir().local_def_id(item_id);
fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
let it = tcx.hir().item(item_id);
debug!("convert: item {} with id {}", it.ident, it.hir_id());
let def_id = item_id.def_id;
match it.kind {
// These don't define types.
@ -1122,7 +1122,7 @@ fn super_predicates_that_define_assoc_type(
let is_trait_alias = tcx.is_trait_alias(trait_def_id);
let superbounds2 = icx.type_parameter_bounds_in_generics(
generics,
item.hir_id,
item.hir_id(),
self_param_ty,
OnlySelfBounds(!is_trait_alias),
assoc_name,
@ -1446,12 +1446,12 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
//
// Something of a hack: use the node id for the trait, also as
// 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 {
index: 0,
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,
kind: ty::GenericParamDefKind::Type {
has_default: false,

View File

@ -582,10 +582,9 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
}
fn visit_item(&mut self, it: &'tcx Item<'tcx>) {
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.
if def_id.to_def_id() != self.def_id {
self.check(def_id);
if it.def_id.to_def_id() != self.def_id {
self.check(it.def_id);
intravisit::walk_item(self, it);
}
}

View File

@ -81,11 +81,10 @@ struct ImplWfCheck<'tcx> {
impl ItemLikeVisitor<'tcx> for ImplWfCheck<'tcx> {
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
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, impl_def_id, impl_.items);
enforce_impl_params_are_constrained(self.tcx, item.def_id, impl_.items);
enforce_impl_items_are_distinct(self.tcx, impl_.items);
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);
}
}
}

View File

@ -2,7 +2,6 @@ use rustc_data_structures::fx::FxHashMap;
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_hir::itemlikevisit::ItemLikeVisitor;
use rustc_hir::Node;
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst};
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_span::Span;
@ -53,16 +52,10 @@ pub struct InferVisitor<'cx, 'tcx> {
impl<'cx, 'tcx> ItemLikeVisitor<'tcx> for InferVisitor<'cx, 'tcx> {
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);
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();
match item.kind {
hir::ItemKind::Union(..) | hir::ItemKind::Enum(..) | hir::ItemKind::Struct(..) => {

View File

@ -14,12 +14,10 @@ struct OutlivesTest<'tcx> {
impl ItemLikeVisitor<'tcx> for OutlivesTest<'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"
// attribute and report an error with various results if found.
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);
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);
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<'_>) {
match item.kind {
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 {
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, _) => {
self.visit_node_helper(item.hir_id);
self.visit_node_helper(item.hir_id());
for variant in enum_def.variants {
if let hir::VariantData::Tuple(..) = variant.data {
@ -89,7 +89,7 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for ConstraintContext<'a, 'tcx> {
}
hir::ItemKind::Fn(..) => {
self.visit_node_helper(item.hir_id);
self.visit_node_helper(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> {
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 {
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 {
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, _) => {
self.add_inferreds_for_item(item.hir_id);
self.add_inferreds_for_item(item.hir_id());
for variant in enum_def.variants {
if let hir::VariantData::Tuple(..) = variant.data {
@ -150,7 +150,7 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for TermsContext<'a, 'tcx> {
}
hir::ItemKind::Fn(..) => {
self.add_inferreds_for_item(item.hir_id);
self.add_inferreds_for_item(item.hir_id());
}
_ => {}

View File

@ -14,12 +14,10 @@ struct VarianceTest<'tcx> {
impl ItemLikeVisitor<'tcx> for VarianceTest<'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"
// attribute and report an error with various results if found.
if self.tcx.has_attr(item_def_id.to_def_id(), sym::rustc_variance) {
let variances_of = self.tcx.variances_of(item_def_id);
if self.tcx.has_attr(item.def_id.to_def_id(), sym::rustc_variance) {
let variances_of = self.tcx.variances_of(item.def_id);
struct_span_err!(self.tcx.sess, item.span, E0208, "{:?}", variances_of).emit();
}
}

View File

@ -135,16 +135,15 @@ impl Clean<ExternalCrate> for CrateNum {
.filter_map(|&id| {
let item = cx.tcx.hir().item(id);
match item.kind {
hir::ItemKind::Mod(_) => as_primitive(Res::Def(
DefKind::Mod,
cx.tcx.hir().local_def_id(id.id).to_def_id(),
)),
hir::ItemKind::Mod(_) => {
as_primitive(Res::Def(DefKind::Mod, id.def_id.to_def_id()))
}
hir::ItemKind::Use(ref path, hir::UseKind::Single)
if item.vis.node.is_pub() =>
{
as_primitive(path.res).map(|(_, prim)| {
// 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,
@ -187,16 +186,13 @@ impl Clean<ExternalCrate> for CrateNum {
.filter_map(|&id| {
let item = cx.tcx.hir().item(id);
match item.kind {
hir::ItemKind::Mod(_) => as_keyword(Res::Def(
DefKind::Mod,
cx.tcx.hir().local_def_id(id.id).to_def_id(),
)),
hir::ItemKind::Mod(_) => {
as_keyword(Res::Def(DefKind::Mod, id.def_id.to_def_id()))
}
hir::ItemKind::Use(ref path, hir::UseKind::Single)
if item.vis.node.is_pub() =>
{
as_keyword(path.res).map(|(_, prim)| {
(cx.tcx.hir().local_def_id(id.id).to_def_id(), prim)
})
as_keyword(path.res).map(|(_, prim)| (id.def_id.to_def_id(), prim))
}
_ => None,
}
@ -912,7 +908,7 @@ fn clean_fn_or_proc_macro(
}
None => {
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 =
if is_const_fn(cx.tcx, def_id) && is_unstable_const_fn(cx.tcx, def_id).is_none() {
hir::Constness::Const
@ -1950,8 +1946,8 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Symbol>) {
use hir::ItemKind;
let (item, renamed) = self;
let def_id = cx.tcx.hir().local_def_id(item.hir_id).to_def_id();
let mut name = renamed.unwrap_or_else(|| cx.tcx.hir().name(item.hir_id));
let def_id = item.def_id.to_def_id();
let mut name = renamed.unwrap_or_else(|| cx.tcx.hir().name(item.hir_id()));
cx.with_param_env(def_id, || {
let kind = match item.kind {
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_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
ItemKind::Fn(ref sig, ref generics, body_id) => {
clean_fn_or_proc_macro(item, sig, generics, body_id, &mut name, cx)
@ -2107,8 +2103,7 @@ fn clean_extern_crate(
cx: &DocContext<'_>,
) -> Vec<Item> {
// 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(def_id).unwrap_or(LOCAL_CRATE);
let cnum = cx.tcx.extern_mod_stmt_cnum(krate.def_id).unwrap_or(LOCAL_CRATE);
// this is the ID of the crate itself
let crate_def_id = DefId { krate: cnum, index: CRATE_DEF_INDEX };
let please_inline = krate.vis.node.is_pub()
@ -2127,7 +2122,7 @@ fn clean_extern_crate(
if let Some(items) = inline::try_inline(
cx,
cx.tcx.parent_module(krate.hir_id).to_def_id(),
cx.tcx.parent_module(krate.hir_id()).to_def_id(),
res,
name,
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
// 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 inner = if kind == hir::UseKind::Glob {
if !denied {
@ -2221,14 +2215,14 @@ fn clean_use_statement(
if let Some(mut items) = inline::try_inline(
cx,
cx.tcx.parent_module(import.hir_id).to_def_id(),
cx.tcx.parent_module(import.hir_id()).to_def_id(),
path.res,
name,
Some(import.attrs),
&mut visited,
) {
items.push(Item::from_def_id_and_parts(
def_id,
import.def_id.to_def_id(),
None,
ImportItem(Import::new_simple(name, resolve_use_source(cx, path), false)),
cx,
@ -2239,7 +2233,7 @@ fn clean_use_statement(
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>) {

View File

@ -1050,7 +1050,7 @@ impl<'a, 'hir, 'tcx> intravisit::Visitor<'hir> for HirCollector<'a, 'hir, 'tcx>
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);
});
}

View File

@ -270,8 +270,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
let name = renamed.unwrap_or(item.ident.name);
if item.vis.node.is_pub() {
let def_id = self.cx.tcx.hir().local_def_id(item.hir_id);
self.store_path(def_id.to_def_id());
self.store_path(item.def_id.to_def_id());
}
match item.kind {
@ -305,7 +304,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
});
let ident = if is_glob { None } else { Some(name) };
if self.maybe_inline_local(
item.hir_id,
item.hir_id(),
path.res,
ident,
is_glob,
@ -322,7 +321,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
om.mods.push(self.visit_mod_contents(
item.span,
&item.vis,
item.hir_id,
item.hir_id(),
m,
Some(name),
));

View File

@ -38,7 +38,7 @@ impl<'tcx> LateLintPass<'tcx> for CopyIterator {
..
}) = 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) {
span_lint_and_note(

View File

@ -169,7 +169,7 @@ impl<'tcx> LateLintPass<'tcx> for Derive {
..
}) = 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);
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);
match item.kind {
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))
{
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 {
cx,
typeck_results: cx.tcx.typeck(impl_item_def_id),
typeck_results: cx.tcx.typeck(item.def_id),
panic_span: None,
};
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_) => {

View File

@ -49,9 +49,8 @@ impl<'tcx> LateLintPass<'tcx> for EmptyEnum {
return;
}
let did = cx.tcx.hir().local_def_id(item.hir_id);
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");
if adt.variants.is_empty() {
span_lint_and_help(

View File

@ -72,7 +72,7 @@ impl LateLintPass<'_> for ExhaustiveItems {
fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
if_chain! {
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));
then {
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 {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
// check for `impl From<???> for ..`
let impl_def_id = cx.tcx.hir().local_def_id(item.hir_id);
if_chain! {
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);
then {
lint_impl_body(cx, item.span, impl_.items);

View File

@ -60,10 +60,9 @@ impl LateLintPass<'_> for FromOverInto {
return;
}
let impl_def_id = cx.tcx.hir().local_def_id(item.hir_id);
if_chain! {
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);
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<'_>) {
let attr = must_use_attr(&item.attrs);
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());
if is_public {
check_result_unit_err(cx, &sig.decl, item.span, fn_header_span);
}
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;
}
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,
cx.tcx.hir().body(*body_id),
item.span,
item.hir_id,
item.hir_id(),
item.span.with_hi(sig.decl.output.span().hi()),
"this function 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)
// or are derived from a macro
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<'_>) {
if let Some(item) = krate.items.values().next() {
if !krate.items.is_empty() {
// Retrieve all inherent implementations from the crate, grouped by type
for impls in cx
.tcx
.crate_inherent_impls(item.hir_id.owner.to_def_id().krate)
.inherent_impls
.values()
{
for impls in cx.tcx.crate_inherent_impls(def_id::LOCAL_CRATE).inherent_impls.values() {
// 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));
if let Some(initial_span) = impl_spans.next() {

View File

@ -62,9 +62,8 @@ impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant {
if in_external_macro(cx.tcx.sess, item.span) {
return;
}
let did = cx.tcx.hir().local_def_id(item.hir_id);
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 mut largest_variant: Option<(_, _)> = None;

View File

@ -177,10 +177,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 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
.iter()
@ -230,8 +229,7 @@ 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 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(def_id);
let ty = cx.tcx.type_of(item.def_id);
span_lint(
cx,

View File

@ -1687,8 +1687,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
let name = impl_item.ident.name.as_str();
let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id);
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(def_id);
let self_ty = cx.tcx.type_of(item.def_id);
// if this impl block implements a trait, lint in trait definition instead
if let hir::ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }) = item.kind {

View File

@ -135,8 +135,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
hir::ItemKind::Fn(..) => {
// ignore main()
if it.ident.name == sym::main {
let def_id = it.hir_id.owner;
let def_key = cx.tcx.hir().def_key(def_id);
let def_key = cx.tcx.hir().def_key(it.def_id);
if def_key.parent == Some(hir::def_id::CRATE_DEF_INDEX) {
return;
}
@ -159,8 +158,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
| hir::ItemKind::Use(..) => return,
};
let def_id = cx.tcx.hir().local_def_id(it.hir_id);
let (article, desc) = cx.tcx.article_and_description(def_id.to_def_id());
let (article, desc) = cx.tcx.article_and_description(it.def_id.to_def_id());
self.check_missing_docs_attrs(cx, &it.attrs, it.span, article, desc);
}

View File

@ -87,7 +87,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
return;
}
if !cx.access_levels.is_exported(it.hir_id) {
if !cx.access_levels.is_exported(it.hir_id()) {
return;
}
match it.kind {

View File

@ -57,7 +57,7 @@ declare_lint_pass!(MutableKeyType => [ MUTABLE_KEY_TYPE ]);
impl<'tcx> LateLintPass<'tcx> for MutableKeyType {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
if let hir::ItemKind::Fn(ref sig, ..) = item.kind {
check_sig(cx, item.hir_id, &sig.decl);
check_sig(cx, item.hir_id(), &sig.decl);
}
}

View File

@ -5,11 +5,12 @@
use crate::utils::{is_automatically_derived, snippet_opt, span_lint_and_then};
use if_chain::if_chain;
use rustc_errors::Applicability;
use rustc_hir::{BindingAnnotation, BorrowKind, Expr, ExprKind, HirId, Item, Mutability, Pat, PatKind};
use rustc_hir::{BindingAnnotation, BorrowKind, Expr, ExprKind, Item, Mutability, Pat, PatKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty;
use rustc_middle::ty::adjustment::{Adjust, Adjustment};
use rustc_session::{declare_tool_lint, impl_lint_pass};
use rustc_span::def_id::LocalDefId;
declare_clippy_lint! {
/// **What it does:** Checks for address of operations (`&`) that are going to
@ -35,7 +36,7 @@ declare_clippy_lint! {
#[derive(Default)]
pub struct NeedlessBorrow {
derived_item: Option<HirId>,
derived_item: Option<LocalDefId>,
}
impl_lint_pass!(NeedlessBorrow => [NEEDLESS_BORROW]);
@ -117,13 +118,13 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrow {
fn check_item(&mut self, _: &LateContext<'tcx>, item: &'tcx Item<'_>) {
if is_automatically_derived(item.attrs) {
debug_assert!(self.derived_item.is_none());
self.derived_item = Some(item.hir_id);
self.derived_item = Some(item.def_id);
}
}
fn check_item_post(&mut self, _: &LateContext<'tcx>, item: &'tcx Item<'_>) {
if let Some(id) = self.derived_item {
if item.hir_id == id {
if item.def_id == id {
self.derived_item = None;
}
}

View File

@ -124,7 +124,7 @@ declare_lint_pass!(Ptr => [PTR_ARG, CMP_NULL, MUT_FROM_REF]);
impl<'tcx> LateLintPass<'tcx> for Ptr {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
if let ItemKind::Fn(ref sig, _, body_id) = item.kind {
check_fn(cx, &sig.decl, item.hir_id, Some(body_id));
check_fn(cx, &sig.decl, item.hir_id(), Some(body_id));
}
}

View File

@ -42,11 +42,10 @@ impl_lint_pass!(RedundantPubCrate => [REDUNDANT_PUB_CRATE]);
impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
if let VisibilityKind::Crate { .. } = item.vis.node {
if !cx.access_levels.is_exported(item.hir_id) {
if !cx.access_levels.is_exported(item.hir_id()) {
if let Some(false) = self.is_exported.last() {
let span = item.span.with_hi(item.ident.span.hi());
let def_id = cx.tcx.hir().local_def_id(item.hir_id);
let descr = cx.tcx.def_kind(def_id).descr(def_id.to_def_id());
let descr = cx.tcx.def_kind(item.def_id).descr(item.def_id.to_def_id());
span_lint_and_then(
cx,
REDUNDANT_PUB_CRATE,
@ -66,7 +65,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate {
}
if let ItemKind::Mod { .. } = item.kind {
self.is_exported.push(cx.access_levels.is_exported(item.hir_id));
self.is_exported.push(cx.access_levels.is_exported(item.hir_id()));
}
}

View File

@ -1106,7 +1106,9 @@ fn is_empty_block(expr: &Expr<'_>) -> bool {
expr.kind,
ExprKind::Block(
Block {
stmts: &[], expr: None, ..
stmts: &[],
expr: None,
..
},
_,
)
@ -2565,7 +2567,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher {
}
}
if !cx.access_levels.is_exported(item.hir_id) {
if !cx.access_levels.is_exported(item.hir_id()) {
return;
}

View File

@ -196,8 +196,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
item_path,
cx,
};
let impl_def_id = cx.tcx.hir().local_def_id(item.hir_id);
let impl_trait_ref = cx.tcx.impl_trait_ref(impl_def_id);
let impl_trait_ref = cx.tcx.impl_trait_ref(item.def_id);
if let Some(impl_trait_ref) = impl_trait_ref {
for impl_item_ref in impl_.items {

View File

@ -370,7 +370,7 @@ fn print_expr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, indent: usize) {
}
fn print_item(cx: &LateContext<'_>, item: &hir::Item<'_>) {
let did = cx.tcx.hir().local_def_id(item.hir_id);
let did = item.def_id;
println!("item `{}`", item.ident.name);
match item.vis.node {
hir::VisibilityKind::Public => println!("public"),
@ -383,8 +383,7 @@ fn print_item(cx: &LateContext<'_>, item: &hir::Item<'_>) {
}
match item.kind {
hir::ItemKind::ExternCrate(ref _renamed_from) => {
let def_id = cx.tcx.hir().local_def_id(item.hir_id);
if let Some(crate_id) = cx.tcx.extern_mod_stmt_cnum(def_id) {
if let Some(crate_id) = cx.tcx.extern_mod_stmt_cnum(did) {
let source = cx.tcx.used_crate_source(crate_id);
if let Some(ref src) = source.dylib {
println!("extern crate dylib source: {:?}", src.0);

View File

@ -113,7 +113,7 @@ impl LateLintPass<'_> for WildcardImports {
if_chain! {
if let ItemKind::Use(use_path, UseKind::Glob) = &item.kind;
if self.warn_on_all || !self.check_exceptions(item, use_path.segments);
let used_imports = cx.tcx.names_imported_by_glob_use(item.hir_id.owner);
let used_imports = cx.tcx.names_imported_by_glob_use(item.def_id);
if !used_imports.is_empty(); // Already handled by `unused_imports`
then {
let mut applicability = Applicability::MachineApplicable;