separate definitions and HIR owners

fix a ui test

use `into`

fix clippy ui test

fix a run-make-fulldeps test

implement `IntoQueryParam<DefId>` for `OwnerId`

use `OwnerId` for more queries

change the type of `ParentOwnerIterator::Item` to `(OwnerId, OwnerNode)`
This commit is contained in:
Takayuki Maeda 2022-09-20 14:11:23 +09:00
parent bb5a016175
commit 8fe936099a
114 changed files with 659 additions and 518 deletions

View File

@ -237,7 +237,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// Wrap the expression in an AnonConst. // Wrap the expression in an AnonConst.
let parent_def_id = self.current_hir_id_owner; let parent_def_id = self.current_hir_id_owner;
let node_id = self.next_node_id(); let node_id = self.next_node_id();
self.create_def(parent_def_id, node_id, DefPathData::AnonConst); self.create_def(parent_def_id.def_id, node_id, DefPathData::AnonConst);
let anon_const = AnonConst { id: node_id, value: P(expr) }; let anon_const = AnonConst { id: node_id, value: P(expr) };
hir::InlineAsmOperand::SymFn { hir::InlineAsmOperand::SymFn {
anon_const: self.lower_anon_const(&anon_const), anon_const: self.lower_anon_const(&anon_const),

View File

@ -359,7 +359,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let node_id = self.next_node_id(); let node_id = self.next_node_id();
// Add a definition for the in-band const def. // Add a definition for the in-band const def.
self.create_def(parent_def_id, node_id, DefPathData::AnonConst); self.create_def(parent_def_id.def_id, node_id, DefPathData::AnonConst);
let anon_const = AnonConst { id: node_id, value: arg }; let anon_const = AnonConst { id: node_id, value: arg };
generic_args.push(AngleBracketedArg::Arg(GenericArg::Const(anon_const))); generic_args.push(AngleBracketedArg::Arg(GenericArg::Const(anon_const)));

View File

@ -24,7 +24,7 @@ pub(super) struct NodeCollector<'a, 'hir> {
/// The parent of this node /// The parent of this node
parent_node: hir::ItemLocalId, parent_node: hir::ItemLocalId,
owner: LocalDefId, owner: OwnerId,
definitions: &'a definitions::Definitions, definitions: &'a definitions::Definitions,
} }
@ -81,9 +81,9 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?})", current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?})",
self.source_map.span_to_diagnostic_string(span), self.source_map.span_to_diagnostic_string(span),
node, node,
self.definitions.def_path(self.owner).to_string_no_crate_verbose(), self.definitions.def_path(self.owner.def_id).to_string_no_crate_verbose(),
self.owner, self.owner,
self.definitions.def_path(hir_id.owner).to_string_no_crate_verbose(), self.definitions.def_path(hir_id.owner.def_id).to_string_no_crate_verbose(),
hir_id.owner, hir_id.owner,
) )
} }
@ -112,19 +112,19 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
fn visit_nested_item(&mut self, item: ItemId) { fn visit_nested_item(&mut self, item: ItemId) {
debug!("visit_nested_item: {:?}", item); debug!("visit_nested_item: {:?}", item);
self.insert_nested(item.def_id); self.insert_nested(item.def_id.def_id);
} }
fn visit_nested_trait_item(&mut self, item_id: TraitItemId) { fn visit_nested_trait_item(&mut self, item_id: TraitItemId) {
self.insert_nested(item_id.def_id); self.insert_nested(item_id.def_id.def_id);
} }
fn visit_nested_impl_item(&mut self, item_id: ImplItemId) { fn visit_nested_impl_item(&mut self, item_id: ImplItemId) {
self.insert_nested(item_id.def_id); self.insert_nested(item_id.def_id.def_id);
} }
fn visit_nested_foreign_item(&mut self, foreign_id: ForeignItemId) { fn visit_nested_foreign_item(&mut self, foreign_id: ForeignItemId) {
self.insert_nested(foreign_id.def_id); self.insert_nested(foreign_id.def_id.def_id);
} }
fn visit_nested_body(&mut self, id: BodyId) { fn visit_nested_body(&mut self, id: BodyId) {

View File

@ -68,7 +68,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
bodies: Vec::new(), bodies: Vec::new(),
attrs: SortedMap::default(), attrs: SortedMap::default(),
children: FxHashMap::default(), children: FxHashMap::default(),
current_hir_id_owner: CRATE_DEF_ID, current_hir_id_owner: hir::CRATE_OWNER_ID,
item_local_id_counter: hir::ItemLocalId::new(0), item_local_id_counter: hir::ItemLocalId::new(0),
node_id_to_local_id: Default::default(), node_id_to_local_id: Default::default(),
local_id_to_def_id: SortedMap::new(), local_id_to_def_id: SortedMap::new(),
@ -177,7 +177,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
} }
pub(super) fn lower_item_ref(&mut self, i: &Item) -> SmallVec<[hir::ItemId; 1]> { pub(super) fn lower_item_ref(&mut self, i: &Item) -> SmallVec<[hir::ItemId; 1]> {
let mut node_ids = smallvec![hir::ItemId { def_id: self.local_def_id(i.id) }]; let mut node_ids =
smallvec![hir::ItemId { def_id: hir::OwnerId { def_id: self.local_def_id(i.id) } }];
if let ItemKind::Use(ref use_tree) = &i.kind { if let ItemKind::Use(ref use_tree) = &i.kind {
self.lower_item_id_use_tree(use_tree, i.id, &mut node_ids); self.lower_item_id_use_tree(use_tree, i.id, &mut node_ids);
} }
@ -193,7 +194,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
match tree.kind { match tree.kind {
UseTreeKind::Nested(ref nested_vec) => { UseTreeKind::Nested(ref nested_vec) => {
for &(ref nested, id) in nested_vec { for &(ref nested, id) in nested_vec {
vec.push(hir::ItemId { def_id: self.local_def_id(id) }); vec.push(hir::ItemId {
def_id: hir::OwnerId { def_id: self.local_def_id(id) },
});
self.lower_item_id_use_tree(nested, id, vec); self.lower_item_id_use_tree(nested, id, vec);
} }
} }
@ -202,7 +205,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
for (_, &id) in for (_, &id) in
iter::zip(self.expect_full_res_from_use(base_id).skip(1), &[id1, id2]) iter::zip(self.expect_full_res_from_use(base_id).skip(1), &[id1, id2])
{ {
vec.push(hir::ItemId { def_id: self.local_def_id(id) }); vec.push(hir::ItemId {
def_id: hir::OwnerId { def_id: self.local_def_id(id) },
});
} }
} }
} }
@ -553,7 +558,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
} }
let item = hir::Item { let item = hir::Item {
def_id: new_id, def_id: hir::OwnerId { def_id: new_id },
ident: this.lower_ident(ident), ident: this.lower_ident(ident),
kind, kind,
vis_span, vis_span,
@ -627,7 +632,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
} }
let item = hir::Item { let item = hir::Item {
def_id: new_hir_id, def_id: hir::OwnerId { def_id: new_hir_id },
ident: this.lower_ident(ident), ident: this.lower_ident(ident),
kind, kind,
vis_span, vis_span,
@ -689,7 +694,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
fn lower_foreign_item_ref(&mut self, i: &ForeignItem) -> hir::ForeignItemRef { fn lower_foreign_item_ref(&mut self, i: &ForeignItem) -> hir::ForeignItemRef {
hir::ForeignItemRef { hir::ForeignItemRef {
id: hir::ForeignItemId { def_id: self.local_def_id(i.id) }, id: hir::ForeignItemId { def_id: hir::OwnerId { def_id: self.local_def_id(i.id) } },
ident: self.lower_ident(i.ident), ident: self.lower_ident(i.ident),
span: self.lower_span(i.span), span: self.lower_span(i.span),
} }
@ -851,7 +856,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
} }
AssocItemKind::MacCall(..) => unimplemented!(), AssocItemKind::MacCall(..) => unimplemented!(),
}; };
let id = hir::TraitItemId { def_id: self.local_def_id(i.id) }; let id = hir::TraitItemId { def_id: hir::OwnerId { def_id: self.local_def_id(i.id) } };
hir::TraitItemRef { hir::TraitItemRef {
id, id,
ident: self.lower_ident(i.ident), ident: self.lower_ident(i.ident),
@ -931,7 +936,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
fn lower_impl_item_ref(&mut self, i: &AssocItem) -> hir::ImplItemRef { fn lower_impl_item_ref(&mut self, i: &AssocItem) -> hir::ImplItemRef {
hir::ImplItemRef { hir::ImplItemRef {
id: hir::ImplItemId { def_id: self.local_def_id(i.id) }, id: hir::ImplItemId { def_id: hir::OwnerId { def_id: self.local_def_id(i.id) } },
ident: self.lower_ident(i.ident), ident: self.lower_ident(i.ident),
span: self.lower_span(i.span), span: self.lower_span(i.span),
kind: match &i.kind { kind: match &i.kind {

View File

@ -126,7 +126,7 @@ struct LoweringContext<'a, 'hir> {
is_in_trait_impl: bool, is_in_trait_impl: bool,
is_in_dyn_type: bool, is_in_dyn_type: bool,
current_hir_id_owner: LocalDefId, current_hir_id_owner: hir::OwnerId,
item_local_id_counter: hir::ItemLocalId, item_local_id_counter: hir::ItemLocalId,
local_id_to_def_id: SortedMap<ItemLocalId, LocalDefId>, local_id_to_def_id: SortedMap<ItemLocalId, LocalDefId>,
trait_map: FxHashMap<ItemLocalId, Box<[TraitCandidate]>>, trait_map: FxHashMap<ItemLocalId, Box<[TraitCandidate]>>,
@ -572,7 +572,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let current_node_ids = std::mem::take(&mut self.node_id_to_local_id); let current_node_ids = std::mem::take(&mut self.node_id_to_local_id);
let current_id_to_def_id = std::mem::take(&mut self.local_id_to_def_id); let current_id_to_def_id = std::mem::take(&mut self.local_id_to_def_id);
let current_trait_map = std::mem::take(&mut self.trait_map); let current_trait_map = std::mem::take(&mut self.trait_map);
let current_owner = std::mem::replace(&mut self.current_hir_id_owner, def_id); let current_owner =
std::mem::replace(&mut self.current_hir_id_owner, hir::OwnerId { def_id });
let current_local_counter = let current_local_counter =
std::mem::replace(&mut self.item_local_id_counter, hir::ItemLocalId::new(1)); std::mem::replace(&mut self.item_local_id_counter, hir::ItemLocalId::new(1));
let current_impl_trait_defs = std::mem::take(&mut self.impl_trait_defs); let current_impl_trait_defs = std::mem::take(&mut self.impl_trait_defs);
@ -587,7 +588,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
debug_assert_eq!(_old, None); debug_assert_eq!(_old, None);
let item = f(self); let item = f(self);
debug_assert_eq!(def_id, item.def_id()); debug_assert_eq!(def_id, item.def_id().def_id);
// `f` should have consumed all the elements in these vectors when constructing `item`. // `f` should have consumed all the elements in these vectors when constructing `item`.
debug_assert!(self.impl_trait_defs.is_empty()); debug_assert!(self.impl_trait_defs.is_empty());
debug_assert!(self.impl_trait_bounds.is_empty()); debug_assert!(self.impl_trait_bounds.is_empty());
@ -786,7 +787,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
/// Mark a span as relative to the current owning item. /// Mark a span as relative to the current owning item.
fn lower_span(&self, span: Span) -> Span { fn lower_span(&self, span: Span) -> Span {
if self.tcx.sess.opts.unstable_opts.incremental_relative_spans { if self.tcx.sess.opts.unstable_opts.incremental_relative_spans {
span.with_parent(Some(self.current_hir_id_owner)) span.with_parent(Some(self.current_hir_id_owner.def_id))
} else { } else {
// Do not make spans relative when not using incremental compilation. // Do not make spans relative when not using incremental compilation.
span span
@ -812,7 +813,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
LifetimeRes::Fresh { param, .. } => { LifetimeRes::Fresh { param, .. } => {
// Late resolution delegates to us the creation of the `LocalDefId`. // Late resolution delegates to us the creation of the `LocalDefId`.
let _def_id = self.create_def( let _def_id = self.create_def(
self.current_hir_id_owner, self.current_hir_id_owner.def_id,
param, param,
DefPathData::LifetimeNs(kw::UnderscoreLifetime), DefPathData::LifetimeNs(kw::UnderscoreLifetime),
); );
@ -1062,7 +1063,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let parent_def_id = self.current_hir_id_owner; let parent_def_id = self.current_hir_id_owner;
let impl_trait_node_id = self.next_node_id(); let impl_trait_node_id = self.next_node_id();
self.create_def(parent_def_id, impl_trait_node_id, DefPathData::ImplTrait); self.create_def(
parent_def_id.def_id,
impl_trait_node_id,
DefPathData::ImplTrait,
);
self.with_dyn_type_scope(false, |this| { self.with_dyn_type_scope(false, |this| {
let node_id = this.next_node_id(); let node_id = this.next_node_id();
@ -1154,7 +1159,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let node_id = self.next_node_id(); let node_id = self.next_node_id();
// Add a definition for the in-band const def. // Add a definition for the in-band const def.
self.create_def(parent_def_id, node_id, DefPathData::AnonConst); self.create_def(
parent_def_id.def_id,
node_id,
DefPathData::AnonConst,
);
let span = self.lower_span(ty.span); let span = self.lower_span(ty.span);
let path_expr = Expr { let path_expr = Expr {
@ -1551,7 +1560,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
debug!(?lifetimes); debug!(?lifetimes);
// `impl Trait` now just becomes `Foo<'a, 'b, ..>`. // `impl Trait` now just becomes `Foo<'a, 'b, ..>`.
hir::TyKind::OpaqueDef(hir::ItemId { def_id: opaque_ty_def_id }, lifetimes, in_trait) hir::TyKind::OpaqueDef(
hir::ItemId { def_id: hir::OwnerId { def_id: opaque_ty_def_id } },
lifetimes,
in_trait,
)
} }
/// Registers a new opaque type with the proper `NodeId`s and /// Registers a new opaque type with the proper `NodeId`s and
@ -1567,7 +1580,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// Generate an `type Foo = impl Trait;` declaration. // Generate an `type Foo = impl Trait;` declaration.
trace!("registering opaque type with id {:#?}", opaque_ty_id); trace!("registering opaque type with id {:#?}", opaque_ty_id);
let opaque_ty_item = hir::Item { let opaque_ty_item = hir::Item {
def_id: opaque_ty_id, def_id: hir::OwnerId { def_id: opaque_ty_id },
ident: Ident::empty(), ident: Ident::empty(),
kind: opaque_ty_item_kind, kind: opaque_ty_item_kind,
vis_span: self.lower_span(span.shrink_to_lo()), vis_span: self.lower_span(span.shrink_to_lo()),
@ -2018,7 +2031,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// async fn, so the *type parameters* are inherited. It's // async fn, so the *type parameters* are inherited. It's
// only the lifetime parameters that we must supply. // only the lifetime parameters that we must supply.
let opaque_ty_ref = hir::TyKind::OpaqueDef( let opaque_ty_ref = hir::TyKind::OpaqueDef(
hir::ItemId { def_id: opaque_ty_def_id }, hir::ItemId { def_id: hir::OwnerId { def_id: opaque_ty_def_id } },
generic_args, generic_args,
in_trait, in_trait,
); );

View File

@ -932,7 +932,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let opt_suggestions = self let opt_suggestions = self
.infcx .infcx
.tcx .tcx
.typeck(path_segment.hir_id.owner) .typeck(path_segment.hir_id.owner.def_id)
.type_dependent_def_id(*hir_id) .type_dependent_def_id(*hir_id)
.and_then(|def_id| self.infcx.tcx.impl_of_method(def_id)) .and_then(|def_id| self.infcx.tcx.impl_of_method(def_id))
.map(|def_id| self.infcx.tcx.associated_items(def_id)) .map(|def_id| self.infcx.tcx.associated_items(def_id))
@ -1032,7 +1032,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
if look_at_return && hir.get_return_block(closure_id).is_some() { if look_at_return && hir.get_return_block(closure_id).is_some() {
// ...otherwise we are probably in the tail expression of the function, point at the // ...otherwise we are probably in the tail expression of the function, point at the
// return type. // return type.
match hir.get_by_def_id(hir.get_parent_item(fn_call_id)) { match hir.get_by_def_id(hir.get_parent_item(fn_call_id).def_id) {
hir::Node::Item(hir::Item { ident, kind: hir::ItemKind::Fn(sig, ..), .. }) hir::Node::Item(hir::Item { ident, kind: hir::ItemKind::Fn(sig, ..), .. })
| hir::Node::TraitItem(hir::TraitItem { | hir::Node::TraitItem(hir::TraitItem {
ident, ident,

View File

@ -281,7 +281,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let tcx = self.infcx.tcx; let tcx = self.infcx.tcx;
match tcx.hir().get_if_local(def_id) { match tcx.hir().get_if_local(def_id) {
Some(Node::ImplItem(impl_item)) => { Some(Node::ImplItem(impl_item)) => {
match tcx.hir().find_by_def_id(tcx.hir().get_parent_item(impl_item.hir_id())) { match tcx.hir().find_by_def_id(tcx.hir().get_parent_item(impl_item.hir_id()).def_id)
{
Some(Node::Item(Item { Some(Node::Item(Item {
kind: ItemKind::Impl(hir::Impl { self_ty, .. }), kind: ItemKind::Impl(hir::Impl { self_ty, .. }),
.. ..
@ -291,7 +292,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
} }
Some(Node::TraitItem(trait_item)) => { Some(Node::TraitItem(trait_item)) => {
let trait_did = tcx.hir().get_parent_item(trait_item.hir_id()); let trait_did = tcx.hir().get_parent_item(trait_item.hir_id());
match tcx.hir().find_by_def_id(trait_did) { match tcx.hir().find_by_def_id(trait_did.def_id) {
Some(Node::Item(Item { kind: ItemKind::Trait(..), .. })) => { Some(Node::Item(Item { kind: ItemKind::Trait(..), .. })) => {
// The method being called is defined in the `trait`, but the `'static` // The method being called is defined in the `trait`, but the `'static`
// obligation comes from the `impl`. Find that `impl` so that we can point // obligation comes from the `impl`. Find that `impl` so that we can point

View File

@ -707,7 +707,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
hir::AsyncGeneratorKind::Block => " of async block", hir::AsyncGeneratorKind::Block => " of async block",
hir::AsyncGeneratorKind::Closure => " of async closure", hir::AsyncGeneratorKind::Closure => " of async closure",
hir::AsyncGeneratorKind::Fn => { hir::AsyncGeneratorKind::Fn => {
let parent_item = hir.get_by_def_id(hir.get_parent_item(mir_hir_id)); let parent_item =
hir.get_by_def_id(hir.get_parent_item(mir_hir_id).def_id);
let output = &parent_item let output = &parent_item
.fn_decl() .fn_decl()
.expect("generator lowered from async fn should be in fn") .expect("generator lowered from async fn should be in fn")

View File

@ -134,7 +134,7 @@ fn mir_borrowck<'tcx>(
let opt_closure_req = tcx let opt_closure_req = tcx
.infer_ctxt() .infer_ctxt()
.with_opaque_type_inference(DefiningAnchor::Bind(hir_owner)) .with_opaque_type_inference(DefiningAnchor::Bind(hir_owner.def_id))
.enter(|infcx| { .enter(|infcx| {
let input_body: &Body<'_> = &input_body.borrow(); let input_body: &Body<'_> = &input_body.borrow();
let promoted: &IndexVec<_, _> = &promoted.borrow(); let promoted: &IndexVec<_, _> = &promoted.borrow();

View File

@ -329,7 +329,7 @@ impl<'tcx> pprust_hir::PpAnn for TypedAnnotation<'tcx> {
let typeck_results = self.maybe_typeck_results.get().or_else(|| { let typeck_results = self.maybe_typeck_results.get().or_else(|| {
self.tcx self.tcx
.hir() .hir()
.maybe_body_owned_by(expr.hir_id.owner) .maybe_body_owned_by(expr.hir_id.owner.def_id)
.map(|body_id| self.tcx.typeck_body(body_id)) .map(|body_id| self.tcx.typeck_body(body_id))
}); });

View File

@ -1,6 +1,6 @@
use crate::def::{CtorKind, DefKind, Res}; use crate::def::{CtorKind, DefKind, Res};
use crate::def_id::DefId; use crate::def_id::DefId;
pub(crate) use crate::hir_id::{HirId, ItemLocalId}; pub(crate) use crate::hir_id::{HirId, ItemLocalId, OwnerId};
use crate::intravisit::FnKind; use crate::intravisit::FnKind;
use crate::LangItem; use crate::LangItem;
@ -2206,14 +2206,14 @@ pub struct FnSig<'hir> {
// so it can fetched later. // so it can fetched later.
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, HashStable_Generic)] #[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, HashStable_Generic)]
pub struct TraitItemId { pub struct TraitItemId {
pub def_id: LocalDefId, pub def_id: OwnerId,
} }
impl TraitItemId { impl TraitItemId {
#[inline] #[inline]
pub fn hir_id(&self) -> HirId { pub fn hir_id(&self) -> HirId {
// Items are always HIR owners. // Items are always HIR owners.
HirId::make_owner(self.def_id) HirId::make_owner(self.def_id.def_id)
} }
} }
@ -2224,7 +2224,7 @@ impl TraitItemId {
#[derive(Debug, HashStable_Generic)] #[derive(Debug, HashStable_Generic)]
pub struct TraitItem<'hir> { pub struct TraitItem<'hir> {
pub ident: Ident, pub ident: Ident,
pub def_id: LocalDefId, pub def_id: OwnerId,
pub generics: &'hir Generics<'hir>, pub generics: &'hir Generics<'hir>,
pub kind: TraitItemKind<'hir>, pub kind: TraitItemKind<'hir>,
pub span: Span, pub span: Span,
@ -2235,7 +2235,7 @@ impl TraitItem<'_> {
#[inline] #[inline]
pub fn hir_id(&self) -> HirId { pub fn hir_id(&self) -> HirId {
// Items are always HIR owners. // Items are always HIR owners.
HirId::make_owner(self.def_id) HirId::make_owner(self.def_id.def_id)
} }
pub fn trait_item_id(&self) -> TraitItemId { pub fn trait_item_id(&self) -> TraitItemId {
@ -2270,14 +2270,14 @@ pub enum TraitItemKind<'hir> {
// so it can fetched later. // so it can fetched later.
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, HashStable_Generic)] #[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, HashStable_Generic)]
pub struct ImplItemId { pub struct ImplItemId {
pub def_id: LocalDefId, pub def_id: OwnerId,
} }
impl ImplItemId { impl ImplItemId {
#[inline] #[inline]
pub fn hir_id(&self) -> HirId { pub fn hir_id(&self) -> HirId {
// Items are always HIR owners. // Items are always HIR owners.
HirId::make_owner(self.def_id) HirId::make_owner(self.def_id.def_id)
} }
} }
@ -2285,7 +2285,7 @@ impl ImplItemId {
#[derive(Debug, HashStable_Generic)] #[derive(Debug, HashStable_Generic)]
pub struct ImplItem<'hir> { pub struct ImplItem<'hir> {
pub ident: Ident, pub ident: Ident,
pub def_id: LocalDefId, pub def_id: OwnerId,
pub generics: &'hir Generics<'hir>, pub generics: &'hir Generics<'hir>,
pub kind: ImplItemKind<'hir>, pub kind: ImplItemKind<'hir>,
pub defaultness: Defaultness, pub defaultness: Defaultness,
@ -2297,7 +2297,7 @@ impl ImplItem<'_> {
#[inline] #[inline]
pub fn hir_id(&self) -> HirId { pub fn hir_id(&self) -> HirId {
// Items are always HIR owners. // Items are always HIR owners.
HirId::make_owner(self.def_id) HirId::make_owner(self.def_id.def_id)
} }
pub fn impl_item_id(&self) -> ImplItemId { pub fn impl_item_id(&self) -> ImplItemId {
@ -2888,14 +2888,14 @@ impl<'hir> VariantData<'hir> {
// so it can fetched later. // so it can fetched later.
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, Hash, HashStable_Generic)] #[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, Hash, HashStable_Generic)]
pub struct ItemId { pub struct ItemId {
pub def_id: LocalDefId, pub def_id: OwnerId,
} }
impl ItemId { impl ItemId {
#[inline] #[inline]
pub fn hir_id(&self) -> HirId { pub fn hir_id(&self) -> HirId {
// Items are always HIR owners. // Items are always HIR owners.
HirId::make_owner(self.def_id) HirId::make_owner(self.def_id.def_id)
} }
} }
@ -2905,7 +2905,7 @@ impl ItemId {
#[derive(Debug, HashStable_Generic)] #[derive(Debug, HashStable_Generic)]
pub struct Item<'hir> { pub struct Item<'hir> {
pub ident: Ident, pub ident: Ident,
pub def_id: LocalDefId, pub def_id: OwnerId,
pub kind: ItemKind<'hir>, pub kind: ItemKind<'hir>,
pub span: Span, pub span: Span,
pub vis_span: Span, pub vis_span: Span,
@ -2915,7 +2915,7 @@ impl Item<'_> {
#[inline] #[inline]
pub fn hir_id(&self) -> HirId { pub fn hir_id(&self) -> HirId {
// Items are always HIR owners. // Items are always HIR owners.
HirId::make_owner(self.def_id) HirId::make_owner(self.def_id.def_id)
} }
pub fn item_id(&self) -> ItemId { pub fn item_id(&self) -> ItemId {
@ -3132,14 +3132,14 @@ pub enum AssocItemKind {
// so it can fetched later. // so it can fetched later.
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, HashStable_Generic)] #[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, HashStable_Generic)]
pub struct ForeignItemId { pub struct ForeignItemId {
pub def_id: LocalDefId, pub def_id: OwnerId,
} }
impl ForeignItemId { impl ForeignItemId {
#[inline] #[inline]
pub fn hir_id(&self) -> HirId { pub fn hir_id(&self) -> HirId {
// Items are always HIR owners. // Items are always HIR owners.
HirId::make_owner(self.def_id) HirId::make_owner(self.def_id.def_id)
} }
} }
@ -3160,7 +3160,7 @@ pub struct ForeignItemRef {
pub struct ForeignItem<'hir> { pub struct ForeignItem<'hir> {
pub ident: Ident, pub ident: Ident,
pub kind: ForeignItemKind<'hir>, pub kind: ForeignItemKind<'hir>,
pub def_id: LocalDefId, pub def_id: OwnerId,
pub span: Span, pub span: Span,
pub vis_span: Span, pub vis_span: Span,
} }
@ -3169,7 +3169,7 @@ impl ForeignItem<'_> {
#[inline] #[inline]
pub fn hir_id(&self) -> HirId { pub fn hir_id(&self) -> HirId {
// Items are always HIR owners. // Items are always HIR owners.
HirId::make_owner(self.def_id) HirId::make_owner(self.def_id.def_id)
} }
pub fn foreign_item_id(&self) -> ForeignItemId { pub fn foreign_item_id(&self) -> ForeignItemId {
@ -3263,7 +3263,7 @@ impl<'hir> OwnerNode<'hir> {
Node::generics(self.into()) Node::generics(self.into())
} }
pub fn def_id(self) -> LocalDefId { pub fn def_id(self) -> OwnerId {
match self { match self {
OwnerNode::Item(Item { def_id, .. }) OwnerNode::Item(Item { def_id, .. })
| OwnerNode::TraitItem(TraitItem { def_id, .. }) | OwnerNode::TraitItem(TraitItem { def_id, .. })

View File

@ -1,6 +1,43 @@
use crate::def_id::{LocalDefId, CRATE_DEF_ID}; use crate::def_id::{DefId, LocalDefId, CRATE_DEF_ID};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
use rustc_span::{def_id::DefPathHash, HashStableContext};
use std::fmt; use std::fmt;
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
#[derive(Encodable, Decodable)]
pub struct OwnerId {
pub def_id: LocalDefId,
}
impl From<OwnerId> for HirId {
fn from(owner: OwnerId) -> HirId {
HirId { owner, local_id: ItemLocalId::from_u32(0) }
}
}
impl OwnerId {
#[inline]
pub fn to_def_id(self) -> DefId {
self.def_id.to_def_id()
}
}
impl<CTX: HashStableContext> HashStable<CTX> for OwnerId {
#[inline]
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
self.to_stable_hash_key(hcx).hash_stable(hcx, hasher);
}
}
impl<CTX: HashStableContext> ToStableHashKey<CTX> for OwnerId {
type KeyType = DefPathHash;
#[inline]
fn to_stable_hash_key(&self, hcx: &CTX) -> DefPathHash {
hcx.def_path_hash(self.to_def_id())
}
}
/// Uniquely identifies a node in the HIR of the current crate. It is /// Uniquely identifies a node in the HIR of the current crate. It is
/// composed of the `owner`, which is the `LocalDefId` of the directly enclosing /// composed of the `owner`, which is the `LocalDefId` of the directly enclosing
/// `hir::Item`, `hir::TraitItem`, or `hir::ImplItem` (i.e., the closest "item-like"), /// `hir::Item`, `hir::TraitItem`, or `hir::ImplItem` (i.e., the closest "item-like"),
@ -15,22 +52,23 @@ use std::fmt;
#[derive(Encodable, Decodable, HashStable_Generic)] #[derive(Encodable, Decodable, HashStable_Generic)]
#[rustc_pass_by_value] #[rustc_pass_by_value]
pub struct HirId { pub struct HirId {
pub owner: LocalDefId, pub owner: OwnerId,
pub local_id: ItemLocalId, pub local_id: ItemLocalId,
} }
impl HirId { impl HirId {
/// Signal local id which should never be used. /// Signal local id which should never be used.
pub const INVALID: HirId = HirId { owner: CRATE_DEF_ID, local_id: ItemLocalId::INVALID }; pub const INVALID: HirId =
HirId { owner: OwnerId { def_id: CRATE_DEF_ID }, local_id: ItemLocalId::INVALID };
#[inline] #[inline]
pub fn expect_owner(self) -> LocalDefId { pub fn expect_owner(self) -> OwnerId {
assert_eq!(self.local_id.index(), 0); assert_eq!(self.local_id.index(), 0);
self.owner self.owner
} }
#[inline] #[inline]
pub fn as_owner(self) -> Option<LocalDefId> { pub fn as_owner(self) -> Option<OwnerId> {
if self.local_id.index() == 0 { Some(self.owner) } else { None } if self.local_id.index() == 0 { Some(self.owner) } else { None }
} }
@ -41,11 +79,14 @@ impl HirId {
#[inline] #[inline]
pub fn make_owner(owner: LocalDefId) -> Self { pub fn make_owner(owner: LocalDefId) -> Self {
Self { owner, local_id: ItemLocalId::from_u32(0) } Self { owner: OwnerId { def_id: owner }, local_id: ItemLocalId::from_u32(0) }
} }
pub fn index(self) -> (usize, usize) { pub fn index(self) -> (usize, usize) {
(rustc_index::vec::Idx::index(self.owner), rustc_index::vec::Idx::index(self.local_id)) (
rustc_index::vec::Idx::index(self.owner.def_id),
rustc_index::vec::Idx::index(self.local_id),
)
} }
} }
@ -94,4 +135,7 @@ impl ItemLocalId {
} }
/// The `HirId` corresponding to `CRATE_NODE_ID` and `CRATE_DEF_ID`. /// The `HirId` corresponding to `CRATE_NODE_ID` and `CRATE_DEF_ID`.
pub const CRATE_HIR_ID: HirId = HirId { owner: CRATE_DEF_ID, local_id: ItemLocalId::from_u32(0) }; pub const CRATE_HIR_ID: HirId =
HirId { owner: OwnerId { def_id: CRATE_DEF_ID }, local_id: ItemLocalId::from_u32(0) };
pub const CRATE_OWNER_ID: OwnerId = OwnerId { def_id: CRATE_DEF_ID };

View File

@ -20,7 +20,7 @@ impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for HirId {
#[inline] #[inline]
fn to_stable_hash_key(&self, hcx: &HirCtx) -> (DefPathHash, ItemLocalId) { fn to_stable_hash_key(&self, hcx: &HirCtx) -> (DefPathHash, ItemLocalId) {
let def_path_hash = self.owner.to_stable_hash_key(hcx); let def_path_hash = self.owner.def_id.to_stable_hash_key(hcx);
(def_path_hash, self.local_id) (def_path_hash, self.local_id)
} }
} }
@ -49,7 +49,7 @@ impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ItemId {
#[inline] #[inline]
fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash { fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash {
self.def_id.to_stable_hash_key(hcx) self.def_id.def_id.to_stable_hash_key(hcx)
} }
} }
@ -58,7 +58,7 @@ impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for TraitItemId {
#[inline] #[inline]
fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash { fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash {
self.def_id.to_stable_hash_key(hcx) self.def_id.def_id.to_stable_hash_key(hcx)
} }
} }
@ -67,7 +67,7 @@ impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ImplItemId {
#[inline] #[inline]
fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash { fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash {
self.def_id.to_stable_hash_key(hcx) self.def_id.def_id.to_stable_hash_key(hcx)
} }
} }
@ -76,7 +76,7 @@ impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ForeignItemId
#[inline] #[inline]
fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash { fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash {
self.def_id.to_stable_hash_key(hcx) self.def_id.def_id.to_stable_hash_key(hcx)
} }
} }

View File

@ -149,19 +149,19 @@ pub fn check_dirty_clean_annotations(tcx: TyCtxt<'_>) {
let crate_items = tcx.hir_crate_items(()); let crate_items = tcx.hir_crate_items(());
for id in crate_items.items() { for id in crate_items.items() {
dirty_clean_visitor.check_item(id.def_id); dirty_clean_visitor.check_item(id.def_id.def_id);
} }
for id in crate_items.trait_items() { for id in crate_items.trait_items() {
dirty_clean_visitor.check_item(id.def_id); dirty_clean_visitor.check_item(id.def_id.def_id);
} }
for id in crate_items.impl_items() { for id in crate_items.impl_items() {
dirty_clean_visitor.check_item(id.def_id); dirty_clean_visitor.check_item(id.def_id.def_id);
} }
for id in crate_items.foreign_items() { for id in crate_items.foreign_items() {
dirty_clean_visitor.check_item(id.def_id); dirty_clean_visitor.check_item(id.def_id.def_id);
} }
let mut all_attrs = FindAllAttrs { tcx, found_attrs: vec![] }; let mut all_attrs = FindAllAttrs { tcx, found_attrs: vec![] };

View File

@ -2440,7 +2440,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
// We do this to avoid suggesting code that ends up as `T: 'a'b`, // We do this to avoid suggesting code that ends up as `T: 'a'b`,
// instead we suggest `T: 'a + 'b` in that case. // instead we suggest `T: 'a + 'b` in that case.
let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id); let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id);
let ast_generics = self.tcx.hir().get_generics(hir_id.owner); let ast_generics = self.tcx.hir().get_generics(hir_id.owner.def_id);
let bounds = let bounds =
ast_generics.and_then(|g| g.bounds_span_for_suggestions(def_id)); ast_generics.and_then(|g| g.bounds_span_for_suggestions(def_id));
// `sp` only covers `T`, change it so that it covers // `sp` only covers `T`, change it so that it covers

View File

@ -185,8 +185,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
| ObligationCauseCode::BlockTailExpression(hir_id) = cause.code() | ObligationCauseCode::BlockTailExpression(hir_id) = cause.code()
{ {
let parent_id = tcx.hir().get_parent_item(*hir_id); let parent_id = tcx.hir().get_parent_item(*hir_id);
let parent_id = tcx.hir().local_def_id_to_hir_id(parent_id); if let Some(fn_decl) = tcx.hir().fn_decl_by_hir_id(parent_id.into()) {
if let Some(fn_decl) = tcx.hir().fn_decl_by_hir_id(parent_id) {
let mut span: MultiSpan = fn_decl.output.span().into(); let mut span: MultiSpan = fn_decl.output.span().into();
let mut add_label = true; let mut add_label = true;
if let hir::FnRetTy::Return(ty) = fn_decl.output { if let hir::FnRetTy::Return(ty) = fn_decl.output {
@ -415,7 +414,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
let tcx = self.tcx(); let tcx = self.tcx();
match tcx.hir().get_if_local(def_id) { match tcx.hir().get_if_local(def_id) {
Some(Node::ImplItem(impl_item)) => { Some(Node::ImplItem(impl_item)) => {
match tcx.hir().find_by_def_id(tcx.hir().get_parent_item(impl_item.hir_id())) { match tcx.hir().find_by_def_id(tcx.hir().get_parent_item(impl_item.hir_id()).def_id)
{
Some(Node::Item(Item { Some(Node::Item(Item {
kind: ItemKind::Impl(hir::Impl { self_ty, .. }), kind: ItemKind::Impl(hir::Impl { self_ty, .. }),
.. ..
@ -425,7 +425,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
} }
Some(Node::TraitItem(trait_item)) => { Some(Node::TraitItem(trait_item)) => {
let trait_did = tcx.hir().get_parent_item(trait_item.hir_id()); let trait_did = tcx.hir().get_parent_item(trait_item.hir_id());
match tcx.hir().find_by_def_id(trait_did) { match tcx.hir().find_by_def_id(trait_did.def_id) {
Some(Node::Item(Item { kind: ItemKind::Trait(..), .. })) => { Some(Node::Item(Item { kind: ItemKind::Trait(..), .. })) => {
// The method being called is defined in the `trait`, but the `'static` // The method being called is defined in the `trait`, but the `'static`
// obligation comes from the `impl`. Find that `impl` so that we can point // obligation comes from the `impl`. Find that `impl` so that we can point

View File

@ -16,6 +16,7 @@ use rustc_data_structures::undo_log::Rollback;
use rustc_data_structures::unify as ut; use rustc_data_structures::unify as ut;
use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed}; use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed};
use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::hir_id::OwnerId;
use rustc_middle::infer::canonical::{Canonical, CanonicalVarValues}; use rustc_middle::infer::canonical::{Canonical, CanonicalVarValues};
use rustc_middle::infer::unify_key::{ConstVarValue, ConstVariableValue}; use rustc_middle::infer::unify_key::{ConstVarValue, ConstVariableValue};
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind, ToType}; use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind, ToType};
@ -583,9 +584,9 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
/// Used only by `rustc_typeck` during body type-checking/inference, /// Used only by `rustc_typeck` during body type-checking/inference,
/// will initialize `in_progress_typeck_results` with fresh `TypeckResults`. /// will initialize `in_progress_typeck_results` with fresh `TypeckResults`.
/// Will also change the scope for opaque type defining use checks to the given owner. /// Will also change the scope for opaque type defining use checks to the given owner.
pub fn with_fresh_in_progress_typeck_results(mut self, table_owner: LocalDefId) -> Self { pub fn with_fresh_in_progress_typeck_results(mut self, table_owner: OwnerId) -> Self {
self.fresh_typeck_results = Some(RefCell::new(ty::TypeckResults::new(table_owner))); self.fresh_typeck_results = Some(RefCell::new(ty::TypeckResults::new(table_owner)));
self.with_opaque_type_inference(DefiningAnchor::Bind(table_owner)) self.with_opaque_type_inference(DefiningAnchor::Bind(table_owner.def_id))
} }
/// Whenever the `InferCtxt` should be able to handle defining uses of opaque types, /// Whenever the `InferCtxt` should be able to handle defining uses of opaque types,

View File

@ -616,7 +616,7 @@ fn may_define_opaque_type(tcx: TyCtxt<'_>, def_id: LocalDefId, opaque_hir_id: hi
let scope = tcx.hir().get_defining_scope(opaque_hir_id); let scope = tcx.hir().get_defining_scope(opaque_hir_id);
// We walk up the node tree until we hit the root or the scope of the opaque type. // We walk up the node tree until we hit the root or the scope of the opaque type.
while hir_id != scope && hir_id != hir::CRATE_HIR_ID { while hir_id != scope && hir_id != hir::CRATE_HIR_ID {
hir_id = tcx.hir().local_def_id_to_hir_id(tcx.hir().get_parent_item(hir_id)); hir_id = tcx.hir().get_parent_item(hir_id).into();
} }
// Syntactically, we are allowed to define the concrete type if: // Syntactically, we are allowed to define the concrete type if:
let res = hir_id == scope; let res = hir_id == scope;

View File

@ -1,4 +1,3 @@
use rustc_hir as hir;
use rustc_hir::def_id::LocalDefId; use rustc_hir::def_id::LocalDefId;
use rustc_middle::ty::query::Providers; use rustc_middle::ty::query::Providers;
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
@ -10,7 +9,7 @@ fn proc_macro_decls_static(tcx: TyCtxt<'_>, (): ()) -> Option<LocalDefId> {
for id in tcx.hir().items() { for id in tcx.hir().items() {
let attrs = finder.tcx.hir().attrs(id.hir_id()); let attrs = finder.tcx.hir().attrs(id.hir_id());
if finder.tcx.sess.contains_name(attrs, sym::rustc_proc_macro_decls) { if finder.tcx.sess.contains_name(attrs, sym::rustc_proc_macro_decls) {
finder.decls = Some(id.def_id); finder.decls = Some(id.def_id.def_id);
} }
} }
@ -19,7 +18,7 @@ fn proc_macro_decls_static(tcx: TyCtxt<'_>, (): ()) -> Option<LocalDefId> {
struct Finder<'tcx> { struct Finder<'tcx> {
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
decls: Option<hir::def_id::LocalDefId>, decls: Option<LocalDefId>,
} }
pub(crate) fn provide(providers: &mut Providers) { pub(crate) fn provide(providers: &mut Providers) {

View File

@ -606,7 +606,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
// Issue #11592: traits are always considered exported, even when private. // Issue #11592: traits are always considered exported, even when private.
if cx.tcx.visibility(it.def_id) if cx.tcx.visibility(it.def_id)
== ty::Visibility::Restricted( == ty::Visibility::Restricted(
cx.tcx.parent_module_from_def_id(it.def_id).to_def_id(), cx.tcx.parent_module_from_def_id(it.def_id.def_id).to_def_id(),
) )
{ {
return; return;
@ -627,13 +627,13 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
let (article, desc) = cx.tcx.article_and_description(it.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.def_id, article, desc); self.check_missing_docs_attrs(cx, it.def_id.def_id, article, desc);
} }
fn check_trait_item(&mut self, cx: &LateContext<'_>, trait_item: &hir::TraitItem<'_>) { fn check_trait_item(&mut self, cx: &LateContext<'_>, trait_item: &hir::TraitItem<'_>) {
let (article, desc) = cx.tcx.article_and_description(trait_item.def_id.to_def_id()); let (article, desc) = cx.tcx.article_and_description(trait_item.def_id.to_def_id());
self.check_missing_docs_attrs(cx, trait_item.def_id, article, desc); self.check_missing_docs_attrs(cx, trait_item.def_id.def_id, article, desc);
} }
fn check_impl_item(&mut self, cx: &LateContext<'_>, impl_item: &hir::ImplItem<'_>) { fn check_impl_item(&mut self, cx: &LateContext<'_>, impl_item: &hir::ImplItem<'_>) {
@ -661,12 +661,12 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
} }
let (article, desc) = cx.tcx.article_and_description(impl_item.def_id.to_def_id()); let (article, desc) = cx.tcx.article_and_description(impl_item.def_id.to_def_id());
self.check_missing_docs_attrs(cx, impl_item.def_id, article, desc); self.check_missing_docs_attrs(cx, impl_item.def_id.def_id, article, desc);
} }
fn check_foreign_item(&mut self, cx: &LateContext<'_>, foreign_item: &hir::ForeignItem<'_>) { fn check_foreign_item(&mut self, cx: &LateContext<'_>, foreign_item: &hir::ForeignItem<'_>) {
let (article, desc) = cx.tcx.article_and_description(foreign_item.def_id.to_def_id()); let (article, desc) = cx.tcx.article_and_description(foreign_item.def_id.to_def_id());
self.check_missing_docs_attrs(cx, foreign_item.def_id, article, desc); self.check_missing_docs_attrs(cx, foreign_item.def_id.def_id, article, desc);
} }
fn check_field_def(&mut self, cx: &LateContext<'_>, sf: &hir::FieldDef<'_>) { fn check_field_def(&mut self, cx: &LateContext<'_>, sf: &hir::FieldDef<'_>) {
@ -719,7 +719,7 @@ declare_lint_pass!(MissingCopyImplementations => [MISSING_COPY_IMPLEMENTATIONS])
impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations { impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations {
fn check_item(&mut self, cx: &LateContext<'_>, item: &hir::Item<'_>) { fn check_item(&mut self, cx: &LateContext<'_>, item: &hir::Item<'_>) {
if !cx.access_levels.is_reachable(item.def_id) { if !cx.access_levels.is_reachable(item.def_id.def_id) {
return; return;
} }
let (def, ty) = match item.kind { let (def, ty) = match item.kind {
@ -809,7 +809,7 @@ impl_lint_pass!(MissingDebugImplementations => [MISSING_DEBUG_IMPLEMENTATIONS]);
impl<'tcx> LateLintPass<'tcx> for MissingDebugImplementations { impl<'tcx> LateLintPass<'tcx> for MissingDebugImplementations {
fn check_item(&mut self, cx: &LateContext<'_>, item: &hir::Item<'_>) { fn check_item(&mut self, cx: &LateContext<'_>, item: &hir::Item<'_>) {
if !cx.access_levels.is_reachable(item.def_id) { if !cx.access_levels.is_reachable(item.def_id.def_id) {
return; return;
} }
@ -836,7 +836,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDebugImplementations {
debug!("{:?}", self.impling_types); debug!("{:?}", self.impling_types);
} }
if !self.impling_types.as_ref().unwrap().contains(&item.def_id) { if !self.impling_types.as_ref().unwrap().contains(&item.def_id.def_id) {
cx.struct_span_lint(MISSING_DEBUG_IMPLEMENTATIONS, item.span, |lint| { cx.struct_span_lint(MISSING_DEBUG_IMPLEMENTATIONS, item.span, |lint| {
lint.build(fluent::lint::builtin_missing_debug_impl) lint.build(fluent::lint::builtin_missing_debug_impl)
.set_arg("debug", cx.tcx.def_path_str(debug)) .set_arg("debug", cx.tcx.def_path_str(debug))
@ -1206,7 +1206,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidNoMangleItems {
check_no_mangle_on_generic_fn( check_no_mangle_on_generic_fn(
no_mangle_attr, no_mangle_attr,
Some(generics), Some(generics),
cx.tcx.hir().get_generics(it.id.def_id).unwrap(), cx.tcx.hir().get_generics(it.id.def_id.def_id).unwrap(),
it.span, it.span,
); );
} }
@ -1389,11 +1389,11 @@ impl<'tcx> LateLintPass<'tcx> for UnreachablePub {
if let hir::ItemKind::Use(_, hir::UseKind::ListStem) = &item.kind { if let hir::ItemKind::Use(_, hir::UseKind::ListStem) = &item.kind {
return; return;
} }
self.perform_lint(cx, "item", item.def_id, item.vis_span, true); self.perform_lint(cx, "item", item.def_id.def_id, item.vis_span, true);
} }
fn check_foreign_item(&mut self, cx: &LateContext<'_>, foreign_item: &hir::ForeignItem<'tcx>) { fn check_foreign_item(&mut self, cx: &LateContext<'_>, foreign_item: &hir::ForeignItem<'tcx>) {
self.perform_lint(cx, "item", foreign_item.def_id, foreign_item.vis_span, true); self.perform_lint(cx, "item", foreign_item.def_id.def_id, foreign_item.vis_span, true);
} }
fn check_field_def(&mut self, cx: &LateContext<'_>, field: &hir::FieldDef<'_>) { fn check_field_def(&mut self, cx: &LateContext<'_>, field: &hir::FieldDef<'_>) {
@ -1404,7 +1404,7 @@ impl<'tcx> LateLintPass<'tcx> for UnreachablePub {
fn check_impl_item(&mut self, cx: &LateContext<'_>, impl_item: &hir::ImplItem<'_>) { fn check_impl_item(&mut self, cx: &LateContext<'_>, impl_item: &hir::ImplItem<'_>) {
// Only lint inherent impl items. // Only lint inherent impl items.
if cx.tcx.associated_item(impl_item.def_id).trait_item_def_id.is_none() { if cx.tcx.associated_item(impl_item.def_id).trait_item_def_id.is_none() {
self.perform_lint(cx, "item", impl_item.def_id, impl_item.vis_span, false); self.perform_lint(cx, "item", impl_item.def_id.def_id, impl_item.vis_span, false);
} }
} }
} }
@ -1841,7 +1841,7 @@ declare_lint! {
} }
pub struct UnnameableTestItems { pub struct UnnameableTestItems {
boundary: Option<LocalDefId>, // Id of the item under which things are not nameable boundary: Option<hir::OwnerId>, // Id of the item under which things are not nameable
items_nameable: bool, items_nameable: bool,
} }
@ -2138,7 +2138,7 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
use rustc_middle::middle::resolve_lifetime::Region; use rustc_middle::middle::resolve_lifetime::Region;
let def_id = item.def_id; let def_id = item.def_id.def_id;
if let hir::ItemKind::Struct(_, ref hir_generics) if let hir::ItemKind::Struct(_, ref hir_generics)
| hir::ItemKind::Enum(_, ref hir_generics) | hir::ItemKind::Enum(_, ref hir_generics)
| hir::ItemKind::Union(_, ref hir_generics) = item.kind | hir::ItemKind::Union(_, ref hir_generics) = item.kind

View File

@ -1048,7 +1048,7 @@ impl<'tcx> LateContext<'tcx> {
.filter(|typeck_results| typeck_results.hir_owner == id.owner) .filter(|typeck_results| typeck_results.hir_owner == id.owner)
.or_else(|| { .or_else(|| {
if self.tcx.has_typeck_results(id.owner.to_def_id()) { if self.tcx.has_typeck_results(id.owner.to_def_id()) {
Some(self.tcx.typeck(id.owner)) Some(self.tcx.typeck(id.owner.def_id))
} else { } else {
None None
} }

View File

@ -382,7 +382,7 @@ impl<'tcx> Collector<'tcx> {
let link_ordinal_attr = self let link_ordinal_attr = self
.tcx .tcx
.hir() .hir()
.attrs(self.tcx.hir().local_def_id_to_hir_id(child_item.id.def_id)) .attrs(child_item.id.def_id.into())
.iter() .iter()
.find(|a| a.has_name(sym::link_ordinal)) .find(|a| a.has_name(sym::link_ordinal))
.unwrap(); .unwrap();

View File

@ -1217,14 +1217,14 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
// from name resolution point of view. // from name resolution point of view.
hir::ItemKind::ForeignMod { items, .. } => { hir::ItemKind::ForeignMod { items, .. } => {
for foreign_item in items { for foreign_item in items {
yield foreign_item.id.def_id.local_def_index; yield foreign_item.id.def_id.def_id.local_def_index;
} }
} }
// Only encode named non-reexport children, reexports are encoded // Only encode named non-reexport children, reexports are encoded
// separately and unnamed items are not used by name resolution. // separately and unnamed items are not used by name resolution.
hir::ItemKind::ExternCrate(..) => continue, hir::ItemKind::ExternCrate(..) => continue,
_ if tcx.def_key(item_id.def_id.to_def_id()).get_opt_name().is_some() => { _ if tcx.def_key(item_id.def_id.to_def_id()).get_opt_name().is_some() => {
yield item_id.def_id.local_def_index; yield item_id.def_id.def_id.local_def_index;
} }
_ => continue, _ => continue,
} }
@ -1446,7 +1446,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
record!(self.tables.macro_definition[def_id] <- &*macro_def.body); record!(self.tables.macro_definition[def_id] <- &*macro_def.body);
} }
hir::ItemKind::Mod(ref m) => { hir::ItemKind::Mod(ref m) => {
return self.encode_info_for_mod(item.def_id, m); return self.encode_info_for_mod(item.def_id.def_id, m);
} }
hir::ItemKind::OpaqueTy(..) => { hir::ItemKind::OpaqueTy(..) => {
self.encode_explicit_item_bounds(def_id); self.encode_explicit_item_bounds(def_id);
@ -1840,7 +1840,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
for id in tcx.hir().items() { for id in tcx.hir().items() {
if matches!(tcx.def_kind(id.def_id), DefKind::Impl) { if matches!(tcx.def_kind(id.def_id), DefKind::Impl) {
if let Some(trait_ref) = tcx.impl_trait_ref(id.def_id.to_def_id()) { if let Some(trait_ref) = tcx.impl_trait_ref(id.def_id) {
let simplified_self_ty = fast_reject::simplify_type( let simplified_self_ty = fast_reject::simplify_type(
self.tcx, self.tcx,
trait_ref.self_ty(), trait_ref.self_ty(),
@ -1850,7 +1850,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
fx_hash_map fx_hash_map
.entry(trait_ref.def_id) .entry(trait_ref.def_id)
.or_default() .or_default()
.push((id.def_id.local_def_index, simplified_self_ty)); .push((id.def_id.def_id.local_def_index, simplified_self_ty));
} }
} }
} }

View File

@ -62,7 +62,7 @@ use crate::ty::TyCtxt;
use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fingerprint::Fingerprint;
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId}; use rustc_hir::def_id::{CrateNum, DefId, LocalDefId};
use rustc_hir::definitions::DefPathHash; use rustc_hir::definitions::DefPathHash;
use rustc_hir::HirId; use rustc_hir::{HirId, OwnerId};
use rustc_query_system::dep_graph::FingerprintStyle; use rustc_query_system::dep_graph::FingerprintStyle;
use rustc_span::symbol::Symbol; use rustc_span::symbol::Symbol;
use std::hash::Hash; use std::hash::Hash;
@ -355,6 +355,28 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for LocalDefId {
} }
} }
impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for OwnerId {
#[inline(always)]
fn fingerprint_style() -> FingerprintStyle {
FingerprintStyle::DefPathHash
}
#[inline(always)]
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
self.to_def_id().to_fingerprint(tcx)
}
#[inline(always)]
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
self.to_def_id().to_debug_str(tcx)
}
#[inline(always)]
fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
dep_node.extract_def_id(tcx).map(|id| OwnerId { def_id: id.expect_local() })
}
}
impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for CrateNum { impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for CrateNum {
#[inline(always)] #[inline(always)]
fn fingerprint_style() -> FingerprintStyle { fn fingerprint_style() -> FingerprintStyle {

View File

@ -93,7 +93,7 @@ pub struct ParentOwnerIterator<'hir> {
} }
impl<'hir> Iterator for ParentOwnerIterator<'hir> { impl<'hir> Iterator for ParentOwnerIterator<'hir> {
type Item = (LocalDefId, OwnerNode<'hir>); type Item = (OwnerId, OwnerNode<'hir>);
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
if self.current_id.local_id.index() != 0 { if self.current_id.local_id.index() != 0 {
@ -107,13 +107,13 @@ impl<'hir> Iterator for ParentOwnerIterator<'hir> {
} }
loop { loop {
// There are nodes that do not have entries, so we need to skip them. // There are nodes that do not have entries, so we need to skip them.
let parent_id = self.map.def_key(self.current_id.owner).parent; let parent_id = self.map.def_key(self.current_id.owner.def_id).parent;
let parent_id = parent_id.map_or(CRATE_HIR_ID.owner, |local_def_index| { let parent_id = parent_id.map_or(CRATE_OWNER_ID, |local_def_index| {
let def_id = LocalDefId { local_def_index }; let def_id = LocalDefId { local_def_index };
self.map.local_def_id_to_hir_id(def_id).owner self.map.local_def_id_to_hir_id(def_id).owner
}); });
self.current_id = HirId::make_owner(parent_id); self.current_id = HirId::make_owner(parent_id.def_id);
// If this `HirId` doesn't have an entry, skip it and look for its `parent_id`. // If this `HirId` doesn't have an entry, skip it and look for its `parent_id`.
if let Some(node) = self.map.tcx.hir_owner(self.current_id.owner) { if let Some(node) = self.map.tcx.hir_owner(self.current_id.owner) {
@ -131,7 +131,7 @@ impl<'hir> Map<'hir> {
#[inline] #[inline]
pub fn root_module(self) -> &'hir Mod<'hir> { pub fn root_module(self) -> &'hir Mod<'hir> {
match self.tcx.hir_owner(CRATE_DEF_ID).map(|o| o.node) { match self.tcx.hir_owner(CRATE_OWNER_ID).map(|o| o.node) {
Some(OwnerNode::Crate(item)) => item, Some(OwnerNode::Crate(item)) => item,
_ => bug!(), _ => bug!(),
} }
@ -186,7 +186,7 @@ impl<'hir> Map<'hir> {
#[inline] #[inline]
pub fn opt_local_def_id(self, hir_id: HirId) -> Option<LocalDefId> { pub fn opt_local_def_id(self, hir_id: HirId) -> Option<LocalDefId> {
if hir_id.local_id == ItemLocalId::new(0) { if hir_id.local_id == ItemLocalId::new(0) {
Some(hir_id.owner) Some(hir_id.owner.def_id)
} else { } else {
self.tcx self.tcx
.hir_owner_nodes(hir_id.owner) .hir_owner_nodes(hir_id.owner)
@ -352,7 +352,7 @@ impl<'hir> Map<'hir> {
} }
pub fn get_generics(self, id: LocalDefId) -> Option<&'hir Generics<'hir>> { pub fn get_generics(self, id: LocalDefId) -> Option<&'hir Generics<'hir>> {
let node = self.tcx.hir_owner(id)?; let node = self.tcx.hir_owner(OwnerId { def_id: id })?;
node.node.generics() node.node.generics()
} }
@ -532,7 +532,7 @@ impl<'hir> Map<'hir> {
pub fn get_module(self, module: LocalDefId) -> (&'hir Mod<'hir>, Span, HirId) { pub fn get_module(self, module: LocalDefId) -> (&'hir Mod<'hir>, Span, HirId) {
let hir_id = HirId::make_owner(module); let hir_id = HirId::make_owner(module);
match self.tcx.hir_owner(module).map(|o| o.node) { match self.tcx.hir_owner(hir_id.owner).map(|o| o.node) {
Some(OwnerNode::Item(&Item { span, kind: ItemKind::Mod(ref m), .. })) => { Some(OwnerNode::Item(&Item { span, kind: ItemKind::Mod(ref m), .. })) => {
(m, span, hir_id) (m, span, hir_id)
} }
@ -622,14 +622,14 @@ impl<'hir> Map<'hir> {
pub fn for_each_module(self, mut f: impl FnMut(LocalDefId)) { pub fn for_each_module(self, mut f: impl FnMut(LocalDefId)) {
let crate_items = self.tcx.hir_crate_items(()); let crate_items = self.tcx.hir_crate_items(());
for module in crate_items.submodules.iter() { for module in crate_items.submodules.iter() {
f(*module) f(module.def_id)
} }
} }
#[inline] #[inline]
pub fn par_for_each_module(self, f: impl Fn(LocalDefId) + Sync + Send) { pub fn par_for_each_module(self, f: impl Fn(LocalDefId) + Sync + Send) {
let crate_items = self.tcx.hir_crate_items(()); let crate_items = self.tcx.hir_crate_items(());
par_for_each_in(&crate_items.submodules[..], |module| f(*module)) par_for_each_in(&crate_items.submodules[..], |module| f(module.def_id))
} }
/// Returns an iterator for the nodes in the ancestor tree of the `current_id` /// Returns an iterator for the nodes in the ancestor tree of the `current_id`
@ -721,27 +721,27 @@ impl<'hir> Map<'hir> {
None None
} }
/// Retrieves the `HirId` for `id`'s parent item, or `id` itself if no /// Retrieves the `OwnerId` for `id`'s parent item, or `id` itself if no
/// parent item is in this map. The "parent item" is the closest parent node /// parent item is in this map. The "parent item" is the closest parent node
/// in the HIR which is recorded by the map and is an item, either an item /// in the HIR which is recorded by the map and is an item, either an item
/// in a module, trait, or impl. /// in a module, trait, or impl.
pub fn get_parent_item(self, hir_id: HirId) -> LocalDefId { pub fn get_parent_item(self, hir_id: HirId) -> OwnerId {
if let Some((def_id, _node)) = self.parent_owner_iter(hir_id).next() { if let Some((def_id, _node)) = self.parent_owner_iter(hir_id).next() {
def_id def_id
} else { } else {
CRATE_DEF_ID CRATE_OWNER_ID
} }
} }
/// Returns the `HirId` of `id`'s nearest module parent, or `id` itself if no /// Returns the `OwnerId` of `id`'s nearest module parent, or `id` itself if no
/// module parent is in this map. /// module parent is in this map.
pub(super) fn get_module_parent_node(self, hir_id: HirId) -> LocalDefId { pub(super) fn get_module_parent_node(self, hir_id: HirId) -> OwnerId {
for (def_id, node) in self.parent_owner_iter(hir_id) { for (def_id, node) in self.parent_owner_iter(hir_id) {
if let OwnerNode::Item(&Item { kind: ItemKind::Mod(_), .. }) = node { if let OwnerNode::Item(&Item { kind: ItemKind::Mod(_), .. }) = node {
return def_id; return def_id;
} }
} }
CRATE_DEF_ID CRATE_OWNER_ID
} }
/// When on an if expression, a match arm tail expression or a match arm, give back /// When on an if expression, a match arm tail expression or a match arm, give back
@ -814,30 +814,30 @@ impl<'hir> Map<'hir> {
} }
bug!( bug!(
"expected foreign mod or inlined parent, found {}", "expected foreign mod or inlined parent, found {}",
self.node_to_string(HirId::make_owner(parent)) self.node_to_string(HirId::make_owner(parent.def_id))
) )
} }
pub fn expect_owner(self, id: LocalDefId) -> OwnerNode<'hir> { pub fn expect_owner(self, id: OwnerId) -> OwnerNode<'hir> {
self.tcx.hir_owner(id).unwrap_or_else(|| bug!("expected owner for {:?}", id)).node self.tcx.hir_owner(id).unwrap_or_else(|| bug!("expected owner for {:?}", id)).node
} }
pub fn expect_item(self, id: LocalDefId) -> &'hir Item<'hir> { pub fn expect_item(self, id: LocalDefId) -> &'hir Item<'hir> {
match self.tcx.hir_owner(id) { match self.tcx.hir_owner(OwnerId { def_id: id }) {
Some(Owner { node: OwnerNode::Item(item), .. }) => item, Some(Owner { node: OwnerNode::Item(item), .. }) => item,
_ => bug!("expected item, found {}", self.node_to_string(HirId::make_owner(id))), _ => bug!("expected item, found {}", self.node_to_string(HirId::make_owner(id))),
} }
} }
pub fn expect_impl_item(self, id: LocalDefId) -> &'hir ImplItem<'hir> { pub fn expect_impl_item(self, id: LocalDefId) -> &'hir ImplItem<'hir> {
match self.tcx.hir_owner(id) { match self.tcx.hir_owner(OwnerId { def_id: id }) {
Some(Owner { node: OwnerNode::ImplItem(item), .. }) => item, Some(Owner { node: OwnerNode::ImplItem(item), .. }) => item,
_ => bug!("expected impl item, found {}", self.node_to_string(HirId::make_owner(id))), _ => bug!("expected impl item, found {}", self.node_to_string(HirId::make_owner(id))),
} }
} }
pub fn expect_trait_item(self, id: LocalDefId) -> &'hir TraitItem<'hir> { pub fn expect_trait_item(self, id: LocalDefId) -> &'hir TraitItem<'hir> {
match self.tcx.hir_owner(id) { match self.tcx.hir_owner(OwnerId { def_id: id }) {
Some(Owner { node: OwnerNode::TraitItem(item), .. }) => item, Some(Owner { node: OwnerNode::TraitItem(item), .. }) => item,
_ => bug!("expected trait item, found {}", self.node_to_string(HirId::make_owner(id))), _ => bug!("expected trait item, found {}", self.node_to_string(HirId::make_owner(id))),
} }
@ -850,11 +850,14 @@ impl<'hir> Map<'hir> {
} }
} }
pub fn expect_foreign_item(self, id: LocalDefId) -> &'hir ForeignItem<'hir> { pub fn expect_foreign_item(self, id: OwnerId) -> &'hir ForeignItem<'hir> {
match self.tcx.hir_owner(id) { match self.tcx.hir_owner(id) {
Some(Owner { node: OwnerNode::ForeignItem(item), .. }) => item, Some(Owner { node: OwnerNode::ForeignItem(item), .. }) => item,
_ => { _ => {
bug!("expected foreign item, found {}", self.node_to_string(HirId::make_owner(id))) bug!(
"expected foreign item, found {}",
self.node_to_string(HirId::make_owner(id.def_id))
)
} }
} }
} }
@ -1290,7 +1293,7 @@ pub(crate) fn hir_crate_items(tcx: TyCtxt<'_>, _: ()) -> ModuleItems {
// A "crate collector" and "module collector" start at a // A "crate collector" and "module collector" start at a
// module item (the former starts at the crate root) but only // module item (the former starts at the crate root) but only
// the former needs to collect it. ItemCollector does not do this for us. // the former needs to collect it. ItemCollector does not do this for us.
collector.submodules.push(CRATE_DEF_ID); collector.submodules.push(CRATE_OWNER_ID);
tcx.hir().walk_toplevel_module(&mut collector); tcx.hir().walk_toplevel_module(&mut collector);
let ItemCollector { let ItemCollector {
@ -1318,7 +1321,7 @@ struct ItemCollector<'tcx> {
// otherwise it collects items in some module. // otherwise it collects items in some module.
crate_collector: bool, crate_collector: bool,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
submodules: Vec<LocalDefId>, submodules: Vec<OwnerId>,
items: Vec<ItemId>, items: Vec<ItemId>,
trait_items: Vec<TraitItemId>, trait_items: Vec<TraitItemId>,
impl_items: Vec<ImplItemId>, impl_items: Vec<ImplItemId>,
@ -1350,7 +1353,7 @@ impl<'hir> Visitor<'hir> for ItemCollector<'hir> {
fn visit_item(&mut self, item: &'hir Item<'hir>) { fn visit_item(&mut self, item: &'hir Item<'hir>) {
if associated_body(Node::Item(item)).is_some() { if associated_body(Node::Item(item)).is_some() {
self.body_owners.push(item.def_id); self.body_owners.push(item.def_id.def_id);
} }
self.items.push(item.item_id()); self.items.push(item.item_id());
@ -1386,7 +1389,7 @@ impl<'hir> Visitor<'hir> for ItemCollector<'hir> {
fn visit_trait_item(&mut self, item: &'hir TraitItem<'hir>) { fn visit_trait_item(&mut self, item: &'hir TraitItem<'hir>) {
if associated_body(Node::TraitItem(item)).is_some() { if associated_body(Node::TraitItem(item)).is_some() {
self.body_owners.push(item.def_id); self.body_owners.push(item.def_id.def_id);
} }
self.trait_items.push(item.trait_item_id()); self.trait_items.push(item.trait_item_id());
@ -1395,7 +1398,7 @@ impl<'hir> Visitor<'hir> for ItemCollector<'hir> {
fn visit_impl_item(&mut self, item: &'hir ImplItem<'hir>) { fn visit_impl_item(&mut self, item: &'hir ImplItem<'hir>) {
if associated_body(Node::ImplItem(item)).is_some() { if associated_body(Node::ImplItem(item)).is_some() {
self.body_owners.push(item.def_id); self.body_owners.push(item.def_id.def_id);
} }
self.impl_items.push(item.impl_item_id()); self.impl_items.push(item.impl_item_id());

View File

@ -39,7 +39,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Owner<'tcx> {
/// bodies. The Ids are in visitor order. This is used to partition a pass between modules. /// bodies. The Ids are in visitor order. This is used to partition a pass between modules.
#[derive(Debug, HashStable, Encodable, Decodable)] #[derive(Debug, HashStable, Encodable, Decodable)]
pub struct ModuleItems { pub struct ModuleItems {
submodules: Box<[LocalDefId]>, submodules: Box<[OwnerId]>,
items: Box<[ItemId]>, items: Box<[ItemId]>,
trait_items: Box<[TraitItemId]>, trait_items: Box<[TraitItemId]>,
impl_items: Box<[ImplItemId]>, impl_items: Box<[ImplItemId]>,
@ -67,10 +67,10 @@ impl ModuleItems {
pub fn definitions(&self) -> impl Iterator<Item = LocalDefId> + '_ { pub fn definitions(&self) -> impl Iterator<Item = LocalDefId> + '_ {
self.items self.items
.iter() .iter()
.map(|id| id.def_id) .map(|id| id.def_id.def_id)
.chain(self.trait_items.iter().map(|id| id.def_id)) .chain(self.trait_items.iter().map(|id| id.def_id.def_id))
.chain(self.impl_items.iter().map(|id| id.def_id)) .chain(self.impl_items.iter().map(|id| id.def_id.def_id))
.chain(self.foreign_items.iter().map(|id| id.def_id)) .chain(self.foreign_items.iter().map(|id| id.def_id.def_id))
} }
pub fn par_items(&self, f: impl Fn(ItemId) + Send + Sync) { pub fn par_items(&self, f: impl Fn(ItemId) + Send + Sync) {
@ -97,7 +97,7 @@ impl<'tcx> TyCtxt<'tcx> {
} }
pub fn parent_module(self, id: HirId) -> LocalDefId { pub fn parent_module(self, id: HirId) -> LocalDefId {
self.parent_module_from_def_id(id.owner) self.parent_module_from_def_id(id.owner.def_id)
} }
pub fn impl_subject(self, def_id: DefId) -> ImplSubject<'tcx> { pub fn impl_subject(self, def_id: DefId) -> ImplSubject<'tcx> {
@ -110,13 +110,13 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn provide(providers: &mut Providers) { pub fn provide(providers: &mut Providers) {
providers.parent_module_from_def_id = |tcx, id| { providers.parent_module_from_def_id = |tcx, id| {
let hir = tcx.hir(); let hir = tcx.hir();
hir.get_module_parent_node(hir.local_def_id_to_hir_id(id)) hir.get_module_parent_node(hir.local_def_id_to_hir_id(id)).def_id
}; };
providers.hir_crate_items = map::hir_crate_items; providers.hir_crate_items = map::hir_crate_items;
providers.crate_hash = map::crate_hash; providers.crate_hash = map::crate_hash;
providers.hir_module_items = map::hir_module_items; providers.hir_module_items = map::hir_module_items;
providers.hir_owner = |tcx, id| { providers.hir_owner = |tcx, id| {
let owner = tcx.hir_crate(()).owners.get(id)?.as_owner()?; let owner = tcx.hir_crate(()).owners.get(id.def_id)?.as_owner()?;
let node = owner.node(); let node = owner.node();
Some(Owner { node, hash_without_bodies: owner.nodes.hash_without_bodies }) Some(Owner { node, hash_without_bodies: owner.nodes.hash_without_bodies })
}; };
@ -128,21 +128,24 @@ pub fn provide(providers: &mut Providers) {
MaybeOwner::NonOwner(hir_id) => hir_id, MaybeOwner::NonOwner(hir_id) => hir_id,
} }
}; };
providers.hir_owner_nodes = |tcx, id| tcx.hir_crate(()).owners[id].map(|i| &i.nodes); providers.hir_owner_nodes = |tcx, id| tcx.hir_crate(()).owners[id.def_id].map(|i| &i.nodes);
providers.hir_owner_parent = |tcx, id| { providers.hir_owner_parent = |tcx, id| {
// Accessing the local_parent is ok since its value is hashed as part of `id`'s DefPathHash. // Accessing the local_parent is ok since its value is hashed as part of `id`'s DefPathHash.
tcx.opt_local_parent(id).map_or(CRATE_HIR_ID, |parent| { tcx.opt_local_parent(id.def_id).map_or(CRATE_HIR_ID, |parent| {
let mut parent_hir_id = tcx.hir().local_def_id_to_hir_id(parent); let mut parent_hir_id = tcx.hir().local_def_id_to_hir_id(parent);
if let Some(local_id) = if let Some(local_id) = tcx.hir_crate(()).owners[parent_hir_id.owner.def_id]
tcx.hir_crate(()).owners[parent_hir_id.owner].unwrap().parenting.get(&id) .unwrap()
.parenting
.get(&id.def_id)
{ {
parent_hir_id.local_id = *local_id; parent_hir_id.local_id = *local_id;
} }
parent_hir_id parent_hir_id
}) })
}; };
providers.hir_attrs = providers.hir_attrs = |tcx, id| {
|tcx, id| tcx.hir_crate(()).owners[id].as_owner().map_or(AttributeMap::EMPTY, |o| &o.attrs); tcx.hir_crate(()).owners[id.def_id].as_owner().map_or(AttributeMap::EMPTY, |o| &o.attrs)
};
providers.source_span = providers.source_span =
|tcx, def_id| tcx.resolutions(()).source_span.get(def_id).copied().unwrap_or(DUMMY_SP); |tcx, def_id| tcx.resolutions(()).source_span.get(def_id).copied().unwrap_or(DUMMY_SP);
providers.def_span = |tcx, def_id| { providers.def_span = |tcx, def_id| {
@ -177,6 +180,7 @@ pub fn provide(providers: &mut Providers) {
let id = id.expect_local(); let id = id.expect_local();
tcx.resolutions(()).expn_that_defined.get(&id).copied().unwrap_or(ExpnId::root()) tcx.resolutions(()).expn_that_defined.get(&id).copied().unwrap_or(ExpnId::root())
}; };
providers.in_scope_traits_map = providers.in_scope_traits_map = |tcx, id| {
|tcx, id| tcx.hir_crate(()).owners[id].as_owner().map(|owner_info| &owner_info.trait_map); tcx.hir_crate(()).owners[id.def_id].as_owner().map(|owner_info| &owner_info.trait_map)
};
} }

View File

@ -3,8 +3,8 @@
use crate::ty; use crate::ty;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::def_id::DefId;
use rustc_hir::ItemLocalId; use rustc_hir::{ItemLocalId, OwnerId};
use rustc_macros::HashStable; use rustc_macros::HashStable;
#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Debug, HashStable)] #[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Debug, HashStable)]
@ -49,7 +49,7 @@ pub enum ObjectLifetimeDefault {
pub struct ResolveLifetimes { pub struct ResolveLifetimes {
/// Maps from every use of a named (not anonymous) lifetime to a /// Maps from every use of a named (not anonymous) lifetime to a
/// `Region` describing how that region is bound /// `Region` describing how that region is bound
pub defs: FxHashMap<LocalDefId, FxHashMap<ItemLocalId, Region>>, pub defs: FxHashMap<OwnerId, FxHashMap<ItemLocalId, Region>>,
pub late_bound_vars: FxHashMap<LocalDefId, FxHashMap<ItemLocalId, Vec<ty::BoundVariableKind>>>, pub late_bound_vars: FxHashMap<OwnerId, FxHashMap<ItemLocalId, Vec<ty::BoundVariableKind>>>,
} }

View File

@ -182,7 +182,7 @@ impl<'tcx> MonoItem<'tcx> {
match *self { match *self {
MonoItem::Fn(Instance { def, .. }) => def.def_id().as_local(), MonoItem::Fn(Instance { def, .. }) => def.def_id().as_local(),
MonoItem::Static(def_id) => def_id.as_local(), MonoItem::Static(def_id) => def_id.as_local(),
MonoItem::GlobalAsm(item_id) => Some(item_id.def_id), MonoItem::GlobalAsm(item_id) => Some(item_id.def_id.def_id),
} }
.map(|def_id| tcx.def_span(def_id)) .map(|def_id| tcx.def_span(def_id))
} }
@ -373,7 +373,7 @@ impl<'tcx> CodegenUnit<'tcx> {
} }
} }
MonoItem::Static(def_id) => def_id.as_local().map(Idx::index), MonoItem::Static(def_id) => def_id.as_local().map(Idx::index),
MonoItem::GlobalAsm(item_id) => Some(item_id.def_id.index()), MonoItem::GlobalAsm(item_id) => Some(item_id.def_id.def_id.index()),
}, },
item.symbol_name(tcx), item.symbol_name(tcx),
) )

View File

@ -73,7 +73,7 @@ rustc_queries! {
/// ///
/// This can be conveniently accessed by methods on `tcx.hir()`. /// This can be conveniently accessed by methods on `tcx.hir()`.
/// Avoid calling this query directly. /// Avoid calling this query directly.
query hir_owner(key: LocalDefId) -> Option<crate::hir::Owner<'tcx>> { query hir_owner(key: hir::OwnerId) -> Option<crate::hir::Owner<'tcx>> {
desc { |tcx| "HIR owner of `{}`", tcx.def_path_str(key.to_def_id()) } desc { |tcx| "HIR owner of `{}`", tcx.def_path_str(key.to_def_id()) }
} }
@ -89,7 +89,7 @@ rustc_queries! {
/// ///
/// This can be conveniently accessed by methods on `tcx.hir()`. /// This can be conveniently accessed by methods on `tcx.hir()`.
/// Avoid calling this query directly. /// Avoid calling this query directly.
query hir_owner_parent(key: LocalDefId) -> hir::HirId { query hir_owner_parent(key: hir::OwnerId) -> hir::HirId {
desc { |tcx| "HIR parent of `{}`", tcx.def_path_str(key.to_def_id()) } desc { |tcx| "HIR parent of `{}`", tcx.def_path_str(key.to_def_id()) }
} }
@ -97,7 +97,7 @@ rustc_queries! {
/// ///
/// This can be conveniently accessed by methods on `tcx.hir()`. /// This can be conveniently accessed by methods on `tcx.hir()`.
/// Avoid calling this query directly. /// Avoid calling this query directly.
query hir_owner_nodes(key: LocalDefId) -> hir::MaybeOwner<&'tcx hir::OwnerNodes<'tcx>> { query hir_owner_nodes(key: hir::OwnerId) -> hir::MaybeOwner<&'tcx hir::OwnerNodes<'tcx>> {
desc { |tcx| "HIR owner items in `{}`", tcx.def_path_str(key.to_def_id()) } desc { |tcx| "HIR owner items in `{}`", tcx.def_path_str(key.to_def_id()) }
} }
@ -105,7 +105,7 @@ rustc_queries! {
/// ///
/// This can be conveniently accessed by methods on `tcx.hir()`. /// This can be conveniently accessed by methods on `tcx.hir()`.
/// Avoid calling this query directly. /// Avoid calling this query directly.
query hir_attrs(key: LocalDefId) -> &'tcx hir::AttributeMap<'tcx> { query hir_attrs(key: hir::OwnerId) -> &'tcx hir::AttributeMap<'tcx> {
desc { |tcx| "HIR owner attributes in `{}`", tcx.def_path_str(key.to_def_id()) } desc { |tcx| "HIR owner attributes in `{}`", tcx.def_path_str(key.to_def_id()) }
} }
@ -1404,7 +1404,7 @@ rustc_queries! {
query specializes(_: (DefId, DefId)) -> bool { query specializes(_: (DefId, DefId)) -> bool {
desc { "computing whether impls specialize one another" } desc { "computing whether impls specialize one another" }
} }
query in_scope_traits_map(_: LocalDefId) query in_scope_traits_map(_: hir::OwnerId)
-> Option<&'tcx FxHashMap<ItemLocalId, Box<[TraitCandidate]>>> { -> Option<&'tcx FxHashMap<ItemLocalId, Box<[TraitCandidate]>>> {
desc { "traits in scope at a block" } desc { "traits in scope at a block" }
} }
@ -1419,7 +1419,7 @@ rustc_queries! {
separate_provide_extern separate_provide_extern
} }
query check_well_formed(key: LocalDefId) -> () { query check_well_formed(key: hir::OwnerId) -> () {
desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) } desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
} }
@ -1586,7 +1586,7 @@ rustc_queries! {
arena_cache arena_cache
desc { "resolving lifetimes" } desc { "resolving lifetimes" }
} }
query named_region_map(_: LocalDefId) -> query named_region_map(_: hir::OwnerId) ->
Option<&'tcx FxHashMap<ItemLocalId, Region>> { Option<&'tcx FxHashMap<ItemLocalId, Region>> {
desc { "looking up a named region" } desc { "looking up a named region" }
} }
@ -1602,7 +1602,7 @@ rustc_queries! {
desc { "looking up lifetime defaults for generic parameter `{}`", tcx.def_path_str(key) } desc { "looking up lifetime defaults for generic parameter `{}`", tcx.def_path_str(key) }
separate_provide_extern separate_provide_extern
} }
query late_bound_vars_map(_: LocalDefId) query late_bound_vars_map(_: hir::OwnerId)
-> Option<&'tcx FxHashMap<ItemLocalId, Vec<ty::BoundVariableKind>>> { -> Option<&'tcx FxHashMap<ItemLocalId, Vec<ty::BoundVariableKind>>> {
desc { "looking up late bound vars" } desc { "looking up late bound vars" }
} }

View File

@ -40,6 +40,7 @@ use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LOCAL_CRATE}; use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LOCAL_CRATE};
use rustc_hir::definitions::Definitions; use rustc_hir::definitions::Definitions;
use rustc_hir::hir_id::OwnerId;
use rustc_hir::intravisit::Visitor; use rustc_hir::intravisit::Visitor;
use rustc_hir::lang_items::LangItem; use rustc_hir::lang_items::LangItem;
use rustc_hir::{ use rustc_hir::{
@ -289,7 +290,7 @@ pub struct CommonConsts<'tcx> {
} }
pub struct LocalTableInContext<'a, V> { pub struct LocalTableInContext<'a, V> {
hir_owner: LocalDefId, hir_owner: OwnerId,
data: &'a ItemLocalMap<V>, data: &'a ItemLocalMap<V>,
} }
@ -301,7 +302,7 @@ pub struct LocalTableInContext<'a, V> {
/// would result in lookup errors, or worse, in silently wrong data being /// would result in lookup errors, or worse, in silently wrong data being
/// stored/returned. /// stored/returned.
#[inline] #[inline]
fn validate_hir_id_for_typeck_results(hir_owner: LocalDefId, hir_id: hir::HirId) { fn validate_hir_id_for_typeck_results(hir_owner: OwnerId, hir_id: hir::HirId) {
if hir_id.owner != hir_owner { if hir_id.owner != hir_owner {
invalid_hir_id_for_typeck_results(hir_owner, hir_id); invalid_hir_id_for_typeck_results(hir_owner, hir_id);
} }
@ -309,7 +310,7 @@ fn validate_hir_id_for_typeck_results(hir_owner: LocalDefId, hir_id: hir::HirId)
#[cold] #[cold]
#[inline(never)] #[inline(never)]
fn invalid_hir_id_for_typeck_results(hir_owner: LocalDefId, hir_id: hir::HirId) { fn invalid_hir_id_for_typeck_results(hir_owner: OwnerId, hir_id: hir::HirId) {
ty::tls::with(|tcx| { ty::tls::with(|tcx| {
bug!( bug!(
"node {} with HirId::owner {:?} cannot be placed in TypeckResults with hir_owner {:?}", "node {} with HirId::owner {:?} cannot be placed in TypeckResults with hir_owner {:?}",
@ -345,7 +346,7 @@ impl<'a, V> ::std::ops::Index<hir::HirId> for LocalTableInContext<'a, V> {
} }
pub struct LocalTableInContextMut<'a, V> { pub struct LocalTableInContextMut<'a, V> {
hir_owner: LocalDefId, hir_owner: OwnerId,
data: &'a mut ItemLocalMap<V>, data: &'a mut ItemLocalMap<V>,
} }
@ -417,7 +418,7 @@ pub struct GeneratorDiagnosticData<'tcx> {
#[derive(TyEncodable, TyDecodable, Debug, HashStable)] #[derive(TyEncodable, TyDecodable, Debug, HashStable)]
pub struct TypeckResults<'tcx> { pub struct TypeckResults<'tcx> {
/// The `HirId::owner` all `ItemLocalId`s in this table are relative to. /// The `HirId::owner` all `ItemLocalId`s in this table are relative to.
pub hir_owner: LocalDefId, pub hir_owner: OwnerId,
/// Resolved definitions for `<T>::X` associated paths and /// Resolved definitions for `<T>::X` associated paths and
/// method calls, including those of overloaded operators. /// method calls, including those of overloaded operators.
@ -592,7 +593,7 @@ pub struct TypeckResults<'tcx> {
} }
impl<'tcx> TypeckResults<'tcx> { impl<'tcx> TypeckResults<'tcx> {
pub fn new(hir_owner: LocalDefId) -> TypeckResults<'tcx> { pub fn new(hir_owner: OwnerId) -> TypeckResults<'tcx> {
TypeckResults { TypeckResults {
hir_owner, hir_owner,
type_dependent_defs: Default::default(), type_dependent_defs: Default::default(),
@ -1726,7 +1727,7 @@ impl<'tcx> TyCtxt<'tcx> {
#[inline] #[inline]
pub fn local_visibility(self, def_id: LocalDefId) -> Visibility { pub fn local_visibility(self, def_id: LocalDefId) -> Visibility {
self.visibility(def_id.to_def_id()).expect_local() self.visibility(def_id).expect_local()
} }
} }
@ -2907,7 +2908,7 @@ impl<'tcx> TyCtxt<'tcx> {
} }
pub fn is_late_bound(self, id: HirId) -> bool { pub fn is_late_bound(self, id: HirId) -> bool {
self.is_late_bound_map(id.owner).map_or(false, |set| { self.is_late_bound_map(id.owner.def_id).map_or(false, |set| {
let def_id = self.hir().local_def_id(id); let def_id = self.hir().local_def_id(id);
set.contains(&def_id) set.contains(&def_id)
}) })

View File

@ -861,7 +861,7 @@ fn foo(&self) -> Self::T { String::new() }
// When `body_owner` is an `impl` or `trait` item, look in its associated types for // When `body_owner` is an `impl` or `trait` item, look in its associated types for
// `expected` and point at it. // `expected` and point at it.
let parent_id = self.hir().get_parent_item(hir_id); let parent_id = self.hir().get_parent_item(hir_id);
let item = self.hir().find_by_def_id(parent_id); let item = self.hir().find_by_def_id(parent_id.def_id);
debug!("expected_projection parent item {:?}", item); debug!("expected_projection parent item {:?}", item);
match item { match item {
Some(hir::Node::Item(hir::Item { kind: hir::ItemKind::Trait(.., items), .. })) => { Some(hir::Node::Item(hir::Item { kind: hir::ItemKind::Trait(.., items), .. })) => {

View File

@ -44,6 +44,7 @@ use rustc_errors::ErrorGuaranteed;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::DefKind; use rustc_hir::def::DefKind;
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, LocalDefId}; use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, LocalDefId};
use rustc_hir::hir_id::OwnerId;
use rustc_hir::lang_items::{LangItem, LanguageItems}; use rustc_hir::lang_items::{LangItem, LanguageItems};
use rustc_hir::{Crate, ItemLocalId, TraitCandidate}; use rustc_hir::{Crate, ItemLocalId, TraitCandidate};
use rustc_index::{bit_set::FiniteBitSet, vec::IndexVec}; use rustc_index::{bit_set::FiniteBitSet, vec::IndexVec};
@ -336,7 +337,7 @@ macro_rules! define_callbacks {
rustc_query_append! { define_callbacks! } rustc_query_append! { define_callbacks! }
mod sealed { mod sealed {
use super::{DefId, LocalDefId}; use super::{DefId, LocalDefId, OwnerId};
/// An analogue of the `Into` trait that's intended only for query parameters. /// An analogue of the `Into` trait that's intended only for query parameters.
/// ///
@ -366,6 +367,13 @@ mod sealed {
self.to_def_id() self.to_def_id()
} }
} }
impl IntoQueryParam<DefId> for OwnerId {
#[inline(always)]
fn into_query_param(self) -> DefId {
self.to_def_id()
}
}
} }
use sealed::IntoQueryParam; use sealed::IntoQueryParam;

View File

@ -1246,7 +1246,7 @@ impl<'v> RootCollector<'_, 'v> {
} }
} }
DefKind::Fn => { DefKind::Fn => {
self.push_if_root(id.def_id); self.push_if_root(id.def_id.def_id);
} }
_ => {} _ => {}
} }
@ -1254,7 +1254,7 @@ impl<'v> RootCollector<'_, 'v> {
fn process_impl_item(&mut self, id: hir::ImplItemId) { fn process_impl_item(&mut self, id: hir::ImplItemId) {
if matches!(self.tcx.def_kind(id.def_id), DefKind::AssocFn) { if matches!(self.tcx.def_kind(id.def_id), DefKind::AssocFn) {
self.push_if_root(id.def_id); self.push_if_root(id.def_id.def_id);
} }
} }

View File

@ -11,9 +11,11 @@ use rustc_errors::{fluent, struct_span_err, Applicability, MultiSpan};
use rustc_expand::base::resolve_path; use rustc_expand::base::resolve_path;
use rustc_feature::{AttributeDuplicates, AttributeType, BuiltinAttribute, BUILTIN_ATTRIBUTE_MAP}; use rustc_feature::{AttributeDuplicates, AttributeType, BuiltinAttribute, BUILTIN_ATTRIBUTE_MAP};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID}; use rustc_hir::def_id::LocalDefId;
use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::{self, FnSig, ForeignItem, HirId, Item, ItemKind, TraitItem, CRATE_HIR_ID}; use rustc_hir::{
self, FnSig, ForeignItem, HirId, Item, ItemKind, TraitItem, CRATE_HIR_ID, CRATE_OWNER_ID,
};
use rustc_hir::{MethodKind, Target}; use rustc_hir::{MethodKind, Target};
use rustc_middle::hir::nested_filter; use rustc_middle::hir::nested_filter;
use rustc_middle::middle::resolve_lifetime::ObjectLifetimeDefault; use rustc_middle::middle::resolve_lifetime::ObjectLifetimeDefault;
@ -35,7 +37,7 @@ pub(crate) fn target_from_impl_item<'tcx>(
match impl_item.kind { match impl_item.kind {
hir::ImplItemKind::Const(..) => Target::AssocConst, hir::ImplItemKind::Const(..) => Target::AssocConst,
hir::ImplItemKind::Fn(..) => { hir::ImplItemKind::Fn(..) => {
let parent_def_id = tcx.hir().get_parent_item(impl_item.hir_id()); let parent_def_id = tcx.hir().get_parent_item(impl_item.hir_id()).def_id;
let containing_item = tcx.hir().expect_item(parent_def_id); let containing_item = tcx.hir().expect_item(parent_def_id);
let containing_impl_is_for_trait = match &containing_item.kind { let containing_impl_is_for_trait = match &containing_item.kind {
hir::ItemKind::Impl(impl_) => impl_.of_trait.is_some(), hir::ItemKind::Impl(impl_) => impl_.of_trait.is_some(),
@ -640,7 +642,7 @@ impl CheckAttrVisitor<'_> {
let span = meta.span(); let span = meta.span();
if let Some(location) = match target { if let Some(location) = match target {
Target::AssocTy => { Target::AssocTy => {
let parent_def_id = self.tcx.hir().get_parent_item(hir_id); let parent_def_id = self.tcx.hir().get_parent_item(hir_id).def_id;
let containing_item = self.tcx.hir().expect_item(parent_def_id); let containing_item = self.tcx.hir().expect_item(parent_def_id);
if Target::from_item(containing_item) == Target::Impl { if Target::from_item(containing_item) == Target::Impl {
Some("type alias in implementation block") Some("type alias in implementation block")
@ -649,7 +651,7 @@ impl CheckAttrVisitor<'_> {
} }
} }
Target::AssocConst => { Target::AssocConst => {
let parent_def_id = self.tcx.hir().get_parent_item(hir_id); let parent_def_id = self.tcx.hir().get_parent_item(hir_id).def_id;
let containing_item = self.tcx.hir().expect_item(parent_def_id); let containing_item = self.tcx.hir().expect_item(parent_def_id);
// We can't link to trait impl's consts. // We can't link to trait impl's consts.
let err = "associated constant in trait implementation block"; let err = "associated constant in trait implementation block";
@ -878,7 +880,7 @@ impl CheckAttrVisitor<'_> {
self.tcx.struct_span_lint_hir(INVALID_DOC_ATTRIBUTES, hir_id, meta.span(), |lint| { self.tcx.struct_span_lint_hir(INVALID_DOC_ATTRIBUTES, hir_id, meta.span(), |lint| {
let mut err = lint.build(fluent::passes::attr_crate_level); let mut err = lint.build(fluent::passes::attr_crate_level);
if attr.style == AttrStyle::Outer if attr.style == AttrStyle::Outer
&& self.tcx.hir().get_parent_item(hir_id) == CRATE_DEF_ID && self.tcx.hir().get_parent_item(hir_id) == CRATE_OWNER_ID
{ {
if let Ok(mut src) = self.tcx.sess.source_map().span_to_snippet(attr.span) { if let Ok(mut src) = self.tcx.sess.source_map().span_to_snippet(attr.span) {
src.insert(1, '!'); src.insert(1, '!');

View File

@ -317,7 +317,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
intravisit::walk_trait_item(self, trait_item); intravisit::walk_trait_item(self, trait_item);
} }
Node::ImplItem(impl_item) => { Node::ImplItem(impl_item) => {
let item = self.tcx.local_parent(impl_item.def_id); let item = self.tcx.local_parent(impl_item.def_id.def_id);
if self.tcx.impl_trait_ref(item).is_none() { if self.tcx.impl_trait_ref(item).is_none() {
//// If it's a type whose items are live, then it's live, too. //// If it's a type whose items are live, then it's live, too.
//// This is done to handle the case where, for example, the static //// This is done to handle the case where, for example, the static
@ -374,7 +374,7 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
if has_repr_c || (f.is_positional() && has_repr_simd) { if has_repr_c || (f.is_positional() && has_repr_simd) {
return Some(def_id); return Some(def_id);
} }
if !tcx.visibility(f.hir_id.owner).is_public() { if !tcx.visibility(f.hir_id.owner.def_id).is_public() {
return None; return None;
} }
if tcx.visibility(def_id).is_public() { Some(def_id) } else { None } if tcx.visibility(def_id).is_public() { Some(def_id) } else { None }
@ -528,7 +528,7 @@ fn check_item<'tcx>(
) { ) {
let allow_dead_code = has_allow_dead_code_or_lang_attr(tcx, id.hir_id()); let allow_dead_code = has_allow_dead_code_or_lang_attr(tcx, id.hir_id());
if allow_dead_code { if allow_dead_code {
worklist.push(id.def_id); worklist.push(id.def_id.def_id);
} }
match tcx.def_kind(id.def_id) { match tcx.def_kind(id.def_id) {
@ -554,7 +554,7 @@ fn check_item<'tcx>(
let of_trait = tcx.impl_trait_ref(id.def_id); let of_trait = tcx.impl_trait_ref(id.def_id);
if of_trait.is_some() { if of_trait.is_some() {
worklist.push(id.def_id); worklist.push(id.def_id.def_id);
} }
// get DefIds from another query // get DefIds from another query
@ -577,12 +577,12 @@ fn check_item<'tcx>(
if let hir::ItemKind::Struct(ref variant_data, _) = item.kind if let hir::ItemKind::Struct(ref variant_data, _) = item.kind
&& let Some(ctor_hir_id) = variant_data.ctor_hir_id() && let Some(ctor_hir_id) = variant_data.ctor_hir_id()
{ {
struct_constructors.insert(tcx.hir().local_def_id(ctor_hir_id), item.def_id); struct_constructors.insert(tcx.hir().local_def_id(ctor_hir_id), item.def_id.def_id);
} }
} }
DefKind::GlobalAsm => { DefKind::GlobalAsm => {
// global_asm! is always live. // global_asm! is always live.
worklist.push(id.def_id); worklist.push(id.def_id.def_id);
} }
_ => {} _ => {}
} }
@ -595,7 +595,7 @@ fn check_trait_item<'tcx>(tcx: TyCtxt<'tcx>, worklist: &mut Vec<LocalDefId>, id:
if matches!(trait_item.kind, Const(_, Some(_)) | Fn(_, hir::TraitFn::Provided(_))) if matches!(trait_item.kind, Const(_, Some(_)) | Fn(_, hir::TraitFn::Provided(_)))
&& has_allow_dead_code_or_lang_attr(tcx, trait_item.hir_id()) && has_allow_dead_code_or_lang_attr(tcx, trait_item.hir_id())
{ {
worklist.push(trait_item.def_id); worklist.push(trait_item.def_id.def_id);
} }
} }
} }
@ -608,7 +608,7 @@ fn check_foreign_item<'tcx>(
if matches!(tcx.def_kind(id.def_id), DefKind::Static(_) | DefKind::Fn) if matches!(tcx.def_kind(id.def_id), DefKind::Static(_) | DefKind::Fn)
&& has_allow_dead_code_or_lang_attr(tcx, id.hir_id()) && has_allow_dead_code_or_lang_attr(tcx, id.hir_id())
{ {
worklist.push(id.def_id); worklist.push(id.def_id.def_id);
} }
} }
@ -871,13 +871,13 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalDefId) {
let module_items = tcx.hir_module_items(module); let module_items = tcx.hir_module_items(module);
for item in module_items.items() { for item in module_items.items() {
if !live_symbols.contains(&item.def_id) { if !live_symbols.contains(&item.def_id.def_id) {
let parent = tcx.local_parent(item.def_id); let parent = tcx.local_parent(item.def_id.def_id);
if parent != module && !live_symbols.contains(&parent) { if parent != module && !live_symbols.contains(&parent) {
// We already have diagnosed something. // We already have diagnosed something.
continue; continue;
} }
visitor.check_definition(item.def_id); visitor.check_definition(item.def_id.def_id);
continue; continue;
} }
@ -926,16 +926,21 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalDefId) {
visitor.warn_dead_fields_and_variants(def_id, "read", dead_fields, is_positional) visitor.warn_dead_fields_and_variants(def_id, "read", dead_fields, is_positional)
} }
visitor.warn_dead_fields_and_variants(item.def_id, "constructed", dead_variants, false); visitor.warn_dead_fields_and_variants(
item.def_id.def_id,
"constructed",
dead_variants,
false,
);
} }
} }
for impl_item in module_items.impl_items() { for impl_item in module_items.impl_items() {
visitor.check_definition(impl_item.def_id); visitor.check_definition(impl_item.def_id.def_id);
} }
for foreign_item in module_items.foreign_items() { for foreign_item in module_items.foreign_items() {
visitor.check_definition(foreign_item.def_id); visitor.check_definition(foreign_item.def_id.def_id);
} }
// We do not warn trait items. // We do not warn trait items.

View File

@ -74,19 +74,19 @@ fn diagnostic_items<'tcx>(tcx: TyCtxt<'tcx>, cnum: CrateNum) -> DiagnosticItems
let crate_items = tcx.hir_crate_items(()); let crate_items = tcx.hir_crate_items(());
for id in crate_items.items() { for id in crate_items.items() {
observe_item(tcx, &mut diagnostic_items, id.def_id); observe_item(tcx, &mut diagnostic_items, id.def_id.def_id);
} }
for id in crate_items.trait_items() { for id in crate_items.trait_items() {
observe_item(tcx, &mut diagnostic_items, id.def_id); observe_item(tcx, &mut diagnostic_items, id.def_id.def_id);
} }
for id in crate_items.impl_items() { for id in crate_items.impl_items() {
observe_item(tcx, &mut diagnostic_items, id.def_id); observe_item(tcx, &mut diagnostic_items, id.def_id.def_id);
} }
for id in crate_items.foreign_items() { for id in crate_items.foreign_items() {
observe_item(tcx, &mut diagnostic_items, id.def_id); observe_item(tcx, &mut diagnostic_items, id.def_id.def_id);
} }
diagnostic_items diagnostic_items

View File

@ -82,7 +82,7 @@ fn err_if_attr_found(ctxt: &EntryContext<'_>, id: ItemId, sym: Symbol, details:
} }
fn find_item(id: ItemId, ctxt: &mut EntryContext<'_>) { fn find_item(id: ItemId, ctxt: &mut EntryContext<'_>) {
let at_root = ctxt.tcx.opt_local_parent(id.def_id) == Some(CRATE_DEF_ID); let at_root = ctxt.tcx.opt_local_parent(id.def_id.def_id) == Some(CRATE_DEF_ID);
match entry_point_type(ctxt, id, at_root) { match entry_point_type(ctxt, id, at_root) {
EntryPointType::None => { EntryPointType::None => {
@ -99,7 +99,7 @@ fn find_item(id: ItemId, ctxt: &mut EntryContext<'_>) {
} }
EntryPointType::RustcMainAttr => { EntryPointType::RustcMainAttr => {
if ctxt.attr_main_fn.is_none() { if ctxt.attr_main_fn.is_none() {
ctxt.attr_main_fn = Some((id.def_id, ctxt.tcx.def_span(id.def_id.to_def_id()))); ctxt.attr_main_fn = Some((id.def_id.def_id, ctxt.tcx.def_span(id.def_id)));
} else { } else {
struct_span_err!( struct_span_err!(
ctxt.tcx.sess, ctxt.tcx.sess,
@ -118,11 +118,11 @@ fn find_item(id: ItemId, ctxt: &mut EntryContext<'_>) {
EntryPointType::Start => { EntryPointType::Start => {
err_if_attr_found(ctxt, id, sym::unix_sigpipe, "can only be used on `fn main()`"); err_if_attr_found(ctxt, id, sym::unix_sigpipe, "can only be used on `fn main()`");
if ctxt.start_fn.is_none() { if ctxt.start_fn.is_none() {
ctxt.start_fn = Some((id.def_id, ctxt.tcx.def_span(id.def_id.to_def_id()))); ctxt.start_fn = Some((id.def_id.def_id, ctxt.tcx.def_span(id.def_id)));
} else { } else {
struct_span_err!( struct_span_err!(
ctxt.tcx.sess, ctxt.tcx.sess,
ctxt.tcx.def_span(id.def_id.to_def_id()), ctxt.tcx.def_span(id.def_id),
E0138, E0138,
"multiple `start` functions" "multiple `start` functions"
) )

View File

@ -1,6 +1,5 @@
use rustc_data_structures::sync::Lock; use rustc_data_structures::sync::Lock;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
use rustc_hir::intravisit; use rustc_hir::intravisit;
use rustc_hir::{HirId, ItemLocalId}; use rustc_hir::{HirId, ItemLocalId};
use rustc_index::bit_set::GrowableBitSet; use rustc_index::bit_set::GrowableBitSet;
@ -42,7 +41,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
struct HirIdValidator<'a, 'hir> { struct HirIdValidator<'a, 'hir> {
hir_map: Map<'hir>, hir_map: Map<'hir>,
owner: Option<LocalDefId>, owner: Option<hir::OwnerId>,
hir_ids_seen: GrowableBitSet<ItemLocalId>, hir_ids_seen: GrowableBitSet<ItemLocalId>,
errors: &'a Lock<Vec<String>>, errors: &'a Lock<Vec<String>>,
} }
@ -63,12 +62,12 @@ impl<'a, 'hir> HirIdValidator<'a, 'hir> {
self.errors.lock().push(f()); self.errors.lock().push(f());
} }
fn check<F: FnOnce(&mut HirIdValidator<'a, 'hir>)>(&mut self, owner: LocalDefId, walk: F) { fn check<F: FnOnce(&mut HirIdValidator<'a, 'hir>)>(&mut self, owner: hir::OwnerId, walk: F) {
assert!(self.owner.is_none()); assert!(self.owner.is_none());
self.owner = Some(owner); self.owner = Some(owner);
walk(self); walk(self);
if owner == CRATE_DEF_ID { if owner == hir::CRATE_OWNER_ID {
return; return;
} }
@ -97,14 +96,14 @@ impl<'a, 'hir> HirIdValidator<'a, 'hir> {
missing_items.push(format!( missing_items.push(format!(
"[local_id: {}, owner: {}]", "[local_id: {}, owner: {}]",
local_id, local_id,
self.hir_map.def_path(owner).to_string_no_crate_verbose() self.hir_map.def_path(owner.def_id).to_string_no_crate_verbose()
)); ));
} }
self.error(|| { self.error(|| {
format!( format!(
"ItemLocalIds not assigned densely in {}. \ "ItemLocalIds not assigned densely in {}. \
Max ItemLocalId = {}, missing IDs = {:#?}; seens IDs = {:#?}", Max ItemLocalId = {}, missing IDs = {:#?}; seens IDs = {:#?}",
self.hir_map.def_path(owner).to_string_no_crate_verbose(), self.hir_map.def_path(owner.def_id).to_string_no_crate_verbose(),
max, max,
missing_items, missing_items,
self.hir_ids_seen self.hir_ids_seen
@ -138,8 +137,8 @@ impl<'a, 'hir> intravisit::Visitor<'hir> for HirIdValidator<'a, 'hir> {
format!( format!(
"HirIdValidator: The recorded owner of {} is {} instead of {}", "HirIdValidator: The recorded owner of {} is {} instead of {}",
self.hir_map.node_to_string(hir_id), self.hir_map.node_to_string(hir_id),
self.hir_map.def_path(hir_id.owner).to_string_no_crate_verbose(), self.hir_map.def_path(hir_id.owner.def_id).to_string_no_crate_verbose(),
self.hir_map.def_path(owner).to_string_no_crate_verbose() self.hir_map.def_path(owner.def_id).to_string_no_crate_verbose()
) )
}); });
} }

View File

@ -16,7 +16,7 @@ pub fn test_layout(tcx: TyCtxt<'_>) {
DefKind::TyAlias | DefKind::Enum | DefKind::Struct | DefKind::Union DefKind::TyAlias | DefKind::Enum | DefKind::Struct | DefKind::Union
) { ) {
for attr in tcx.get_attrs(id.def_id.to_def_id(), sym::rustc_layout) { for attr in tcx.get_attrs(id.def_id.to_def_id(), sym::rustc_layout) {
dump_layout_of(tcx, id.def_id, attr); dump_layout_of(tcx, id.def_id.def_id, attr);
} }
} }
} }

View File

@ -153,7 +153,7 @@ impl<'tcx> ReachableContext<'tcx> {
hir::ImplItemKind::Fn(..) => { hir::ImplItemKind::Fn(..) => {
let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id); let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id);
let impl_did = self.tcx.hir().get_parent_item(hir_id); let impl_did = self.tcx.hir().get_parent_item(hir_id);
method_might_be_inlined(self.tcx, impl_item, impl_did) method_might_be_inlined(self.tcx, impl_item, impl_did.def_id)
} }
hir::ImplItemKind::TyAlias(_) => false, hir::ImplItemKind::TyAlias(_) => false,
}, },
@ -305,8 +305,8 @@ fn check_item<'tcx>(
worklist: &mut Vec<LocalDefId>, worklist: &mut Vec<LocalDefId>,
access_levels: &privacy::AccessLevels, access_levels: &privacy::AccessLevels,
) { ) {
if has_custom_linkage(tcx, id.def_id) { if has_custom_linkage(tcx, id.def_id.def_id) {
worklist.push(id.def_id); worklist.push(id.def_id.def_id);
} }
if !matches!(tcx.def_kind(id.def_id), DefKind::Impl) { if !matches!(tcx.def_kind(id.def_id), DefKind::Impl) {
@ -318,8 +318,8 @@ fn check_item<'tcx>(
if let hir::ItemKind::Impl(hir::Impl { of_trait: Some(ref trait_ref), ref items, .. }) = if let hir::ItemKind::Impl(hir::Impl { of_trait: Some(ref trait_ref), ref items, .. }) =
item.kind item.kind
{ {
if !access_levels.is_reachable(item.def_id) { if !access_levels.is_reachable(item.def_id.def_id) {
worklist.extend(items.iter().map(|ii_ref| ii_ref.id.def_id)); worklist.extend(items.iter().map(|ii_ref| ii_ref.id.def_id.def_id));
let Res::Def(DefKind::Trait, trait_def_id) = trait_ref.path.res else { let Res::Def(DefKind::Trait, trait_def_id) = trait_ref.path.res else {
unreachable!(); unreachable!();
@ -403,8 +403,8 @@ fn reachable_set<'tcx>(tcx: TyCtxt<'tcx>, (): ()) -> FxHashSet<LocalDefId> {
} }
for id in crate_items.impl_items() { for id in crate_items.impl_items() {
if has_custom_linkage(tcx, id.def_id) { if has_custom_linkage(tcx, id.def_id.def_id) {
reachable_context.worklist.push(id.def_id); reachable_context.worklist.push(id.def_id.def_id);
} }
} }
} }

View File

@ -385,7 +385,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
} }
self.annotate( self.annotate(
i.def_id, i.def_id.def_id,
i.span, i.span,
fn_sig, fn_sig,
kind, kind,
@ -404,7 +404,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
}; };
self.annotate( self.annotate(
ti.def_id, ti.def_id.def_id,
ti.span, ti.span,
fn_sig, fn_sig,
AnnotationKind::Required, AnnotationKind::Required,
@ -427,7 +427,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
}; };
self.annotate( self.annotate(
ii.def_id, ii.def_id.def_id,
ii.span, ii.span,
fn_sig, fn_sig,
kind, kind,
@ -485,7 +485,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
fn visit_foreign_item(&mut self, i: &'tcx hir::ForeignItem<'tcx>) { fn visit_foreign_item(&mut self, i: &'tcx hir::ForeignItem<'tcx>) {
self.annotate( self.annotate(
i.def_id, i.def_id.def_id,
i.span, i.span,
None, None,
AnnotationKind::Required, AnnotationKind::Required,
@ -573,25 +573,25 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> {
hir::ItemKind::Impl(hir::Impl { of_trait: None, .. }) hir::ItemKind::Impl(hir::Impl { of_trait: None, .. })
| hir::ItemKind::ForeignMod { .. } | hir::ItemKind::ForeignMod { .. }
) { ) {
self.check_missing_stability(i.def_id, i.span); self.check_missing_stability(i.def_id.def_id, i.span);
} }
// Ensure stable `const fn` have a const stability attribute. // Ensure stable `const fn` have a const stability attribute.
self.check_missing_const_stability(i.def_id, i.span); self.check_missing_const_stability(i.def_id.def_id, i.span);
intravisit::walk_item(self, i) intravisit::walk_item(self, i)
} }
fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem<'tcx>) { fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem<'tcx>) {
self.check_missing_stability(ti.def_id, ti.span); self.check_missing_stability(ti.def_id.def_id, ti.span);
intravisit::walk_trait_item(self, ti); intravisit::walk_trait_item(self, ti);
} }
fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem<'tcx>) { fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem<'tcx>) {
let impl_def_id = self.tcx.hir().get_parent_item(ii.hir_id()); let impl_def_id = self.tcx.hir().get_parent_item(ii.hir_id());
if self.tcx.impl_trait_ref(impl_def_id).is_none() { if self.tcx.impl_trait_ref(impl_def_id).is_none() {
self.check_missing_stability(ii.def_id, ii.span); self.check_missing_stability(ii.def_id.def_id, ii.span);
self.check_missing_const_stability(ii.def_id, ii.span); self.check_missing_const_stability(ii.def_id.def_id, ii.span);
} }
intravisit::walk_impl_item(self, ii); intravisit::walk_impl_item(self, ii);
} }
@ -610,7 +610,7 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> {
} }
fn visit_foreign_item(&mut self, i: &'tcx hir::ForeignItem<'tcx>) { fn visit_foreign_item(&mut self, i: &'tcx hir::ForeignItem<'tcx>) {
self.check_missing_stability(i.def_id, i.span); self.check_missing_stability(i.def_id.def_id, i.span);
intravisit::walk_foreign_item(self, i); intravisit::walk_foreign_item(self, i);
} }
// Note that we don't need to `check_missing_stability` for default generic parameters, // Note that we don't need to `check_missing_stability` for default generic parameters,
@ -716,7 +716,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> {
return; return;
} }
let Some(cnum) = self.tcx.extern_mod_stmt_cnum(item.def_id) else { let Some(cnum) = self.tcx.extern_mod_stmt_cnum(item.def_id.def_id) else {
return; return;
}; };
let def_id = cnum.as_def_id(); let def_id = cnum.as_def_id();
@ -869,7 +869,7 @@ fn is_unstable_reexport<'tcx>(tcx: TyCtxt<'tcx>, id: hir::HirId) -> bool {
} }
// If this is a path that isn't a use, we don't need to do anything special // If this is a path that isn't a use, we don't need to do anything special
if !matches!(tcx.hir().item(hir::ItemId { def_id }).kind, ItemKind::Use(..)) { if !matches!(tcx.hir().expect_item(def_id).kind, ItemKind::Use(..)) {
return false; return false;
} }

View File

@ -506,8 +506,8 @@ impl<'tcx> EmbargoVisitor<'tcx> {
let module = self.tcx.hir().get_module(module_def_id).0; let module = self.tcx.hir().get_module(module_def_id).0;
for item_id in module.item_ids { for item_id in module.item_ids {
let def_kind = self.tcx.def_kind(item_id.def_id); let def_kind = self.tcx.def_kind(item_id.def_id);
let vis = self.tcx.local_visibility(item_id.def_id); let vis = self.tcx.local_visibility(item_id.def_id.def_id);
self.update_macro_reachable_def(item_id.def_id, def_kind, vis, defining_mod); self.update_macro_reachable_def(item_id.def_id.def_id, def_kind, vis, defining_mod);
} }
if let Some(exports) = self.tcx.module_reexports(module_def_id) { if let Some(exports) = self.tcx.module_reexports(module_def_id) {
for export in exports { for export in exports {
@ -627,11 +627,14 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
let item_level = match item.kind { let item_level = match item.kind {
hir::ItemKind::Impl { .. } => { hir::ItemKind::Impl { .. } => {
let impl_level = let impl_level = Option::<AccessLevel>::of_impl(
Option::<AccessLevel>::of_impl(item.def_id, self.tcx, &self.access_levels); item.def_id.def_id,
self.update(item.def_id, impl_level) self.tcx,
&self.access_levels,
);
self.update(item.def_id.def_id, impl_level)
} }
_ => self.get(item.def_id), _ => self.get(item.def_id.def_id),
}; };
// Update levels of nested things. // Update levels of nested things.
@ -652,13 +655,13 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
if impl_.of_trait.is_some() if impl_.of_trait.is_some()
|| self.tcx.visibility(impl_item_ref.id.def_id).is_public() || self.tcx.visibility(impl_item_ref.id.def_id).is_public()
{ {
self.update(impl_item_ref.id.def_id, item_level); self.update(impl_item_ref.id.def_id.def_id, item_level);
} }
} }
} }
hir::ItemKind::Trait(.., trait_item_refs) => { hir::ItemKind::Trait(.., trait_item_refs) => {
for trait_item_ref in trait_item_refs { for trait_item_ref in trait_item_refs {
self.update(trait_item_ref.id.def_id, item_level); self.update(trait_item_ref.id.def_id.def_id, item_level);
} }
} }
hir::ItemKind::Struct(ref def, _) | hir::ItemKind::Union(ref def, _) => { hir::ItemKind::Struct(ref def, _) | hir::ItemKind::Union(ref def, _) => {
@ -674,12 +677,12 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
} }
} }
hir::ItemKind::Macro(ref macro_def, _) => { hir::ItemKind::Macro(ref macro_def, _) => {
self.update_reachability_from_macro(item.def_id, macro_def); self.update_reachability_from_macro(item.def_id.def_id, macro_def);
} }
hir::ItemKind::ForeignMod { items, .. } => { hir::ItemKind::ForeignMod { items, .. } => {
for foreign_item in items { for foreign_item in items {
if self.tcx.visibility(foreign_item.id.def_id).is_public() { if self.tcx.visibility(foreign_item.id.def_id).is_public() {
self.update(foreign_item.id.def_id, item_level); self.update(foreign_item.id.def_id.def_id, item_level);
} }
} }
} }
@ -717,7 +720,7 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
// reachable if they are returned via `impl Trait`, even from private functions. // reachable if they are returned via `impl Trait`, even from private functions.
let exist_level = let exist_level =
cmp::max(item_level, Some(AccessLevel::ReachableFromImplTrait)); cmp::max(item_level, Some(AccessLevel::ReachableFromImplTrait));
self.reach(item.def_id, exist_level).generics().predicates().ty(); self.reach(item.def_id.def_id, exist_level).generics().predicates().ty();
} }
} }
// Visit everything. // Visit everything.
@ -726,16 +729,16 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
| hir::ItemKind::Fn(..) | hir::ItemKind::Fn(..)
| hir::ItemKind::TyAlias(..) => { | hir::ItemKind::TyAlias(..) => {
if item_level.is_some() { if item_level.is_some() {
self.reach(item.def_id, item_level).generics().predicates().ty(); self.reach(item.def_id.def_id, item_level).generics().predicates().ty();
} }
} }
hir::ItemKind::Trait(.., trait_item_refs) => { hir::ItemKind::Trait(.., trait_item_refs) => {
if item_level.is_some() { if item_level.is_some() {
self.reach(item.def_id, item_level).generics().predicates(); self.reach(item.def_id.def_id, item_level).generics().predicates();
for trait_item_ref in trait_item_refs { for trait_item_ref in trait_item_refs {
let tcx = self.tcx; let tcx = self.tcx;
let mut reach = self.reach(trait_item_ref.id.def_id, item_level); let mut reach = self.reach(trait_item_ref.id.def_id.def_id, item_level);
reach.generics().predicates(); reach.generics().predicates();
if trait_item_ref.kind == AssocItemKind::Type if trait_item_ref.kind == AssocItemKind::Type
@ -750,18 +753,22 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
} }
hir::ItemKind::TraitAlias(..) => { hir::ItemKind::TraitAlias(..) => {
if item_level.is_some() { if item_level.is_some() {
self.reach(item.def_id, item_level).generics().predicates(); self.reach(item.def_id.def_id, item_level).generics().predicates();
} }
} }
// Visit everything except for private impl items. // Visit everything except for private impl items.
hir::ItemKind::Impl(ref impl_) => { hir::ItemKind::Impl(ref impl_) => {
if item_level.is_some() { if item_level.is_some() {
self.reach(item.def_id, item_level).generics().predicates().ty().trait_ref(); self.reach(item.def_id.def_id, item_level)
.generics()
.predicates()
.ty()
.trait_ref();
for impl_item_ref in impl_.items { for impl_item_ref in impl_.items {
let impl_item_level = self.get(impl_item_ref.id.def_id); let impl_item_level = self.get(impl_item_ref.id.def_id.def_id);
if impl_item_level.is_some() { if impl_item_level.is_some() {
self.reach(impl_item_ref.id.def_id, impl_item_level) self.reach(impl_item_ref.id.def_id.def_id, impl_item_level)
.generics() .generics()
.predicates() .predicates()
.ty(); .ty();
@ -773,7 +780,7 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
// Visit everything, but enum variants have their own levels. // Visit everything, but enum variants have their own levels.
hir::ItemKind::Enum(ref def, _) => { hir::ItemKind::Enum(ref def, _) => {
if item_level.is_some() { if item_level.is_some() {
self.reach(item.def_id, item_level).generics().predicates(); self.reach(item.def_id.def_id, item_level).generics().predicates();
} }
for variant in def.variants { for variant in def.variants {
let variant_level = self.get(self.tcx.hir().local_def_id(variant.id)); let variant_level = self.get(self.tcx.hir().local_def_id(variant.id));
@ -784,13 +791,13 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
} }
// Corner case: if the variant is reachable, but its // Corner case: if the variant is reachable, but its
// enum is not, make the enum reachable as well. // enum is not, make the enum reachable as well.
self.reach(item.def_id, variant_level).ty(); self.reach(item.def_id.def_id, variant_level).ty();
} }
if let Some(hir_id) = variant.data.ctor_hir_id() { if let Some(hir_id) = variant.data.ctor_hir_id() {
let ctor_def_id = self.tcx.hir().local_def_id(hir_id); let ctor_def_id = self.tcx.hir().local_def_id(hir_id);
let ctor_level = self.get(ctor_def_id); let ctor_level = self.get(ctor_def_id);
if ctor_level.is_some() { if ctor_level.is_some() {
self.reach(item.def_id, ctor_level).ty(); self.reach(item.def_id.def_id, ctor_level).ty();
} }
} }
} }
@ -798,9 +805,9 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
// Visit everything, but foreign items have their own levels. // Visit everything, but foreign items have their own levels.
hir::ItemKind::ForeignMod { items, .. } => { hir::ItemKind::ForeignMod { items, .. } => {
for foreign_item in items { for foreign_item in items {
let foreign_item_level = self.get(foreign_item.id.def_id); let foreign_item_level = self.get(foreign_item.id.def_id.def_id);
if foreign_item_level.is_some() { if foreign_item_level.is_some() {
self.reach(foreign_item.id.def_id, foreign_item_level) self.reach(foreign_item.id.def_id.def_id, foreign_item_level)
.generics() .generics()
.predicates() .predicates()
.ty(); .ty();
@ -810,7 +817,7 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
// Visit everything except for private fields. // Visit everything except for private fields.
hir::ItemKind::Struct(ref struct_def, _) | hir::ItemKind::Union(ref struct_def, _) => { hir::ItemKind::Struct(ref struct_def, _) | hir::ItemKind::Union(ref struct_def, _) => {
if item_level.is_some() { if item_level.is_some() {
self.reach(item.def_id, item_level).generics().predicates(); self.reach(item.def_id.def_id, item_level).generics().predicates();
for field in struct_def.fields() { for field in struct_def.fields() {
let def_id = self.tcx.hir().local_def_id(field.hir_id); let def_id = self.tcx.hir().local_def_id(field.hir_id);
let field_level = self.get(def_id); let field_level = self.get(def_id);
@ -823,7 +830,7 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
let ctor_def_id = self.tcx.hir().local_def_id(hir_id); let ctor_def_id = self.tcx.hir().local_def_id(hir_id);
let ctor_level = self.get(ctor_def_id); let ctor_level = self.get(ctor_def_id);
if ctor_level.is_some() { if ctor_level.is_some() {
self.reach(item.def_id, ctor_level).ty(); self.reach(item.def_id.def_id, ctor_level).ty();
} }
} }
} }
@ -945,7 +952,7 @@ impl<'tcx, 'a> TestReachabilityVisitor<'tcx, 'a> {
impl<'tcx, 'a> Visitor<'tcx> for TestReachabilityVisitor<'tcx, 'a> { impl<'tcx, 'a> Visitor<'tcx> for TestReachabilityVisitor<'tcx, 'a> {
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
self.access_level_diagnostic(item.def_id); self.access_level_diagnostic(item.def_id.def_id);
match item.kind { match item.kind {
hir::ItemKind::Enum(ref def, _) => { hir::ItemKind::Enum(ref def, _) => {
@ -969,13 +976,13 @@ impl<'tcx, 'a> Visitor<'tcx> for TestReachabilityVisitor<'tcx, 'a> {
} }
fn visit_trait_item(&mut self, item: &'tcx hir::TraitItem<'tcx>) { fn visit_trait_item(&mut self, item: &'tcx hir::TraitItem<'tcx>) {
self.access_level_diagnostic(item.def_id); self.access_level_diagnostic(item.def_id.def_id);
} }
fn visit_impl_item(&mut self, item: &'tcx hir::ImplItem<'tcx>) { fn visit_impl_item(&mut self, item: &'tcx hir::ImplItem<'tcx>) {
self.access_level_diagnostic(item.def_id); self.access_level_diagnostic(item.def_id.def_id);
} }
fn visit_foreign_item(&mut self, item: &'tcx hir::ForeignItem<'tcx>) { fn visit_foreign_item(&mut self, item: &'tcx hir::ForeignItem<'tcx>) {
self.access_level_diagnostic(item.def_id); self.access_level_diagnostic(item.def_id.def_id);
} }
} }
@ -1058,7 +1065,7 @@ impl<'tcx> Visitor<'tcx> for NamePrivacyVisitor<'tcx> {
} }
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
let orig_current_item = mem::replace(&mut self.current_item, item.def_id); let orig_current_item = mem::replace(&mut self.current_item, item.def_id.def_id);
intravisit::walk_item(self, item); intravisit::walk_item(self, item);
self.current_item = orig_current_item; self.current_item = orig_current_item;
} }
@ -1361,7 +1368,7 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
// Check types in item interfaces. // Check types in item interfaces.
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
let orig_current_item = mem::replace(&mut self.current_item, item.def_id); let orig_current_item = mem::replace(&mut self.current_item, item.def_id.def_id);
let old_maybe_typeck_results = self.maybe_typeck_results.take(); let old_maybe_typeck_results = self.maybe_typeck_results.take();
intravisit::walk_item(self, item); intravisit::walk_item(self, item);
self.maybe_typeck_results = old_maybe_typeck_results; self.maybe_typeck_results = old_maybe_typeck_results;
@ -1503,7 +1510,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
hir::ItemKind::ForeignMod { .. } => {} hir::ItemKind::ForeignMod { .. } => {}
hir::ItemKind::Trait(.., bounds, _) => { hir::ItemKind::Trait(.., bounds, _) => {
if !self.trait_is_public(item.def_id) { if !self.trait_is_public(item.def_id.def_id) {
return; return;
} }
@ -1564,7 +1571,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
let impl_item = self.tcx.hir().impl_item(impl_item_ref.id); let impl_item = self.tcx.hir().impl_item(impl_item_ref.id);
match impl_item.kind { match impl_item.kind {
hir::ImplItemKind::Const(..) | hir::ImplItemKind::Fn(..) => { hir::ImplItemKind::Const(..) | hir::ImplItemKind::Fn(..) => {
self.access_levels.is_reachable(impl_item_ref.id.def_id) self.access_levels.is_reachable(impl_item_ref.id.def_id.def_id)
} }
hir::ImplItemKind::TyAlias(_) => false, hir::ImplItemKind::TyAlias(_) => false,
} }
@ -1584,7 +1591,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
let impl_item = self.tcx.hir().impl_item(impl_item_ref.id); let impl_item = self.tcx.hir().impl_item(impl_item_ref.id);
match impl_item.kind { match impl_item.kind {
hir::ImplItemKind::Const(..) | hir::ImplItemKind::Fn(..) hir::ImplItemKind::Const(..) | hir::ImplItemKind::Fn(..)
if self.item_is_public(impl_item.def_id) => if self.item_is_public(impl_item.def_id.def_id) =>
{ {
intravisit::walk_impl_item(self, impl_item) intravisit::walk_impl_item(self, impl_item)
} }
@ -1625,7 +1632,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
// methods will be visible as `Public::foo`. // methods will be visible as `Public::foo`.
let mut found_pub_static = false; let mut found_pub_static = false;
for impl_item_ref in impl_.items { for impl_item_ref in impl_.items {
if self.access_levels.is_reachable(impl_item_ref.id.def_id) if self.access_levels.is_reachable(impl_item_ref.id.def_id.def_id)
|| self.tcx.visibility(impl_item_ref.id.def_id).is_public() || self.tcx.visibility(impl_item_ref.id.def_id).is_public()
{ {
let impl_item = self.tcx.hir().impl_item(impl_item_ref.id); let impl_item = self.tcx.hir().impl_item(impl_item_ref.id);
@ -1654,7 +1661,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
hir::ItemKind::TyAlias(..) => return, hir::ItemKind::TyAlias(..) => return,
// Not at all public, so we don't care. // Not at all public, so we don't care.
_ if !self.item_is_public(item.def_id) => { _ if !self.item_is_public(item.def_id.def_id) => {
return; return;
} }
@ -1685,7 +1692,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
} }
fn visit_foreign_item(&mut self, item: &'tcx hir::ForeignItem<'tcx>) { fn visit_foreign_item(&mut self, item: &'tcx hir::ForeignItem<'tcx>) {
if self.access_levels.is_reachable(item.def_id) { if self.access_levels.is_reachable(item.def_id.def_id) {
intravisit::walk_foreign_item(self, item) intravisit::walk_foreign_item(self, item)
} }
} }
@ -1922,43 +1929,44 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'tcx> {
pub fn check_item(&mut self, id: ItemId) { pub fn check_item(&mut self, id: ItemId) {
let tcx = self.tcx; let tcx = self.tcx;
let item_visibility = tcx.local_visibility(id.def_id); let def_id = id.def_id.def_id;
let def_kind = tcx.def_kind(id.def_id); let item_visibility = tcx.local_visibility(def_id);
let def_kind = tcx.def_kind(def_id);
match def_kind { match def_kind {
DefKind::Const | DefKind::Static(_) | DefKind::Fn | DefKind::TyAlias => { DefKind::Const | DefKind::Static(_) | DefKind::Fn | DefKind::TyAlias => {
self.check(id.def_id, item_visibility).generics().predicates().ty(); self.check(def_id, item_visibility).generics().predicates().ty();
} }
DefKind::OpaqueTy => { DefKind::OpaqueTy => {
// `ty()` for opaque types is the underlying type, // `ty()` for opaque types is the underlying type,
// it's not a part of interface, so we skip it. // it's not a part of interface, so we skip it.
self.check(id.def_id, item_visibility).generics().bounds(); self.check(def_id, item_visibility).generics().bounds();
} }
DefKind::Trait => { DefKind::Trait => {
let item = tcx.hir().item(id); let item = tcx.hir().item(id);
if let hir::ItemKind::Trait(.., trait_item_refs) = item.kind { if let hir::ItemKind::Trait(.., trait_item_refs) = item.kind {
self.check(item.def_id, item_visibility).generics().predicates(); self.check(item.def_id.def_id, item_visibility).generics().predicates();
for trait_item_ref in trait_item_refs { for trait_item_ref in trait_item_refs {
self.check_assoc_item( self.check_assoc_item(
trait_item_ref.id.def_id, trait_item_ref.id.def_id.def_id,
trait_item_ref.kind, trait_item_ref.kind,
item_visibility, item_visibility,
); );
if let AssocItemKind::Type = trait_item_ref.kind { if let AssocItemKind::Type = trait_item_ref.kind {
self.check(trait_item_ref.id.def_id, item_visibility).bounds(); self.check(trait_item_ref.id.def_id.def_id, item_visibility).bounds();
} }
} }
} }
} }
DefKind::TraitAlias => { DefKind::TraitAlias => {
self.check(id.def_id, item_visibility).generics().predicates(); self.check(def_id, item_visibility).generics().predicates();
} }
DefKind::Enum => { DefKind::Enum => {
let item = tcx.hir().item(id); let item = tcx.hir().item(id);
if let hir::ItemKind::Enum(ref def, _) = item.kind { if let hir::ItemKind::Enum(ref def, _) = item.kind {
self.check(item.def_id, item_visibility).generics().predicates(); self.check(item.def_id.def_id, item_visibility).generics().predicates();
for variant in def.variants { for variant in def.variants {
for field in variant.data.fields() { for field in variant.data.fields() {
@ -1973,8 +1981,8 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'tcx> {
let item = tcx.hir().item(id); let item = tcx.hir().item(id);
if let hir::ItemKind::ForeignMod { items, .. } = item.kind { if let hir::ItemKind::ForeignMod { items, .. } = item.kind {
for foreign_item in items { for foreign_item in items {
let vis = tcx.local_visibility(foreign_item.id.def_id); let vis = tcx.local_visibility(foreign_item.id.def_id.def_id);
self.check(foreign_item.id.def_id, vis).generics().predicates().ty(); self.check(foreign_item.id.def_id.def_id, vis).generics().predicates().ty();
} }
} }
} }
@ -1984,7 +1992,7 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'tcx> {
if let hir::ItemKind::Struct(ref struct_def, _) if let hir::ItemKind::Struct(ref struct_def, _)
| hir::ItemKind::Union(ref struct_def, _) = item.kind | hir::ItemKind::Union(ref struct_def, _) = item.kind
{ {
self.check(item.def_id, item_visibility).generics().predicates(); self.check(item.def_id.def_id, item_visibility).generics().predicates();
for field in struct_def.fields() { for field in struct_def.fields() {
let def_id = tcx.hir().local_def_id(field.hir_id); let def_id = tcx.hir().local_def_id(field.hir_id);
@ -2000,20 +2008,21 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'tcx> {
DefKind::Impl => { DefKind::Impl => {
let item = tcx.hir().item(id); let item = tcx.hir().item(id);
if let hir::ItemKind::Impl(ref impl_) = item.kind { if let hir::ItemKind::Impl(ref impl_) = item.kind {
let impl_vis = ty::Visibility::of_impl(item.def_id, tcx, &Default::default()); let impl_vis =
ty::Visibility::of_impl(item.def_id.def_id, tcx, &Default::default());
// check that private components do not appear in the generics or predicates of inherent impls // check that private components do not appear in the generics or predicates of inherent impls
// this check is intentionally NOT performed for impls of traits, per #90586 // this check is intentionally NOT performed for impls of traits, per #90586
if impl_.of_trait.is_none() { if impl_.of_trait.is_none() {
self.check(item.def_id, impl_vis).generics().predicates(); self.check(item.def_id.def_id, impl_vis).generics().predicates();
} }
for impl_item_ref in impl_.items { for impl_item_ref in impl_.items {
let impl_item_vis = if impl_.of_trait.is_none() { let impl_item_vis = if impl_.of_trait.is_none() {
min(tcx.local_visibility(impl_item_ref.id.def_id), impl_vis, tcx) min(tcx.local_visibility(impl_item_ref.id.def_id.def_id), impl_vis, tcx)
} else { } else {
impl_vis impl_vis
}; };
self.check_assoc_item( self.check_assoc_item(
impl_item_ref.id.def_id, impl_item_ref.id.def_id.def_id,
impl_item_ref.kind, impl_item_ref.kind,
impl_item_vis, impl_item_vis,
); );
@ -2061,7 +2070,7 @@ fn local_visibility(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Visibility {
// Visibilities of trait impl items are inherited from their traits // Visibilities of trait impl items are inherited from their traits
// and are not filled in resolve. // and are not filled in resolve.
Node::ImplItem(impl_item) => { Node::ImplItem(impl_item) => {
match tcx.hir().get_by_def_id(tcx.hir().get_parent_item(hir_id)) { match tcx.hir().get_by_def_id(tcx.hir().get_parent_item(hir_id).def_id) {
Node::Item(hir::Item { Node::Item(hir::Item {
kind: hir::ItemKind::Impl(hir::Impl { of_trait: Some(tr), .. }), kind: hir::ItemKind::Impl(hir::Impl { of_trait: Some(tr), .. }),
.. ..

View File

@ -1,6 +1,7 @@
//! Defines the set of legal keys that can be used in queries. //! Defines the set of legal keys that can be used in queries.
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE}; use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
use rustc_hir::hir_id::OwnerId;
use rustc_middle::infer::canonical::Canonical; use rustc_middle::infer::canonical::Canonical;
use rustc_middle::mir; use rustc_middle::mir;
use rustc_middle::traits; use rustc_middle::traits;
@ -104,6 +105,19 @@ impl Key for CrateNum {
} }
} }
impl Key for OwnerId {
#[inline(always)]
fn query_crate_is_local(&self) -> bool {
true
}
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
self.to_def_id().default_span(tcx)
}
fn key_as_def_id(&self) -> Option<DefId> {
Some(self.to_def_id())
}
}
impl Key for LocalDefId { impl Key for LocalDefId {
#[inline(always)] #[inline(always)]
fn query_crate_is_local(&self) -> bool { fn query_crate_is_local(&self) -> bool {

View File

@ -41,7 +41,10 @@ pub struct StableHashingContext<'a> {
pub(super) enum BodyResolver<'tcx> { pub(super) enum BodyResolver<'tcx> {
Forbidden, Forbidden,
Ignore, Ignore,
Traverse { owner: LocalDefId, bodies: &'tcx SortedMap<hir::ItemLocalId, &'tcx hir::Body<'tcx>> }, Traverse {
owner: hir::OwnerId,
bodies: &'tcx SortedMap<hir::ItemLocalId, &'tcx hir::Body<'tcx>>,
},
} }
impl<'a> StableHashingContext<'a> { impl<'a> StableHashingContext<'a> {
@ -103,7 +106,7 @@ impl<'a> StableHashingContext<'a> {
#[inline] #[inline]
pub fn with_hir_bodies( pub fn with_hir_bodies(
&mut self, &mut self,
owner: LocalDefId, owner: hir::OwnerId,
bodies: &SortedMap<hir::ItemLocalId, &hir::Body<'_>>, bodies: &SortedMap<hir::ItemLocalId, &hir::Body<'_>>,
f: impl FnOnce(&mut StableHashingContext<'_>), f: impl FnOnce(&mut StableHashingContext<'_>),
) { ) {

View File

@ -339,24 +339,25 @@ fn convert_named_region_map(named_region_map: NamedRegionMap) -> ResolveLifetime
/// This allows us to avoid cycles. Importantly, if we ask for lifetimes for lifetimes that have an owner /// This allows us to avoid cycles. Importantly, if we ask for lifetimes for lifetimes that have an owner
/// other than the trait itself (like the trait methods or associated types), then we just use the regular /// other than the trait itself (like the trait methods or associated types), then we just use the regular
/// `resolve_lifetimes`. /// `resolve_lifetimes`.
fn resolve_lifetimes_for<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx ResolveLifetimes { fn resolve_lifetimes_for<'tcx>(tcx: TyCtxt<'tcx>, def_id: hir::OwnerId) -> &'tcx ResolveLifetimes {
let item_id = item_for(tcx, def_id); let item_id = item_for(tcx, def_id.def_id);
if item_id == def_id { let local_def_id = item_id.def_id.def_id;
let item = tcx.hir().item(hir::ItemId { def_id: item_id }); if item_id.def_id == def_id {
let item = tcx.hir().item(item_id);
match item.kind { match item.kind {
hir::ItemKind::Trait(..) => tcx.resolve_lifetimes_trait_definition(item_id), hir::ItemKind::Trait(..) => tcx.resolve_lifetimes_trait_definition(local_def_id),
_ => tcx.resolve_lifetimes(item_id), _ => tcx.resolve_lifetimes(local_def_id),
} }
} else { } else {
tcx.resolve_lifetimes(item_id) tcx.resolve_lifetimes(local_def_id)
} }
} }
/// Finds the `Item` that contains the given `LocalDefId` /// Finds the `Item` that contains the given `LocalDefId`
fn item_for(tcx: TyCtxt<'_>, local_def_id: LocalDefId) -> LocalDefId { fn item_for(tcx: TyCtxt<'_>, local_def_id: LocalDefId) -> hir::ItemId {
match tcx.hir().find_by_def_id(local_def_id) { match tcx.hir().find_by_def_id(local_def_id) {
Some(Node::Item(item)) => { Some(Node::Item(item)) => {
return item.def_id; return item.item_id();
} }
_ => {} _ => {}
} }
@ -366,7 +367,7 @@ fn item_for(tcx: TyCtxt<'_>, local_def_id: LocalDefId) -> LocalDefId {
loop { loop {
let node = parent_iter.next().map(|n| n.1); let node = parent_iter.next().map(|n| n.1);
match node { match node {
Some(hir::Node::Item(item)) => break item.def_id, Some(hir::Node::Item(item)) => break item.item_id(),
Some(hir::Node::Crate(_)) | None => bug!("Called `item_for` on an Item."), Some(hir::Node::Crate(_)) | None => bug!("Called `item_for` on an Item."),
_ => {} _ => {}
} }
@ -566,13 +567,12 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
// their owner, we can keep going until we find the Item that owns that. We then // their owner, we can keep going until we find the Item that owns that. We then
// conservatively add all resolved lifetimes. Otherwise we run into problems in // conservatively add all resolved lifetimes. Otherwise we run into problems in
// cases like `type Foo<'a> = impl Bar<As = impl Baz + 'a>`. // cases like `type Foo<'a> = impl Bar<As = impl Baz + 'a>`.
for (_hir_id, node) in for (_hir_id, node) in self.tcx.hir().parent_iter(item.def_id.into()) {
self.tcx.hir().parent_iter(self.tcx.hir().local_def_id_to_hir_id(item.def_id))
{
match node { match node {
hir::Node::Item(parent_item) => { hir::Node::Item(parent_item) => {
let resolved_lifetimes: &ResolveLifetimes = let resolved_lifetimes: &ResolveLifetimes = self.tcx.resolve_lifetimes(
self.tcx.resolve_lifetimes(item_for(self.tcx, parent_item.def_id)); item_for(self.tcx, parent_item.def_id.def_id).def_id.def_id,
);
// We need to add *all* deps, since opaque tys may want them from *us* // We need to add *all* deps, since opaque tys may want them from *us*
for (&owner, defs) in resolved_lifetimes.defs.iter() { for (&owner, defs) in resolved_lifetimes.defs.iter() {
defs.iter().for_each(|(&local_id, region)| { defs.iter().for_each(|(&local_id, region)| {
@ -1315,7 +1315,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
// regular fns. // regular fns.
if let Some(hir::PredicateOrigin::ImplTrait) = where_bound_origin if let Some(hir::PredicateOrigin::ImplTrait) = where_bound_origin
&& let hir::LifetimeName::Param(_, hir::ParamName::Fresh) = lifetime_ref.name && let hir::LifetimeName::Param(_, hir::ParamName::Fresh) = lifetime_ref.name
&& let hir::IsAsync::NotAsync = self.tcx.asyncness(lifetime_ref.hir_id.owner) && let hir::IsAsync::NotAsync = self.tcx.asyncness(lifetime_ref.hir_id.owner.def_id)
&& !self.tcx.features().anonymous_lifetime_in_impl_trait && !self.tcx.features().anonymous_lifetime_in_impl_trait
{ {
rustc_session::parse::feature_err( rustc_session::parse::feature_err(

View File

@ -345,14 +345,14 @@ impl<'tcx> DumpVisitor<'tcx> {
body: hir::BodyId, body: hir::BodyId,
) { ) {
let map = self.tcx.hir(); let map = self.tcx.hir();
self.nest_typeck_results(item.def_id, |v| { self.nest_typeck_results(item.def_id.def_id, |v| {
let body = map.body(body); let body = map.body(body);
if let Some(fn_data) = v.save_ctxt.get_item_data(item) { if let Some(fn_data) = v.save_ctxt.get_item_data(item) {
down_cast_data!(fn_data, DefData, item.span); down_cast_data!(fn_data, DefData, item.span);
v.process_formals(body.params, &fn_data.qualname); v.process_formals(body.params, &fn_data.qualname);
v.process_generic_params(ty_params, &fn_data.qualname, item.hir_id()); v.process_generic_params(ty_params, &fn_data.qualname, item.hir_id());
v.dumper.dump_def(&access_from!(v.save_ctxt, item.def_id), fn_data); v.dumper.dump_def(&access_from!(v.save_ctxt, item.def_id.def_id), fn_data);
} }
for arg in decl.inputs { for arg in decl.inputs {
@ -373,10 +373,10 @@ impl<'tcx> DumpVisitor<'tcx> {
typ: &'tcx hir::Ty<'tcx>, typ: &'tcx hir::Ty<'tcx>,
expr: &'tcx hir::Expr<'tcx>, expr: &'tcx hir::Expr<'tcx>,
) { ) {
self.nest_typeck_results(item.def_id, |v| { self.nest_typeck_results(item.def_id.def_id, |v| {
if let Some(var_data) = v.save_ctxt.get_item_data(item) { if let Some(var_data) = v.save_ctxt.get_item_data(item) {
down_cast_data!(var_data, DefData, item.span); down_cast_data!(var_data, DefData, item.span);
v.dumper.dump_def(&access_from!(v.save_ctxt, item.def_id), var_data); v.dumper.dump_def(&access_from!(v.save_ctxt, item.def_id.def_id), var_data);
} }
v.visit_ty(&typ); v.visit_ty(&typ);
v.visit_expr(expr); v.visit_expr(expr);
@ -473,7 +473,7 @@ impl<'tcx> DumpVisitor<'tcx> {
let span = self.span_from_span(item.ident.span); let span = self.span_from_span(item.ident.span);
let attrs = self.tcx.hir().attrs(item.hir_id()); let attrs = self.tcx.hir().attrs(item.hir_id());
self.dumper.dump_def( self.dumper.dump_def(
&access_from!(self.save_ctxt, item.def_id), &access_from!(self.save_ctxt, item.def_id.def_id),
Def { Def {
kind, kind,
id: id_from_def_id(item.def_id.to_def_id()), id: id_from_def_id(item.def_id.to_def_id()),
@ -491,7 +491,7 @@ impl<'tcx> DumpVisitor<'tcx> {
); );
} }
self.nest_typeck_results(item.def_id, |v| { self.nest_typeck_results(item.def_id.def_id, |v| {
for field in def.fields() { for field in def.fields() {
v.process_struct_field_def(field, item.hir_id()); v.process_struct_field_def(field, item.hir_id());
v.visit_ty(&field.ty); v.visit_ty(&field.ty);
@ -513,7 +513,7 @@ impl<'tcx> DumpVisitor<'tcx> {
}; };
down_cast_data!(enum_data, DefData, item.span); down_cast_data!(enum_data, DefData, item.span);
let access = access_from!(self.save_ctxt, item.def_id); let access = access_from!(self.save_ctxt, item.def_id.def_id);
for variant in enum_definition.variants { for variant in enum_definition.variants {
let name = variant.ident.name.to_string(); let name = variant.ident.name.to_string();
@ -612,7 +612,7 @@ impl<'tcx> DumpVisitor<'tcx> {
} }
let map = self.tcx.hir(); let map = self.tcx.hir();
self.nest_typeck_results(item.def_id, |v| { self.nest_typeck_results(item.def_id.def_id, |v| {
v.visit_ty(&impl_.self_ty); v.visit_ty(&impl_.self_ty);
if let Some(trait_ref) = &impl_.of_trait { if let Some(trait_ref) = &impl_.of_trait {
v.process_path(trait_ref.hir_ref_id, &hir::QPath::Resolved(None, &trait_ref.path)); v.process_path(trait_ref.hir_ref_id, &hir::QPath::Resolved(None, &trait_ref.path));
@ -648,7 +648,7 @@ impl<'tcx> DumpVisitor<'tcx> {
methods.iter().map(|i| id_from_def_id(i.id.def_id.to_def_id())).collect(); methods.iter().map(|i| id_from_def_id(i.id.def_id.to_def_id())).collect();
let attrs = self.tcx.hir().attrs(item.hir_id()); let attrs = self.tcx.hir().attrs(item.hir_id());
self.dumper.dump_def( self.dumper.dump_def(
&access_from!(self.save_ctxt, item.def_id), &access_from!(self.save_ctxt, item.def_id.def_id),
Def { Def {
kind: DefKind::Trait, kind: DefKind::Trait,
id, id,
@ -710,7 +710,7 @@ impl<'tcx> DumpVisitor<'tcx> {
fn process_mod(&mut self, item: &'tcx hir::Item<'tcx>) { fn process_mod(&mut self, item: &'tcx hir::Item<'tcx>) {
if let Some(mod_data) = self.save_ctxt.get_item_data(item) { if let Some(mod_data) = self.save_ctxt.get_item_data(item) {
down_cast_data!(mod_data, DefData, item.span); down_cast_data!(mod_data, DefData, item.span);
self.dumper.dump_def(&access_from!(self.save_ctxt, item.def_id), mod_data); self.dumper.dump_def(&access_from!(self.save_ctxt, item.def_id.def_id), mod_data);
} }
} }
@ -980,7 +980,7 @@ impl<'tcx> DumpVisitor<'tcx> {
let body = body.map(|b| self.tcx.hir().body(b).value); let body = body.map(|b| self.tcx.hir().body(b).value);
let attrs = self.tcx.hir().attrs(trait_item.hir_id()); let attrs = self.tcx.hir().attrs(trait_item.hir_id());
self.process_assoc_const( self.process_assoc_const(
trait_item.def_id, trait_item.def_id.def_id,
trait_item.ident, trait_item.ident,
&ty, &ty,
body, body,
@ -994,7 +994,7 @@ impl<'tcx> DumpVisitor<'tcx> {
self.process_method( self.process_method(
sig, sig,
body, body,
trait_item.def_id, trait_item.def_id.def_id,
trait_item.ident, trait_item.ident,
&trait_item.generics, &trait_item.generics,
trait_item.span, trait_item.span,
@ -1050,7 +1050,7 @@ impl<'tcx> DumpVisitor<'tcx> {
let body = self.tcx.hir().body(body); let body = self.tcx.hir().body(body);
let attrs = self.tcx.hir().attrs(impl_item.hir_id()); let attrs = self.tcx.hir().attrs(impl_item.hir_id());
self.process_assoc_const( self.process_assoc_const(
impl_item.def_id, impl_item.def_id.def_id,
impl_item.ident, impl_item.ident,
&ty, &ty,
Some(&body.value), Some(&body.value),
@ -1062,7 +1062,7 @@ impl<'tcx> DumpVisitor<'tcx> {
self.process_method( self.process_method(
sig, sig,
Some(body), Some(body),
impl_item.def_id, impl_item.def_id.def_id,
impl_item.ident, impl_item.ident,
&impl_item.generics, &impl_item.generics,
impl_item.span, impl_item.span,
@ -1136,10 +1136,10 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
hir::ItemKind::Use(path, hir::UseKind::Single) => { hir::ItemKind::Use(path, hir::UseKind::Single) => {
let sub_span = path.segments.last().unwrap().ident.span; let sub_span = path.segments.last().unwrap().ident.span;
if !self.span.filter_generated(sub_span) { if !self.span.filter_generated(sub_span) {
let access = access_from!(self.save_ctxt, item.def_id); let access = access_from!(self.save_ctxt, item.def_id.def_id);
let ref_id = self.lookup_def_id(item.hir_id()).map(id_from_def_id); let ref_id = self.lookup_def_id(item.hir_id()).map(id_from_def_id);
let span = self.span_from_span(sub_span); let span = self.span_from_span(sub_span);
let parent = self.save_ctxt.tcx.local_parent(item.def_id); let parent = self.save_ctxt.tcx.local_parent(item.def_id.def_id);
self.dumper.import( self.dumper.import(
&access, &access,
Import { Import {
@ -1157,16 +1157,16 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
} }
hir::ItemKind::Use(path, hir::UseKind::Glob) => { hir::ItemKind::Use(path, hir::UseKind::Glob) => {
// Make a comma-separated list of names of imported modules. // Make a comma-separated list of names of imported modules.
let names = self.tcx.names_imported_by_glob_use(item.def_id); let names = self.tcx.names_imported_by_glob_use(item.def_id.def_id);
let names: Vec<_> = names.iter().map(|n| n.to_string()).collect(); let names: Vec<_> = names.iter().map(|n| n.to_string()).collect();
// Otherwise it's a span with wrong macro expansion info, which // Otherwise it's a span with wrong macro expansion info, which
// we don't want to track anyway, since it's probably macro-internal `use` // we don't want to track anyway, since it's probably macro-internal `use`
if let Some(sub_span) = self.span.sub_span_of_star(item.span) { if let Some(sub_span) = self.span.sub_span_of_star(item.span) {
if !self.span.filter_generated(item.span) { if !self.span.filter_generated(item.span) {
let access = access_from!(self.save_ctxt, item.def_id); let access = access_from!(self.save_ctxt, item.def_id.def_id);
let span = self.span_from_span(sub_span); let span = self.span_from_span(sub_span);
let parent = self.save_ctxt.tcx.local_parent(item.def_id); let parent = self.save_ctxt.tcx.local_parent(item.def_id.def_id);
self.dumper.import( self.dumper.import(
&access, &access,
Import { Import {
@ -1187,7 +1187,7 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
let name_span = item.ident.span; let name_span = item.ident.span;
if !self.span.filter_generated(name_span) { if !self.span.filter_generated(name_span) {
let span = self.span_from_span(name_span); let span = self.span_from_span(name_span);
let parent = self.save_ctxt.tcx.local_parent(item.def_id); let parent = self.save_ctxt.tcx.local_parent(item.def_id.def_id);
self.dumper.import( self.dumper.import(
&Access { public: false, reachable: false }, &Access { public: false, reachable: false },
Import { Import {
@ -1235,7 +1235,7 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
let attrs = self.tcx.hir().attrs(item.hir_id()); let attrs = self.tcx.hir().attrs(item.hir_id());
self.dumper.dump_def( self.dumper.dump_def(
&access_from!(self.save_ctxt, item.def_id), &access_from!(self.save_ctxt, item.def_id.def_id),
Def { Def {
kind: DefKind::Type, kind: DefKind::Type,
id, id,
@ -1323,7 +1323,7 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
} }
hir::TyKind::OpaqueDef(item_id, _, _) => { hir::TyKind::OpaqueDef(item_id, _, _) => {
let item = self.tcx.hir().item(item_id); let item = self.tcx.hir().item(item_id);
self.nest_typeck_results(item_id.def_id, |v| v.visit_item(item)); self.nest_typeck_results(item_id.def_id.def_id, |v| v.visit_item(item));
} }
_ => intravisit::walk_ty(self, t), _ => intravisit::walk_ty(self, t),
} }
@ -1430,7 +1430,7 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
} }
fn visit_foreign_item(&mut self, item: &'tcx hir::ForeignItem<'tcx>) { fn visit_foreign_item(&mut self, item: &'tcx hir::ForeignItem<'tcx>) {
let access = access_from!(self.save_ctxt, item.def_id); let access = access_from!(self.save_ctxt, item.def_id.def_id);
match item.kind { match item.kind {
hir::ForeignItemKind::Fn(decl, _, ref generics) => { hir::ForeignItemKind::Fn(decl, _, ref generics) => {

View File

@ -622,7 +622,7 @@ impl<'tcx> SaveContext<'tcx> {
hir::QPath::TypeRelative(..) | hir::QPath::LangItem(..) => { hir::QPath::TypeRelative(..) | hir::QPath::LangItem(..) => {
// #75962: `self.typeck_results` may be different from the `hir_id`'s result. // #75962: `self.typeck_results` may be different from the `hir_id`'s result.
if self.tcx.has_typeck_results(hir_id.owner.to_def_id()) { if self.tcx.has_typeck_results(hir_id.owner.to_def_id()) {
self.tcx.typeck(hir_id.owner).qpath_res(qpath, hir_id) self.tcx.typeck(hir_id.owner.def_id).qpath_res(qpath, hir_id)
} else { } else {
Res::Err Res::Err
} }
@ -1041,7 +1041,7 @@ fn id_from_hir_id(id: hir::HirId, scx: &SaveContext<'_>) -> rls_data::Id {
// crate (very unlikely to actually happen). // crate (very unlikely to actually happen).
rls_data::Id { rls_data::Id {
krate: LOCAL_CRATE.as_u32(), krate: LOCAL_CRATE.as_u32(),
index: id.owner.local_def_index.as_u32() | id.local_id.as_u32().reverse_bits(), index: id.owner.def_id.local_def_index.as_u32() | id.local_id.as_u32().reverse_bits(),
} }
}) })
} }

View File

@ -26,19 +26,19 @@ pub fn report_symbol_names(tcx: TyCtxt<'_>) {
let crate_items = tcx.hir_crate_items(()); let crate_items = tcx.hir_crate_items(());
for id in crate_items.items() { for id in crate_items.items() {
symbol_names.process_attrs(id.def_id); symbol_names.process_attrs(id.def_id.def_id);
} }
for id in crate_items.trait_items() { for id in crate_items.trait_items() {
symbol_names.process_attrs(id.def_id); symbol_names.process_attrs(id.def_id.def_id);
} }
for id in crate_items.impl_items() { for id in crate_items.impl_items() {
symbol_names.process_attrs(id.def_id); symbol_names.process_attrs(id.def_id.def_id);
} }
for id in crate_items.foreign_items() { for id in crate_items.foreign_items() {
symbol_names.process_attrs(id.def_id); symbol_names.process_attrs(id.def_id.def_id);
} }
}) })
} }

View File

@ -1898,7 +1898,9 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
// FIXME(compiler-errors): This could be generalized, both to // FIXME(compiler-errors): This could be generalized, both to
// be more granular, and probably look past other `#[fundamental]` // be more granular, and probably look past other `#[fundamental]`
// types, too. // types, too.
self.tcx.visibility(def.did()).is_accessible_from(body_id.owner, self.tcx) self.tcx
.visibility(def.did())
.is_accessible_from(body_id.owner.def_id, self.tcx)
} else { } else {
true true
} }

View File

@ -659,7 +659,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
_ => {} _ => {}
} }
hir_id = self.tcx.hir().local_def_id_to_hir_id(self.tcx.hir().get_parent_item(hir_id)); hir_id = self.tcx.hir().get_parent_item(hir_id).into();
} }
} }
@ -2712,7 +2712,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
let parent_id = hir.get_parent_item(arg_hir_id); let parent_id = hir.get_parent_item(arg_hir_id);
let typeck_results: &TypeckResults<'tcx> = match &in_progress_typeck_results { let typeck_results: &TypeckResults<'tcx> = match &in_progress_typeck_results {
Some(t) if t.hir_owner == parent_id => t, Some(t) if t.hir_owner == parent_id => t,
_ => self.tcx.typeck(parent_id), _ => self.tcx.typeck(parent_id.def_id),
}; };
let expr = expr.peel_blocks(); let expr = expr.peel_blocks();
let ty = typeck_results.expr_ty_adjusted_opt(expr).unwrap_or(tcx.ty_error()); let ty = typeck_results.expr_ty_adjusted_opt(expr).unwrap_or(tcx.ty_error());

View File

@ -42,7 +42,7 @@ fn impl_item_implementor_ids(tcx: TyCtxt<'_>, impl_id: DefId) -> FxHashMap<DefId
fn associated_item(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AssocItem { fn associated_item(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AssocItem {
let id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local()); let id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
let parent_def_id = tcx.hir().get_parent_item(id); let parent_def_id = tcx.hir().get_parent_item(id);
let parent_item = tcx.hir().expect_item(parent_def_id); let parent_item = tcx.hir().expect_item(parent_def_id.def_id);
match parent_item.kind { match parent_item.kind {
hir::ItemKind::Impl(ref impl_) => { hir::ItemKind::Impl(ref impl_) => {
if let Some(impl_item_ref) = if let Some(impl_item_ref) =

View File

@ -3003,7 +3003,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
/// Make sure that we are in the condition to suggest the blanket implementation. /// Make sure that we are in the condition to suggest the blanket implementation.
fn maybe_lint_blanket_trait_impl(&self, self_ty: &hir::Ty<'_>, diag: &mut Diagnostic) { fn maybe_lint_blanket_trait_impl(&self, self_ty: &hir::Ty<'_>, diag: &mut Diagnostic) {
let tcx = self.tcx(); let tcx = self.tcx();
let parent_id = tcx.hir().get_parent_item(self_ty.hir_id); let parent_id = tcx.hir().get_parent_item(self_ty.hir_id).def_id;
if let hir::Node::Item(hir::Item { if let hir::Node::Item(hir::Item {
kind: kind:
hir::ItemKind::Impl(hir::Impl { hir::ItemKind::Impl(hir::Impl {

View File

@ -140,7 +140,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let Some(ret) = self let Some(ret) = self
.tcx .tcx
.hir() .hir()
.find_by_def_id(self.body_id.owner) .find_by_def_id(self.body_id.owner.def_id)
.and_then(|owner| owner.fn_decl()) .and_then(|owner| owner.fn_decl())
.map(|decl| decl.output.span()) .map(|decl| decl.output.span())
else { return; }; else { return; };
@ -495,7 +495,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.typeck_results .typeck_results
.borrow() .borrow()
.liberated_fn_sigs() .liberated_fn_sigs()
.get(hir::HirId::make_owner(self.body_id.owner))?; .get(hir::HirId::make_owner(self.body_id.owner.def_id))?;
let substs = sig.output().walk().find_map(|arg| { let substs = sig.output().walk().find_map(|arg| {
if let ty::GenericArgKind::Type(ty) = arg.unpack() if let ty::GenericArgKind::Type(ty) = arg.unpack()

View File

@ -782,19 +782,19 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
let _indenter = indenter(); let _indenter = indenter();
match tcx.def_kind(id.def_id) { match tcx.def_kind(id.def_id) {
DefKind::Static(..) => { DefKind::Static(..) => {
tcx.ensure().typeck(id.def_id); tcx.ensure().typeck(id.def_id.def_id);
maybe_check_static_with_link_section(tcx, id.def_id); maybe_check_static_with_link_section(tcx, id.def_id.def_id);
check_static_inhabited(tcx, id.def_id); check_static_inhabited(tcx, id.def_id.def_id);
} }
DefKind::Const => { DefKind::Const => {
tcx.ensure().typeck(id.def_id); tcx.ensure().typeck(id.def_id.def_id);
} }
DefKind::Enum => { DefKind::Enum => {
let item = tcx.hir().item(id); let item = tcx.hir().item(id);
let hir::ItemKind::Enum(ref enum_definition, _) = item.kind else { let hir::ItemKind::Enum(ref enum_definition, _) = item.kind else {
return; return;
}; };
check_enum(tcx, &enum_definition.variants, item.def_id); check_enum(tcx, &enum_definition.variants, item.def_id.def_id);
} }
DefKind::Fn => {} // entirely within check_item_body DefKind::Fn => {} // entirely within check_item_body
DefKind::Impl => { DefKind::Impl => {
@ -807,7 +807,7 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
check_impl_items_against_trait( check_impl_items_against_trait(
tcx, tcx,
it.span, it.span,
it.def_id, it.def_id.def_id,
impl_trait_ref, impl_trait_ref,
&impl_.items, &impl_.items,
); );
@ -845,10 +845,10 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
} }
} }
DefKind::Struct => { DefKind::Struct => {
check_struct(tcx, id.def_id); check_struct(tcx, id.def_id.def_id);
} }
DefKind::Union => { DefKind::Union => {
check_union(tcx, id.def_id); check_union(tcx, id.def_id.def_id);
} }
DefKind::OpaqueTy => { DefKind::OpaqueTy => {
let item = tcx.hir().item(id); let item = tcx.hir().item(id);
@ -861,7 +861,7 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
// See https://github.com/rust-lang/rust/issues/75100 // See https://github.com/rust-lang/rust/issues/75100
if !tcx.sess.opts.actually_rustdoc { if !tcx.sess.opts.actually_rustdoc {
let substs = InternalSubsts::identity_for_item(tcx, item.def_id.to_def_id()); let substs = InternalSubsts::identity_for_item(tcx, item.def_id.to_def_id());
check_opaque(tcx, item.def_id, substs, &origin); check_opaque(tcx, item.def_id.def_id, substs, &origin);
} }
} }
DefKind::TyAlias => { DefKind::TyAlias => {
@ -888,7 +888,7 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
} }
} else { } else {
for item in items { for item in items {
let def_id = item.id.def_id; let def_id = item.id.def_id.def_id;
let generics = tcx.generics_of(def_id); let generics = tcx.generics_of(def_id);
let own_counts = generics.own_counts(); let own_counts = generics.own_counts();
if generics.params.len() - own_counts.lifetimes != 0 { if generics.params.len() - own_counts.lifetimes != 0 {

View File

@ -1683,7 +1683,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
expected, expected,
found, found,
can_suggest, can_suggest,
fcx.tcx.hir().local_def_id_to_hir_id(fcx.tcx.hir().get_parent_item(id)), fcx.tcx.hir().get_parent_item(id).into(),
); );
} }
if !pointing_at_return_type { if !pointing_at_return_type {
@ -1692,7 +1692,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
} }
let parent_id = fcx.tcx.hir().get_parent_item(id); let parent_id = fcx.tcx.hir().get_parent_item(id);
let parent_item = fcx.tcx.hir().get_by_def_id(parent_id); let parent_item = fcx.tcx.hir().get_by_def_id(parent_id.def_id);
if let (Some(expr), Some(_), Some((fn_decl, _, _))) = if let (Some(expr), Some(_), Some((fn_decl, _, _))) =
(expression, blk_id, fcx.get_node_fn_decl(parent_item)) (expression, blk_id, fcx.get_node_fn_decl(parent_item))
@ -1704,7 +1704,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
expected, expected,
found, found,
id, id,
fcx.tcx.hir().local_def_id_to_hir_id(parent_id), parent_id.into(),
); );
} }

View File

@ -375,7 +375,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let field_is_local = sole_field.did.is_local(); let field_is_local = sole_field.did.is_local();
let field_is_accessible = let field_is_accessible =
sole_field.vis.is_accessible_from(expr.hir_id.owner, self.tcx) sole_field.vis.is_accessible_from(expr.hir_id.owner.def_id, self.tcx)
// Skip suggestions for unstable public fields (for example `Pin::pointer`) // Skip suggestions for unstable public fields (for example `Pin::pointer`)
&& matches!(self.tcx.eval_stability(sole_field.did, None, expr.span, None), EvalResult::Allow | EvalResult::Unmarked); && matches!(self.tcx.eval_stability(sole_field.did, None, expr.span, None), EvalResult::Allow | EvalResult::Unmarked);

View File

@ -752,7 +752,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
kind: hir::ImplItemKind::Fn(..), kind: hir::ImplItemKind::Fn(..),
span: encl_fn_span, span: encl_fn_span,
.. ..
})) = self.tcx.hir().find_by_def_id(encl_item_id) })) = self.tcx.hir().find_by_def_id(encl_item_id.def_id)
{ {
// We are inside a function body, so reporting "return statement // We are inside a function body, so reporting "return statement
// outside of function body" needs an explanation. // outside of function body" needs an explanation.
@ -761,7 +761,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// If this didn't hold, we would not have to report an error in // If this didn't hold, we would not have to report an error in
// the first place. // the first place.
assert_ne!(encl_item_id, encl_body_owner_id); assert_ne!(encl_item_id.def_id, encl_body_owner_id);
let encl_body_id = self.tcx.hir().body_owned_by(encl_body_owner_id); let encl_body_id = self.tcx.hir().body_owned_by(encl_body_owner_id);
let encl_body = self.tcx.hir().body(encl_body_id); let encl_body = self.tcx.hir().body(encl_body_id);
@ -2338,7 +2338,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if let ty::Adt(def, _) = output_ty.kind() && !def.is_enum() { if let ty::Adt(def, _) = output_ty.kind() && !def.is_enum() {
def.non_enum_variant().fields.iter().any(|field| { def.non_enum_variant().fields.iter().any(|field| {
field.ident(self.tcx) == ident field.ident(self.tcx) == ident
&& field.vis.is_accessible_from(expr.hir_id.owner, self.tcx) && field.vis.is_accessible_from(expr.hir_id.owner.def_id, self.tcx)
}) })
} else if let ty::Tuple(tys) = output_ty.kind() } else if let ty::Tuple(tys) = output_ty.kind()
&& let Ok(idx) = ident.as_str().parse::<usize>() && let Ok(idx) = ident.as_str().parse::<usize>()

View File

@ -1543,7 +1543,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
fn parent_item_span(&self, id: hir::HirId) -> Option<Span> { fn parent_item_span(&self, id: hir::HirId) -> Option<Span> {
let node = self.tcx.hir().get_by_def_id(self.tcx.hir().get_parent_item(id)); let node = self.tcx.hir().get_by_def_id(self.tcx.hir().get_parent_item(id).def_id);
match node { match node {
Node::Item(&hir::Item { kind: hir::ItemKind::Fn(_, _, body_id), .. }) Node::Item(&hir::Item { kind: hir::ItemKind::Fn(_, _, body_id), .. })
| Node::ImplItem(&hir::ImplItem { kind: hir::ImplItemKind::Fn(_, body_id), .. }) => { | Node::ImplItem(&hir::ImplItem { kind: hir::ImplItemKind::Fn(_, body_id), .. }) => {
@ -1559,7 +1559,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// Given a function block's `HirId`, returns its `FnDecl` if it exists, or `None` otherwise. /// Given a function block's `HirId`, returns its `FnDecl` if it exists, or `None` otherwise.
fn get_parent_fn_decl(&self, blk_id: hir::HirId) -> Option<(&'tcx hir::FnDecl<'tcx>, Ident)> { fn get_parent_fn_decl(&self, blk_id: hir::HirId) -> Option<(&'tcx hir::FnDecl<'tcx>, Ident)> {
let parent = self.tcx.hir().get_by_def_id(self.tcx.hir().get_parent_item(blk_id)); let parent = self.tcx.hir().get_by_def_id(self.tcx.hir().get_parent_item(blk_id).def_id);
self.get_node_fn_decl(parent).map(|(fn_decl, ident, _)| (fn_decl, ident)) self.get_node_fn_decl(parent).map(|(fn_decl, ident, _)| (fn_decl, ident))
} }

View File

@ -2077,7 +2077,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Colon, Colon,
Nothing, Nothing,
} }
let ast_generics = hir.get_generics(id.owner).unwrap(); let ast_generics = hir.get_generics(id.owner.def_id).unwrap();
let (sp, mut introducer) = if let Some(span) = let (sp, mut introducer) = if let Some(span) =
ast_generics.bounds_span_for_suggestions(def_id) ast_generics.bounds_span_for_suggestions(def_id)
{ {

View File

@ -519,7 +519,7 @@ fn get_owner_return_paths<'tcx>(
def_id: LocalDefId, def_id: LocalDefId,
) -> Option<(LocalDefId, ReturnsVisitor<'tcx>)> { ) -> Option<(LocalDefId, ReturnsVisitor<'tcx>)> {
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id); let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
let parent_id = tcx.hir().get_parent_item(hir_id); let parent_id = tcx.hir().get_parent_item(hir_id).def_id;
tcx.hir().find_by_def_id(parent_id).and_then(|node| node.body_id()).map(|body_id| { tcx.hir().find_by_def_id(parent_id).and_then(|node| node.body_id()).map(|body_id| {
let body = tcx.hir().body(body_id); let body = tcx.hir().body(body_id);
let mut visitor = ReturnsVisitor::default(); let mut visitor = ReturnsVisitor::default();

View File

@ -116,7 +116,7 @@ pub(super) fn enter_wf_checking_ctxt<'tcx, F>(
}) })
} }
fn check_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) { fn check_well_formed(tcx: TyCtxt<'_>, def_id: hir::OwnerId) {
let node = tcx.hir().expect_owner(def_id); let node = tcx.hir().expect_owner(def_id);
match node { match node {
hir::OwnerNode::Crate(_) => {} hir::OwnerNode::Crate(_) => {}
@ -148,7 +148,7 @@ fn check_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) {
/// the types first. /// the types first.
#[instrument(skip(tcx), level = "debug")] #[instrument(skip(tcx), level = "debug")]
fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) { fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) {
let def_id = item.def_id; let def_id = item.def_id.def_id;
debug!( debug!(
?item.def_id, ?item.def_id,
@ -175,7 +175,7 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) {
// for `T` // for `T`
hir::ItemKind::Impl(ref impl_) => { hir::ItemKind::Impl(ref impl_) => {
let is_auto = tcx let is_auto = tcx
.impl_trait_ref(item.def_id) .impl_trait_ref(def_id)
.map_or(false, |trait_ref| tcx.trait_is_auto(trait_ref.def_id)); .map_or(false, |trait_ref| tcx.trait_is_auto(trait_ref.def_id));
if let (hir::Defaultness::Default { .. }, true) = (impl_.defaultness, is_auto) { if let (hir::Defaultness::Default { .. }, true) = (impl_.defaultness, is_auto) {
let sp = impl_.of_trait.as_ref().map_or(item.span, |t| t.path.span); let sp = impl_.of_trait.as_ref().map_or(item.span, |t| t.path.span);
@ -211,13 +211,13 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) {
} }
} }
hir::ItemKind::Fn(ref sig, ..) => { hir::ItemKind::Fn(ref sig, ..) => {
check_item_fn(tcx, item.def_id, item.ident, item.span, sig.decl); check_item_fn(tcx, def_id, item.ident, item.span, sig.decl);
} }
hir::ItemKind::Static(ty, ..) => { hir::ItemKind::Static(ty, ..) => {
check_item_type(tcx, item.def_id, ty.span, false); check_item_type(tcx, def_id, ty.span, false);
} }
hir::ItemKind::Const(ty, ..) => { hir::ItemKind::Const(ty, ..) => {
check_item_type(tcx, item.def_id, ty.span, false); check_item_type(tcx, def_id, ty.span, false);
} }
hir::ItemKind::Struct(ref struct_def, ref ast_generics) => { hir::ItemKind::Struct(ref struct_def, ref ast_generics) => {
check_type_defn(tcx, item, false, |wfcx| vec![wfcx.non_enum_variant(struct_def)]); check_type_defn(tcx, item, false, |wfcx| vec![wfcx.non_enum_variant(struct_def)]);
@ -247,7 +247,7 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) {
} }
fn check_foreign_item(tcx: TyCtxt<'_>, item: &hir::ForeignItem<'_>) { fn check_foreign_item(tcx: TyCtxt<'_>, item: &hir::ForeignItem<'_>) {
let def_id = item.def_id; let def_id = item.def_id.def_id;
debug!( debug!(
?item.def_id, ?item.def_id,
@ -256,15 +256,15 @@ fn check_foreign_item(tcx: TyCtxt<'_>, item: &hir::ForeignItem<'_>) {
match item.kind { match item.kind {
hir::ForeignItemKind::Fn(decl, ..) => { hir::ForeignItemKind::Fn(decl, ..) => {
check_item_fn(tcx, item.def_id, item.ident, item.span, decl) check_item_fn(tcx, def_id, item.ident, item.span, decl)
} }
hir::ForeignItemKind::Static(ty, ..) => check_item_type(tcx, item.def_id, ty.span, true), hir::ForeignItemKind::Static(ty, ..) => check_item_type(tcx, def_id, ty.span, true),
hir::ForeignItemKind::Type => (), hir::ForeignItemKind::Type => (),
} }
} }
fn check_trait_item(tcx: TyCtxt<'_>, trait_item: &hir::TraitItem<'_>) { fn check_trait_item(tcx: TyCtxt<'_>, trait_item: &hir::TraitItem<'_>) {
let def_id = trait_item.def_id; let def_id = trait_item.def_id.def_id;
let (method_sig, span) = match trait_item.kind { let (method_sig, span) = match trait_item.kind {
hir::TraitItemKind::Fn(ref sig, _) => (Some(sig), trait_item.span), hir::TraitItemKind::Fn(ref sig, _) => (Some(sig), trait_item.span),
@ -272,7 +272,7 @@ fn check_trait_item(tcx: TyCtxt<'_>, trait_item: &hir::TraitItem<'_>) {
_ => (None, trait_item.span), _ => (None, trait_item.span),
}; };
check_object_unsafe_self_trait_by_name(tcx, trait_item); check_object_unsafe_self_trait_by_name(tcx, trait_item);
check_associated_item(tcx, trait_item.def_id, span, method_sig); check_associated_item(tcx, def_id, span, method_sig);
let encl_trait_def_id = tcx.local_parent(def_id); let encl_trait_def_id = tcx.local_parent(def_id);
let encl_trait = tcx.hir().expect_item(encl_trait_def_id); let encl_trait = tcx.hir().expect_item(encl_trait_def_id);
@ -393,7 +393,7 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, associated_items: &[hir::TraitItemRe
// We also assume that all of the function signature's parameter types // We also assume that all of the function signature's parameter types
// are well formed. // are well formed.
&sig.inputs().iter().copied().collect(), &sig.inputs().iter().copied().collect(),
gat_def_id, gat_def_id.def_id,
gat_generics, gat_generics,
) )
} }
@ -416,7 +416,7 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, associated_items: &[hir::TraitItemRe
.copied() .copied()
.collect::<Vec<_>>(), .collect::<Vec<_>>(),
&FxHashSet::default(), &FxHashSet::default(),
gat_def_id, gat_def_id.def_id,
gat_generics, gat_generics,
) )
} }
@ -456,7 +456,7 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, associated_items: &[hir::TraitItemRe
} }
for (gat_def_id, required_bounds) in required_bounds_by_item { for (gat_def_id, required_bounds) in required_bounds_by_item {
let gat_item_hir = tcx.hir().expect_trait_item(gat_def_id); let gat_item_hir = tcx.hir().expect_trait_item(gat_def_id.def_id);
debug!(?required_bounds); debug!(?required_bounds);
let param_env = tcx.param_env(gat_def_id); let param_env = tcx.param_env(gat_def_id);
let gat_hir = gat_item_hir.hir_id(); let gat_hir = gat_item_hir.hir_id();
@ -786,7 +786,7 @@ fn could_be_self(trait_def_id: LocalDefId, ty: &hir::Ty<'_>) -> bool {
/// When this is done, suggest using `Self` instead. /// When this is done, suggest using `Self` instead.
fn check_object_unsafe_self_trait_by_name(tcx: TyCtxt<'_>, item: &hir::TraitItem<'_>) { fn check_object_unsafe_self_trait_by_name(tcx: TyCtxt<'_>, item: &hir::TraitItem<'_>) {
let (trait_name, trait_def_id) = let (trait_name, trait_def_id) =
match tcx.hir().get_by_def_id(tcx.hir().get_parent_item(item.hir_id())) { match tcx.hir().get_by_def_id(tcx.hir().get_parent_item(item.hir_id()).def_id) {
hir::Node::Item(item) => match item.kind { hir::Node::Item(item) => match item.kind {
hir::ItemKind::Trait(..) => (item.ident, item.def_id), hir::ItemKind::Trait(..) => (item.ident, item.def_id),
_ => return, _ => return,
@ -796,18 +796,18 @@ fn check_object_unsafe_self_trait_by_name(tcx: TyCtxt<'_>, item: &hir::TraitItem
let mut trait_should_be_self = vec![]; let mut trait_should_be_self = vec![];
match &item.kind { match &item.kind {
hir::TraitItemKind::Const(ty, _) | hir::TraitItemKind::Type(_, Some(ty)) hir::TraitItemKind::Const(ty, _) | hir::TraitItemKind::Type(_, Some(ty))
if could_be_self(trait_def_id, ty) => if could_be_self(trait_def_id.def_id, ty) =>
{ {
trait_should_be_self.push(ty.span) trait_should_be_self.push(ty.span)
} }
hir::TraitItemKind::Fn(sig, _) => { hir::TraitItemKind::Fn(sig, _) => {
for ty in sig.decl.inputs { for ty in sig.decl.inputs {
if could_be_self(trait_def_id, ty) { if could_be_self(trait_def_id.def_id, ty) {
trait_should_be_self.push(ty.span); trait_should_be_self.push(ty.span);
} }
} }
match sig.decl.output { match sig.decl.output {
hir::FnRetTy::Return(ty) if could_be_self(trait_def_id, ty) => { hir::FnRetTy::Return(ty) if could_be_self(trait_def_id.def_id, ty) => {
trait_should_be_self.push(ty.span); trait_should_be_self.push(ty.span);
} }
_ => {} _ => {}
@ -836,8 +836,6 @@ fn check_object_unsafe_self_trait_by_name(tcx: TyCtxt<'_>, item: &hir::TraitItem
} }
fn check_impl_item(tcx: TyCtxt<'_>, impl_item: &hir::ImplItem<'_>) { fn check_impl_item(tcx: TyCtxt<'_>, impl_item: &hir::ImplItem<'_>) {
let def_id = impl_item.def_id;
let (method_sig, span) = match impl_item.kind { let (method_sig, span) = match impl_item.kind {
hir::ImplItemKind::Fn(ref sig, _) => (Some(sig), impl_item.span), hir::ImplItemKind::Fn(ref sig, _) => (Some(sig), impl_item.span),
// Constrain binding and overflow error spans to `<Ty>` in `type foo = <Ty>`. // Constrain binding and overflow error spans to `<Ty>` in `type foo = <Ty>`.
@ -845,7 +843,7 @@ fn check_impl_item(tcx: TyCtxt<'_>, impl_item: &hir::ImplItem<'_>) {
_ => (None, impl_item.span), _ => (None, impl_item.span),
}; };
check_associated_item(tcx, def_id, span, method_sig); check_associated_item(tcx, impl_item.def_id.def_id, span, method_sig);
} }
fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) { fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) {
@ -1045,7 +1043,7 @@ fn check_type_defn<'tcx, F>(
) where ) where
F: FnMut(&WfCheckingCtxt<'_, 'tcx>) -> Vec<AdtVariant<'tcx>>, F: FnMut(&WfCheckingCtxt<'_, 'tcx>) -> Vec<AdtVariant<'tcx>>,
{ {
enter_wf_checking_ctxt(tcx, item.span, item.def_id, |wfcx| { enter_wf_checking_ctxt(tcx, item.span, item.def_id.def_id, |wfcx| {
let variants = lookup_fields(wfcx); let variants = lookup_fields(wfcx);
let packed = tcx.adt_def(item.def_id).repr().packed(); let packed = tcx.adt_def(item.def_id).repr().packed();
@ -1124,7 +1122,7 @@ fn check_type_defn<'tcx, F>(
} }
} }
check_where_clauses(wfcx, item.span, item.def_id); check_where_clauses(wfcx, item.span, item.def_id.def_id);
}); });
} }
@ -1132,11 +1130,12 @@ fn check_type_defn<'tcx, F>(
fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item<'_>) { fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item<'_>) {
debug!(?item.def_id); debug!(?item.def_id);
let trait_def = tcx.trait_def(item.def_id); let def_id = item.def_id.def_id;
let trait_def = tcx.trait_def(def_id);
if trait_def.is_marker if trait_def.is_marker
|| matches!(trait_def.specialization_kind, TraitSpecializationKind::Marker) || matches!(trait_def.specialization_kind, TraitSpecializationKind::Marker)
{ {
for associated_def_id in &*tcx.associated_item_def_ids(item.def_id) { for associated_def_id in &*tcx.associated_item_def_ids(def_id) {
struct_span_err!( struct_span_err!(
tcx.sess, tcx.sess,
tcx.def_span(*associated_def_id), tcx.def_span(*associated_def_id),
@ -1147,8 +1146,8 @@ fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item<'_>) {
} }
} }
enter_wf_checking_ctxt(tcx, item.span, item.def_id, |wfcx| { enter_wf_checking_ctxt(tcx, item.span, def_id, |wfcx| {
check_where_clauses(wfcx, item.span, item.def_id) check_where_clauses(wfcx, item.span, def_id)
}); });
// Only check traits, don't check trait aliases // Only check traits, don't check trait aliases
@ -1242,7 +1241,7 @@ fn check_impl<'tcx>(
ast_trait_ref: &Option<hir::TraitRef<'_>>, ast_trait_ref: &Option<hir::TraitRef<'_>>,
constness: hir::Constness, constness: hir::Constness,
) { ) {
enter_wf_checking_ctxt(tcx, item.span, item.def_id, |wfcx| { enter_wf_checking_ctxt(tcx, item.span, item.def_id.def_id, |wfcx| {
match *ast_trait_ref { match *ast_trait_ref {
Some(ref ast_trait_ref) => { Some(ref ast_trait_ref) => {
// `#[rustc_reservation_impl]` impls are not real impls and // `#[rustc_reservation_impl]` impls are not real impls and
@ -1273,18 +1272,18 @@ fn check_impl<'tcx>(
let self_ty = tcx.type_of(item.def_id); let self_ty = tcx.type_of(item.def_id);
let self_ty = wfcx.normalize( let self_ty = wfcx.normalize(
item.span, item.span,
Some(WellFormedLoc::Ty(item.hir_id().expect_owner())), Some(WellFormedLoc::Ty(item.hir_id().expect_owner().def_id)),
self_ty, self_ty,
); );
wfcx.register_wf_obligation( wfcx.register_wf_obligation(
ast_self_ty.span, ast_self_ty.span,
Some(WellFormedLoc::Ty(item.hir_id().expect_owner())), Some(WellFormedLoc::Ty(item.hir_id().expect_owner().def_id)),
self_ty.into(), self_ty.into(),
); );
} }
} }
check_where_clauses(wfcx, item.span, item.def_id); check_where_clauses(wfcx, item.span, item.def_id.def_id);
}); });
} }

View File

@ -105,7 +105,7 @@ impl<'tcx> InherentCollect<'tcx> {
} }
if let Some(simp) = simplify_type(self.tcx, self_ty, TreatParams::AsInfer) { if let Some(simp) = simplify_type(self.tcx, self_ty, TreatParams::AsInfer) {
self.impls_map.incoherent_impls.entry(simp).or_default().push(impl_def_id); self.impls_map.incoherent_impls.entry(simp).or_default().push(impl_def_id.def_id);
} else { } else {
bug!("unexpected self type: {:?}", self_ty); bug!("unexpected self type: {:?}", self_ty);
} }
@ -220,7 +220,9 @@ impl<'tcx> InherentCollect<'tcx> {
| ty::Ref(..) | ty::Ref(..)
| ty::Never | ty::Never
| ty::FnPtr(_) | ty::FnPtr(_)
| ty::Tuple(..) => self.check_primitive_impl(item.def_id, self_ty, items, ty.span), | ty::Tuple(..) => {
self.check_primitive_impl(item.def_id.def_id, self_ty, items, ty.span)
}
ty::Projection(..) | ty::Opaque(..) | ty::Param(_) => { ty::Projection(..) | ty::Opaque(..) | ty::Param(_) => {
let mut err = struct_span_err!( let mut err = struct_span_err!(
self.tcx.sess, self.tcx.sess,

View File

@ -42,7 +42,7 @@ fn do_orphan_check_impl<'tcx>(
) -> Result<(), ErrorGuaranteed> { ) -> Result<(), ErrorGuaranteed> {
let trait_def_id = trait_ref.def_id; let trait_def_id = trait_ref.def_id;
let item = tcx.hir().item(hir::ItemId { def_id }); let item = tcx.hir().expect_item(def_id);
let hir::ItemKind::Impl(ref impl_) = item.kind else { let hir::ItemKind::Impl(ref impl_) = item.kind else {
bug!("{:?} is not an impl: {:?}", def_id, item); bug!("{:?} is not an impl: {:?}", def_id, item);
}; };

View File

@ -28,7 +28,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed, StashKey}; use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed, StashKey};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::{CtorKind, DefKind}; use rustc_hir::def::{CtorKind, DefKind};
use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID, LOCAL_CRATE}; use rustc_hir::def_id::{DefId, LocalDefId, LOCAL_CRATE};
use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::weak_lang_items; use rustc_hir::weak_lang_items;
use rustc_hir::{GenericParamKind, HirId, Node}; use rustc_hir::{GenericParamKind, HirId, Node};
@ -449,8 +449,10 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {
match self.node() { match self.node() {
hir::Node::Field(_) | hir::Node::Ctor(_) | hir::Node::Variant(_) => { hir::Node::Field(_) | hir::Node::Ctor(_) | hir::Node::Variant(_) => {
let item = let item = self
self.tcx.hir().expect_item(self.tcx.hir().get_parent_item(self.hir_id())); .tcx
.hir()
.expect_item(self.tcx.hir().get_parent_item(self.hir_id()).def_id);
match &item.kind { match &item.kind {
hir::ItemKind::Enum(_, generics) hir::ItemKind::Enum(_, generics)
| hir::ItemKind::Struct(_, generics) | hir::ItemKind::Struct(_, generics)
@ -728,7 +730,7 @@ impl<'tcx> ItemCtxt<'tcx> {
fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) { fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
let it = tcx.hir().item(item_id); let it = tcx.hir().item(item_id);
debug!("convert: item {} with id {}", it.ident, it.hir_id()); debug!("convert: item {} with id {}", it.ident, it.hir_id());
let def_id = item_id.def_id; let def_id = item_id.def_id.def_id;
match it.kind { match it.kind {
// These don't define types. // These don't define types.
@ -840,20 +842,21 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) { fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
let trait_item = tcx.hir().trait_item(trait_item_id); let trait_item = tcx.hir().trait_item(trait_item_id);
tcx.ensure().generics_of(trait_item_id.def_id); let def_id = trait_item_id.def_id;
tcx.ensure().generics_of(def_id);
match trait_item.kind { match trait_item.kind {
hir::TraitItemKind::Fn(..) => { hir::TraitItemKind::Fn(..) => {
tcx.ensure().type_of(trait_item_id.def_id); tcx.ensure().type_of(def_id);
tcx.ensure().fn_sig(trait_item_id.def_id); tcx.ensure().fn_sig(def_id);
} }
hir::TraitItemKind::Const(.., Some(_)) => { hir::TraitItemKind::Const(.., Some(_)) => {
tcx.ensure().type_of(trait_item_id.def_id); tcx.ensure().type_of(def_id);
} }
hir::TraitItemKind::Const(hir_ty, _) => { hir::TraitItemKind::Const(hir_ty, _) => {
tcx.ensure().type_of(trait_item_id.def_id); tcx.ensure().type_of(def_id);
// Account for `const C: _;`. // Account for `const C: _;`.
let mut visitor = HirPlaceholderCollector::default(); let mut visitor = HirPlaceholderCollector::default();
visitor.visit_trait_item(trait_item); visitor.visit_trait_item(trait_item);
@ -863,8 +866,8 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
} }
hir::TraitItemKind::Type(_, Some(_)) => { hir::TraitItemKind::Type(_, Some(_)) => {
tcx.ensure().item_bounds(trait_item_id.def_id); tcx.ensure().item_bounds(def_id);
tcx.ensure().type_of(trait_item_id.def_id); tcx.ensure().type_of(def_id);
// Account for `type T = _;`. // Account for `type T = _;`.
let mut visitor = HirPlaceholderCollector::default(); let mut visitor = HirPlaceholderCollector::default();
visitor.visit_trait_item(trait_item); visitor.visit_trait_item(trait_item);
@ -872,7 +875,7 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
} }
hir::TraitItemKind::Type(_, None) => { hir::TraitItemKind::Type(_, None) => {
tcx.ensure().item_bounds(trait_item_id.def_id); tcx.ensure().item_bounds(def_id);
// #74612: Visit and try to find bad placeholders // #74612: Visit and try to find bad placeholders
// even if there is no concrete type. // even if there is no concrete type.
let mut visitor = HirPlaceholderCollector::default(); let mut visitor = HirPlaceholderCollector::default();
@ -882,7 +885,7 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
} }
}; };
tcx.ensure().predicates_of(trait_item_id.def_id); tcx.ensure().predicates_of(def_id);
} }
fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) { fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) {
@ -1595,7 +1598,7 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
} }
ItemKind::OpaqueTy(hir::OpaqueTy { origin: hir::OpaqueTyOrigin::TyAlias, .. }) => { ItemKind::OpaqueTy(hir::OpaqueTy { origin: hir::OpaqueTyOrigin::TyAlias, .. }) => {
let parent_id = tcx.hir().get_parent_item(hir_id); let parent_id = tcx.hir().get_parent_item(hir_id);
assert_ne!(parent_id, CRATE_DEF_ID); assert_ne!(parent_id, hir::CRATE_OWNER_ID);
debug!("generics_of: parent of opaque ty {:?} is {:?}", def_id, parent_id); debug!("generics_of: parent of opaque ty {:?} is {:?}", def_id, parent_id);
// Opaque types are always nested within another item, and // Opaque types are always nested within another item, and
// inherit the generics of the item. // inherit the generics of the item.
@ -3386,7 +3389,7 @@ fn check_target_feature_trait_unsafe(tcx: TyCtxt<'_>, id: LocalDefId, attr_span:
let node = tcx.hir().get(hir_id); let node = tcx.hir().get(hir_id);
if let Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Fn(..), .. }) = node { if let Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Fn(..), .. }) = node {
let parent_id = tcx.hir().get_parent_item(hir_id); let parent_id = tcx.hir().get_parent_item(hir_id);
let parent_item = tcx.hir().expect_item(parent_id); let parent_item = tcx.hir().expect_item(parent_id.def_id);
if let hir::ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }) = parent_item.kind { if let hir::ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }) = parent_item.kind {
tcx.sess tcx.sess
.struct_span_err( .struct_span_err(

View File

@ -569,22 +569,22 @@ fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: LocalDefId) -> T
fn visit_item(&mut self, it: &'tcx Item<'tcx>) { fn visit_item(&mut self, it: &'tcx Item<'tcx>) {
trace!(?it.def_id); trace!(?it.def_id);
// The opaque type itself or its children are not within its reveal scope. // The opaque type itself or its children are not within its reveal scope.
if it.def_id != self.def_id { if it.def_id.def_id != self.def_id {
self.check(it.def_id); self.check(it.def_id.def_id);
intravisit::walk_item(self, it); intravisit::walk_item(self, it);
} }
} }
fn visit_impl_item(&mut self, it: &'tcx ImplItem<'tcx>) { fn visit_impl_item(&mut self, it: &'tcx ImplItem<'tcx>) {
trace!(?it.def_id); trace!(?it.def_id);
// The opaque type itself or its children are not within its reveal scope. // The opaque type itself or its children are not within its reveal scope.
if it.def_id != self.def_id { if it.def_id.def_id != self.def_id {
self.check(it.def_id); self.check(it.def_id.def_id);
intravisit::walk_impl_item(self, it); intravisit::walk_impl_item(self, it);
} }
} }
fn visit_trait_item(&mut self, it: &'tcx TraitItem<'tcx>) { fn visit_trait_item(&mut self, it: &'tcx TraitItem<'tcx>) {
trace!(?it.def_id); trace!(?it.def_id);
self.check(it.def_id); self.check(it.def_id.def_id);
intravisit::walk_trait_item(self, it); intravisit::walk_trait_item(self, it);
} }
} }
@ -688,22 +688,22 @@ fn find_opaque_ty_constraints_for_rpit(
fn visit_item(&mut self, it: &'tcx Item<'tcx>) { fn visit_item(&mut self, it: &'tcx Item<'tcx>) {
trace!(?it.def_id); trace!(?it.def_id);
// The opaque type itself or its children are not within its reveal scope. // The opaque type itself or its children are not within its reveal scope.
if it.def_id != self.def_id { if it.def_id.def_id != self.def_id {
self.check(it.def_id); self.check(it.def_id.def_id);
intravisit::walk_item(self, it); intravisit::walk_item(self, it);
} }
} }
fn visit_impl_item(&mut self, it: &'tcx ImplItem<'tcx>) { fn visit_impl_item(&mut self, it: &'tcx ImplItem<'tcx>) {
trace!(?it.def_id); trace!(?it.def_id);
// The opaque type itself or its children are not within its reveal scope. // The opaque type itself or its children are not within its reveal scope.
if it.def_id != self.def_id { if it.def_id.def_id != self.def_id {
self.check(it.def_id); self.check(it.def_id.def_id);
intravisit::walk_impl_item(self, it); intravisit::walk_impl_item(self, it);
} }
} }
fn visit_trait_item(&mut self, it: &'tcx TraitItem<'tcx>) { fn visit_trait_item(&mut self, it: &'tcx TraitItem<'tcx>) {
trace!(?it.def_id); trace!(?it.def_id);
self.check(it.def_id); self.check(it.def_id.def_id);
intravisit::walk_trait_item(self, it); intravisit::walk_trait_item(self, it);
} }
} }

View File

@ -58,10 +58,10 @@ fn check_mod_impl_wf(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
let module = tcx.hir_module_items(module_def_id); let module = tcx.hir_module_items(module_def_id);
for id in module.items() { for id in module.items() {
if matches!(tcx.def_kind(id.def_id), DefKind::Impl) { if matches!(tcx.def_kind(id.def_id), DefKind::Impl) {
enforce_impl_params_are_constrained(tcx, id.def_id); enforce_impl_params_are_constrained(tcx, id.def_id.def_id);
enforce_impl_items_are_distinct(tcx, id.def_id); enforce_impl_items_are_distinct(tcx, id.def_id.def_id);
if min_specialization { if min_specialization {
check_min_specialization(tcx, id.def_id); check_min_specialization(tcx, id.def_id.def_id);
} }
} }
} }

View File

@ -1080,7 +1080,7 @@ pub(crate) fn clean_impl_item<'tcx>(
let mut what_rustc_thinks = let mut what_rustc_thinks =
Item::from_def_id_and_parts(local_did, Some(impl_.ident.name), inner, cx); Item::from_def_id_and_parts(local_did, Some(impl_.ident.name), inner, cx);
let impl_ref = cx.tcx.impl_trait_ref(cx.tcx.local_parent(impl_.def_id)); let impl_ref = cx.tcx.impl_trait_ref(cx.tcx.local_parent(impl_.def_id.def_id));
// Trait impl items always inherit the impl's visibility -- // Trait impl items always inherit the impl's visibility --
// we don't want to show `pub`. // we don't want to show `pub`.
@ -1325,7 +1325,7 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type
segments: trait_segments.iter().map(|x| clean_path_segment(x, cx)).collect(), segments: trait_segments.iter().map(|x| clean_path_segment(x, cx)).collect(),
}; };
register_res(cx, trait_.res); register_res(cx, trait_.res);
let self_def_id = DefId::local(qself.hir_id.owner.local_def_index); let self_def_id = DefId::local(qself.hir_id.owner.def_id.local_def_index);
let self_type = clean_ty(qself, cx); let self_type = clean_ty(qself, cx);
let should_show_cast = compute_should_show_cast(Some(self_def_id), &trait_, &self_type); let should_show_cast = compute_should_show_cast(Some(self_def_id), &trait_, &self_type);
Type::QPath(Box::new(QPathData { Type::QPath(Box::new(QPathData {
@ -2037,7 +2037,7 @@ fn clean_extern_crate<'tcx>(
cx: &mut DocContext<'tcx>, cx: &mut DocContext<'tcx>,
) -> Vec<Item> { ) -> Vec<Item> {
// this is the ID of the `extern crate` statement // this is the ID of the `extern crate` statement
let cnum = cx.tcx.extern_mod_stmt_cnum(krate.def_id).unwrap_or(LOCAL_CRATE); let cnum = cx.tcx.extern_mod_stmt_cnum(krate.def_id.def_id).unwrap_or(LOCAL_CRATE);
// this is the ID of the crate itself // this is the ID of the crate itself
let crate_def_id = cnum.as_def_id(); let crate_def_id = cnum.as_def_id();
let attrs = cx.tcx.hir().attrs(krate.hir_id()); let attrs = cx.tcx.hir().attrs(krate.hir_id());
@ -2099,7 +2099,7 @@ fn clean_use_statement<'tcx>(
let attrs = cx.tcx.hir().attrs(import.hir_id()); let attrs = cx.tcx.hir().attrs(import.hir_id());
let inline_attr = attrs.lists(sym::doc).get_word_attr(sym::inline); let inline_attr = attrs.lists(sym::doc).get_word_attr(sym::inline);
let pub_underscore = visibility.is_public() && name == kw::Underscore; let pub_underscore = visibility.is_public() && name == kw::Underscore;
let current_mod = cx.tcx.parent_module_from_def_id(import.def_id); let current_mod = cx.tcx.parent_module_from_def_id(import.def_id.def_id);
// The parent of the module in which this import resides. This // The parent of the module in which this import resides. This
// is the same as `current_mod` if that's already the top // is the same as `current_mod` if that's already the top

View File

@ -48,7 +48,7 @@ impl<'a, 'tcx> CfgPropagator<'a, 'tcx> {
let expected_parent = hir.get_parent_item(hir_id); let expected_parent = hir.get_parent_item(hir_id);
// If parents are different, it means that `item` is a reexport and we need // If parents are different, it means that `item` is a reexport and we need
// to compute the actual `cfg` by iterating through its "real" parents. // to compute the actual `cfg` by iterating through its "real" parents.
if self.parent == Some(expected_parent) { if self.parent == Some(expected_parent.def_id) {
return; return;
} }
} }

View File

@ -143,14 +143,14 @@ where
// then we need to exit before calling typeck (which will panic). See // then we need to exit before calling typeck (which will panic). See
// test/run-make/rustdoc-scrape-examples-invalid-expr for an example. // test/run-make/rustdoc-scrape-examples-invalid-expr for an example.
let hir = tcx.hir(); let hir = tcx.hir();
if hir.maybe_body_owned_by(ex.hir_id.owner).is_none() { if hir.maybe_body_owned_by(ex.hir_id.owner.def_id).is_none() {
return; return;
} }
// Get type of function if expression is a function call // Get type of function if expression is a function call
let (ty, call_span, ident_span) = match ex.kind { let (ty, call_span, ident_span) = match ex.kind {
hir::ExprKind::Call(f, _) => { hir::ExprKind::Call(f, _) => {
let types = tcx.typeck(ex.hir_id.owner); let types = tcx.typeck(ex.hir_id.owner.def_id);
if let Some(ty) = types.node_type_opt(f.hir_id) { if let Some(ty) = types.node_type_opt(f.hir_id) {
(ty, ex.span, f.span) (ty, ex.span, f.span)
@ -160,7 +160,7 @@ where
} }
} }
hir::ExprKind::MethodCall(path, _, _, call_span) => { hir::ExprKind::MethodCall(path, _, _, call_span) => {
let types = tcx.typeck(ex.hir_id.owner); let types = tcx.typeck(ex.hir_id.owner.def_id);
let Some(def_id) = types.type_dependent_def_id(ex.hir_id) else { let Some(def_id) = types.type_dependent_def_id(ex.hir_id) else {
trace!("type_dependent_def_id({}) = None", ex.hir_id); trace!("type_dependent_def_id({}) = None", ex.hir_id);
return; return;
@ -183,9 +183,8 @@ where
// If the enclosing item has a span coming from a proc macro, then we also don't want to include // If the enclosing item has a span coming from a proc macro, then we also don't want to include
// the example. // the example.
let enclosing_item_span = tcx let enclosing_item_span =
.hir() tcx.hir().span_with_body(tcx.hir().get_parent_item(ex.hir_id).into());
.span_with_body(tcx.hir().local_def_id_to_hir_id(tcx.hir().get_parent_item(ex.hir_id)));
if enclosing_item_span.from_expansion() { if enclosing_item_span.from_expansion() {
trace!("Rejecting expr ({call_span:?}) from macro item: {enclosing_item_span:?}"); trace!("Rejecting expr ({call_span:?}) from macro item: {enclosing_item_span:?}");
return; return;

View File

@ -44,7 +44,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingAllowedAttrPass {
) { ) {
let item = match cx.tcx.hir().get(id) { let item = match cx.tcx.hir().get(id) {
Node::Item(item) => item, Node::Item(item) => item,
_ => cx.tcx.hir().expect_item(cx.tcx.hir().get_parent_item(id)), _ => cx.tcx.hir().expect_item(cx.tcx.hir().get_parent_item(id).def_id),
}; };
let allowed = |attr| pprust::attribute_to_string(attr).contains("allowed_attr"); let allowed = |attr| pprust::attribute_to_string(attr).contains("allowed_attr");

View File

@ -33,7 +33,9 @@ Thir {
region_scope: Node(2), region_scope: Node(2),
lint_level: Explicit( lint_level: Explicit(
HirId { HirId {
owner: DefId(0:3 ~ thir_tree[8f1d]::main), owner: OwnerId {
def_id: DefId(0:3 ~ thir_tree[8f1d]::main),
},
local_id: 2, local_id: 2,
}, },
), ),

View File

@ -704,7 +704,7 @@ fn walk_parents<'tcx>(
span, span,
.. ..
}) if span.ctxt() == ctxt => { }) if span.ctxt() == ctxt => {
let ty = cx.tcx.type_of(def_id); let ty = cx.tcx.type_of(def_id.def_id);
Some(ty_auto_deref_stability(cx, ty, precedence).position_for_result(cx)) Some(ty_auto_deref_stability(cx, ty, precedence).position_for_result(cx))
}, },

View File

@ -233,11 +233,11 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
let body = cx.tcx.hir().body(body_id); let body = cx.tcx.hir().body(body_id);
let mut fpu = FindPanicUnwrap { let mut fpu = FindPanicUnwrap {
cx, cx,
typeck_results: cx.tcx.typeck(item.def_id), typeck_results: cx.tcx.typeck(item.def_id.def_id),
panic_span: None, panic_span: None,
}; };
fpu.visit_expr(body.value); fpu.visit_expr(body.value);
lint_for_missing_headers(cx, item.def_id, item.span, sig, headers, Some(body_id), fpu.panic_span); lint_for_missing_headers(cx, item.def_id.def_id, item.span, sig, headers, Some(body_id), fpu.panic_span);
} }
}, },
hir::ItemKind::Impl(impl_) => { hir::ItemKind::Impl(impl_) => {
@ -268,7 +268,7 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
let headers = check_attrs(cx, &self.valid_idents, attrs); let headers = check_attrs(cx, &self.valid_idents, attrs);
if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind { if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind {
if !in_external_macro(cx.tcx.sess, item.span) { if !in_external_macro(cx.tcx.sess, item.span) {
lint_for_missing_headers(cx, item.def_id, item.span, sig, headers, None, None); lint_for_missing_headers(cx, item.def_id.def_id, item.span, sig, headers, None, None);
} }
} }
} }
@ -283,11 +283,11 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
let body = cx.tcx.hir().body(body_id); let body = cx.tcx.hir().body(body_id);
let mut fpu = FindPanicUnwrap { let mut fpu = FindPanicUnwrap {
cx, cx,
typeck_results: cx.tcx.typeck(item.def_id), typeck_results: cx.tcx.typeck(item.def_id.def_id),
panic_span: None, panic_span: None,
}; };
fpu.visit_expr(body.value); fpu.visit_expr(body.value);
lint_for_missing_headers(cx, item.def_id, item.span, sig, headers, Some(body_id), fpu.panic_span); lint_for_missing_headers(cx, item.def_id.def_id, item.span, sig, headers, Some(body_id), fpu.panic_span);
} }
} }
} }

View File

@ -297,7 +297,7 @@ impl LateLintPass<'_> for EnumVariantNames {
} }
} }
if let ItemKind::Enum(ref def, _) = item.kind { if let ItemKind::Enum(ref def, _) = item.kind {
if !(self.avoid_breaking_exported_api && cx.access_levels.is_exported(item.def_id)) { if !(self.avoid_breaking_exported_api && cx.access_levels.is_exported(item.def_id.def_id)) {
check_variant(cx, self.threshold, def, item_name, item.span); check_variant(cx, self.threshold, def, item_name, item.span);
} }
} }

View File

@ -71,7 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
} }
} }
let parent_id = cx.tcx.hir().get_parent_item(hir_id); let parent_id = cx.tcx.hir().get_parent_item(hir_id).def_id;
let parent_node = cx.tcx.hir().find_by_def_id(parent_id); let parent_node = cx.tcx.hir().find_by_def_id(parent_id);
let mut trait_self_ty = None; let mut trait_self_ty = None;

View File

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

View File

@ -33,7 +33,7 @@ impl<'tcx> LateLintPass<'tcx> for Exit {
if let ExprKind::Path(ref path) = path_expr.kind; if let ExprKind::Path(ref path) = path_expr.kind;
if let Some(def_id) = cx.qpath_res(path, path_expr.hir_id).opt_def_id(); if let Some(def_id) = cx.qpath_res(path, path_expr.hir_id).opt_def_id();
if match_def_path(cx, def_id, &paths::EXIT); if match_def_path(cx, def_id, &paths::EXIT);
let parent = cx.tcx.hir().get_parent_item(e.hir_id); let parent = cx.tcx.hir().get_parent_item(e.hir_id).def_id;
if let Some(Node::Item(Item{kind: ItemKind::Fn(..), ..})) = cx.tcx.hir().find_by_def_id(parent); if let Some(Node::Item(Item{kind: ItemKind::Fn(..), ..})) = cx.tcx.hir().find_by_def_id(parent);
// If the next item up is a function we check if it is an entry point // If the next item up is a function we check if it is an entry point
// and only then emit a linter warning // and only then emit a linter warning

View File

@ -107,7 +107,7 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[h
let body = cx.tcx.hir().body(body_id); let body = cx.tcx.hir().body(body_id);
let mut fpu = FindPanicUnwrap { let mut fpu = FindPanicUnwrap {
lcx: cx, lcx: cx,
typeck_results: cx.tcx.typeck(impl_item.id.def_id), typeck_results: cx.tcx.typeck(impl_item.id.def_id.def_id),
result: Vec::new(), result: Vec::new(),
}; };
fpu.visit_expr(body.value); fpu.visit_expr(body.value);

View File

@ -21,7 +21,7 @@ pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>
let attrs = cx.tcx.hir().attrs(item.hir_id()); let attrs = cx.tcx.hir().attrs(item.hir_id());
let attr = cx.tcx.get_attr(item.def_id.to_def_id(), sym::must_use); let attr = cx.tcx.get_attr(item.def_id.to_def_id(), sym::must_use);
if let hir::ItemKind::Fn(ref sig, _generics, ref body_id) = item.kind { if let hir::ItemKind::Fn(ref sig, _generics, ref body_id) = item.kind {
let is_public = cx.access_levels.is_exported(item.def_id); let is_public = cx.access_levels.is_exported(item.def_id.def_id);
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
if let Some(attr) = attr { if let Some(attr) = attr {
check_needless_must_use(cx, sig.decl, item.hir_id(), item.span, fn_header_span, attr); check_needless_must_use(cx, sig.decl, item.hir_id(), item.span, fn_header_span, attr);
@ -31,7 +31,7 @@ pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>
sig.decl, sig.decl,
cx.tcx.hir().body(*body_id), cx.tcx.hir().body(*body_id),
item.span, item.span,
item.def_id, item.def_id.def_id,
item.span.with_hi(sig.decl.output.span().hi()), item.span.with_hi(sig.decl.output.span().hi()),
"this function could have a `#[must_use]` attribute", "this function could have a `#[must_use]` attribute",
); );
@ -41,19 +41,19 @@ pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>
pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) { pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) {
if let hir::ImplItemKind::Fn(ref sig, ref body_id) = item.kind { if let hir::ImplItemKind::Fn(ref sig, ref body_id) = item.kind {
let is_public = cx.access_levels.is_exported(item.def_id); let is_public = cx.access_levels.is_exported(item.def_id.def_id);
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
let attrs = cx.tcx.hir().attrs(item.hir_id()); let attrs = cx.tcx.hir().attrs(item.hir_id());
let attr = cx.tcx.get_attr(item.def_id.to_def_id(), sym::must_use); let attr = cx.tcx.get_attr(item.def_id.to_def_id(), sym::must_use);
if let Some(attr) = attr { if let Some(attr) = attr {
check_needless_must_use(cx, sig.decl, item.hir_id(), item.span, fn_header_span, attr); check_needless_must_use(cx, sig.decl, item.hir_id(), item.span, fn_header_span, attr);
} else if is_public && !is_proc_macro(cx.sess(), attrs) && trait_ref_of_method(cx, item.def_id).is_none() { } else if is_public && !is_proc_macro(cx.sess(), attrs) && trait_ref_of_method(cx, item.def_id.def_id).is_none() {
check_must_use_candidate( check_must_use_candidate(
cx, cx,
sig.decl, sig.decl,
cx.tcx.hir().body(*body_id), cx.tcx.hir().body(*body_id),
item.span, item.span,
item.def_id, item.def_id.def_id,
item.span.with_hi(sig.decl.output.span().hi()), item.span.with_hi(sig.decl.output.span().hi()),
"this method could have a `#[must_use]` attribute", "this method could have a `#[must_use]` attribute",
); );
@ -63,7 +63,7 @@ pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Imp
pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) { pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) {
if let hir::TraitItemKind::Fn(ref sig, ref eid) = item.kind { if let hir::TraitItemKind::Fn(ref sig, ref eid) = item.kind {
let is_public = cx.access_levels.is_exported(item.def_id); let is_public = cx.access_levels.is_exported(item.def_id.def_id);
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
let attrs = cx.tcx.hir().attrs(item.hir_id()); let attrs = cx.tcx.hir().attrs(item.hir_id());
@ -78,7 +78,7 @@ pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Tr
sig.decl, sig.decl,
body, body,
item.span, item.span,
item.def_id, item.def_id.def_id,
item.span.with_hi(sig.decl.output.span().hi()), item.span.with_hi(sig.decl.output.span().hi()),
"this method could have a `#[must_use]` attribute", "this method could have a `#[must_use]` attribute",
); );
@ -171,7 +171,7 @@ fn is_mutable_pat(cx: &LateContext<'_>, pat: &hir::Pat<'_>, tys: &mut DefIdSet)
return false; // ignore `_` patterns return false; // ignore `_` patterns
} }
if cx.tcx.has_typeck_results(pat.hir_id.owner.to_def_id()) { if cx.tcx.has_typeck_results(pat.hir_id.owner.to_def_id()) {
is_mutable_ty(cx, cx.tcx.typeck(pat.hir_id.owner).pat_ty(pat), pat.span, tys) is_mutable_ty(cx, cx.tcx.typeck(pat.hir_id.owner.def_id).pat_ty(pat), pat.span, tys)
} else { } else {
false false
} }
@ -218,7 +218,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> {
if self.cx.tcx.has_typeck_results(arg.hir_id.owner.to_def_id()) if self.cx.tcx.has_typeck_results(arg.hir_id.owner.to_def_id())
&& is_mutable_ty( && is_mutable_ty(
self.cx, self.cx,
self.cx.tcx.typeck(arg.hir_id.owner).expr_ty(arg), self.cx.tcx.typeck(arg.hir_id.owner.def_id).expr_ty(arg),
arg.span, arg.span,
&mut tys, &mut tys,
) )
@ -236,7 +236,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> {
if self.cx.tcx.has_typeck_results(arg.hir_id.owner.to_def_id()) if self.cx.tcx.has_typeck_results(arg.hir_id.owner.to_def_id())
&& is_mutable_ty( && is_mutable_ty(
self.cx, self.cx,
self.cx.tcx.typeck(arg.hir_id.owner).expr_ty(arg), self.cx.tcx.typeck(arg.hir_id.owner.def_id).expr_ty(arg),
arg.span, arg.span,
&mut tys, &mut tys,
) )

View File

@ -28,7 +28,7 @@ pub(super) fn check_fn<'tcx>(
pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) { pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) {
if let hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(eid)) = item.kind { if let hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(eid)) = item.kind {
let body = cx.tcx.hir().body(eid); let body = cx.tcx.hir().body(eid);
check_raw_ptr(cx, sig.header.unsafety, sig.decl, body, item.def_id); check_raw_ptr(cx, sig.header.unsafety, sig.decl, body, item.def_id.def_id);
} }
} }

View File

@ -34,9 +34,9 @@ fn result_err_ty<'tcx>(
pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::Item<'tcx>, large_err_threshold: u64) { pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::Item<'tcx>, large_err_threshold: u64) {
if let hir::ItemKind::Fn(ref sig, _generics, _) = item.kind if let hir::ItemKind::Fn(ref sig, _generics, _) = item.kind
&& let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.def_id, item.span) && let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.def_id.def_id, item.span)
{ {
if cx.access_levels.is_exported(item.def_id) { if cx.access_levels.is_exported(item.def_id.def_id) {
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
check_result_unit_err(cx, err_ty, fn_header_span); check_result_unit_err(cx, err_ty, fn_header_span);
} }
@ -47,10 +47,10 @@ pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::Item<'tcx>, l
pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::ImplItem<'tcx>, large_err_threshold: u64) { pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::ImplItem<'tcx>, large_err_threshold: u64) {
// Don't lint if method is a trait's implementation, we can't do anything about those // Don't lint if method is a trait's implementation, we can't do anything about those
if let hir::ImplItemKind::Fn(ref sig, _) = item.kind if let hir::ImplItemKind::Fn(ref sig, _) = item.kind
&& let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.def_id, item.span) && let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.def_id.def_id, item.span)
&& trait_ref_of_method(cx, item.def_id).is_none() && trait_ref_of_method(cx, item.def_id.def_id).is_none()
{ {
if cx.access_levels.is_exported(item.def_id) { if cx.access_levels.is_exported(item.def_id.def_id) {
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
check_result_unit_err(cx, err_ty, fn_header_span); check_result_unit_err(cx, err_ty, fn_header_span);
} }
@ -61,8 +61,8 @@ pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::ImplItem
pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::TraitItem<'tcx>, large_err_threshold: u64) { pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::TraitItem<'tcx>, large_err_threshold: u64) {
if let hir::TraitItemKind::Fn(ref sig, _) = item.kind { if let hir::TraitItemKind::Fn(ref sig, _) = item.kind {
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
if let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.def_id, item.span) { if let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.def_id.def_id, item.span) {
if cx.access_levels.is_exported(item.def_id) { if cx.access_levels.is_exported(item.def_id.def_id) {
check_result_unit_err(cx, err_ty, fn_header_span); check_result_unit_err(cx, err_ty, fn_header_span);
} }
check_result_large_err(cx, err_ty, hir_ty.span, large_err_threshold); check_result_large_err(cx, err_ty, hir_ty.span, large_err_threshold);

View File

@ -112,7 +112,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher {
} }
} }
if !cx.access_levels.is_exported(item.def_id) { if !cx.access_levels.is_exported(item.def_id.def_id) {
return; return;
} }

View File

@ -108,7 +108,7 @@ impl<'tcx> LateLintPass<'tcx> for InherentToString {
if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::String); if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::String);
// Filters instances of to_string which are required by a trait // Filters instances of to_string which are required by a trait
if trait_ref_of_method(cx, impl_item.def_id).is_none(); if trait_ref_of_method(cx, impl_item.def_id.def_id).is_none();
then { then {
show_lint(cx, impl_item); show_lint(cx, impl_item);

View File

@ -44,7 +44,7 @@ impl<'tcx> LateLintPass<'tcx> for IterNotReturningIterator {
let name = item.ident.name.as_str(); let name = item.ident.name.as_str();
if matches!(name, "iter" | "iter_mut") { if matches!(name, "iter" | "iter_mut") {
if let TraitItemKind::Fn(fn_sig, _) = &item.kind { if let TraitItemKind::Fn(fn_sig, _) = &item.kind {
check_sig(cx, name, fn_sig, item.def_id); check_sig(cx, name, fn_sig, item.def_id.def_id);
} }
} }
} }
@ -58,7 +58,7 @@ impl<'tcx> LateLintPass<'tcx> for IterNotReturningIterator {
) )
{ {
if let ImplItemKind::Fn(fn_sig, _) = &item.kind { if let ImplItemKind::Fn(fn_sig, _) = &item.kind {
check_sig(cx, name, fn_sig, item.def_id); check_sig(cx, name, fn_sig, item.def_id.def_id);
} }
} }
} }

View File

@ -134,7 +134,7 @@ impl<'tcx> LateLintPass<'tcx> for LenZero {
if item.ident.name == sym::len; if item.ident.name == sym::len;
if let ImplItemKind::Fn(sig, _) = &item.kind; if let ImplItemKind::Fn(sig, _) = &item.kind;
if sig.decl.implicit_self.has_implicit_self(); if sig.decl.implicit_self.has_implicit_self();
if cx.access_levels.is_exported(item.def_id); if cx.access_levels.is_exported(item.def_id.def_id);
if matches!(sig.decl.output, FnRetTy::Return(_)); if matches!(sig.decl.output, FnRetTy::Return(_));
if let Some(imp) = get_parent_as_impl(cx.tcx, item.hir_id()); if let Some(imp) = get_parent_as_impl(cx.tcx, item.hir_id());
if imp.of_trait.is_none(); if imp.of_trait.is_none();
@ -210,7 +210,7 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, trait_items
} }
} }
if cx.access_levels.is_exported(visited_trait.def_id) && trait_items.iter().any(|i| is_named_self(cx, i, sym::len)) if cx.access_levels.is_exported(visited_trait.def_id.def_id) && trait_items.iter().any(|i| is_named_self(cx, i, sym::len))
{ {
let mut current_and_super_traits = DefIdSet::default(); let mut current_and_super_traits = DefIdSet::default();
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);

View File

@ -102,7 +102,7 @@ impl<'tcx> LateLintPass<'tcx> for Lifetimes {
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) {
if let ImplItemKind::Fn(ref sig, id) = item.kind { if let ImplItemKind::Fn(ref sig, id) = item.kind {
let report_extra_lifetimes = trait_ref_of_method(cx, item.def_id).is_none(); let report_extra_lifetimes = trait_ref_of_method(cx, item.def_id.def_id).is_none();
check_fn_inner( check_fn_inner(
cx, cx,
sig.decl, sig.decl,
@ -276,7 +276,7 @@ fn could_use_elision<'tcx>(
let mut checker = BodyLifetimeChecker { let mut checker = BodyLifetimeChecker {
lifetimes_used_in_body: false, lifetimes_used_in_body: false,
}; };
checker.visit_expr(body.value); checker.visit_expr(&body.value);
if checker.lifetimes_used_in_body { if checker.lifetimes_used_in_body {
return false; return false;
} }

View File

@ -69,7 +69,7 @@ fn check_for_mutation<'tcx>(
ExprUseVisitor::new( ExprUseVisitor::new(
&mut delegate, &mut delegate,
&infcx, &infcx,
body.hir_id.owner, body.hir_id.owner.def_id,
cx.param_env, cx.param_env,
cx.typeck_results(), cx.typeck_results(),
) )

View File

@ -166,7 +166,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustiveEnum {
if let Some((id, span)) = iter.next() if let Some((id, span)) = iter.next()
&& iter.next().is_none() && iter.next().is_none()
{ {
self.potential_enums.push((item.def_id, id, item.span, span)); self.potential_enums.push((item.def_id.def_id, id, item.span, span));
} }
} }
} }

View File

@ -3250,7 +3250,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
return; return;
} }
let name = impl_item.ident.name.as_str(); let name = impl_item.ident.name.as_str();
let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()); let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()).def_id;
let item = cx.tcx.hir().expect_item(parent); let item = cx.tcx.hir().expect_item(parent);
let self_ty = cx.tcx.type_of(item.def_id); let self_ty = cx.tcx.type_of(item.def_id);
@ -3259,7 +3259,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
if let hir::ImplItemKind::Fn(ref sig, id) = impl_item.kind; if let hir::ImplItemKind::Fn(ref sig, id) = impl_item.kind;
if let Some(first_arg) = iter_input_pats(sig.decl, cx.tcx.hir().body(id)).next(); if let Some(first_arg) = iter_input_pats(sig.decl, cx.tcx.hir().body(id)).next();
let method_sig = cx.tcx.fn_sig(impl_item.def_id); let method_sig = cx.tcx.fn_sig(impl_item.def_id.def_id);
let method_sig = cx.tcx.erase_late_bound_regions(method_sig); let method_sig = cx.tcx.erase_late_bound_regions(method_sig);
let first_arg_ty = method_sig.inputs().iter().next(); let first_arg_ty = method_sig.inputs().iter().next();
@ -3269,7 +3269,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
then { then {
// if this impl block implements a trait, lint in trait definition instead // if this impl block implements a trait, lint in trait definition instead
if !implements_trait && cx.access_levels.is_exported(impl_item.def_id) { if !implements_trait && cx.access_levels.is_exported(impl_item.def_id.def_id) {
// check missing trait implementations // check missing trait implementations
for method_config in &TRAIT_METHODS { for method_config in &TRAIT_METHODS {
if name == method_config.method_name && if name == method_config.method_name &&
@ -3301,7 +3301,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
if sig.decl.implicit_self.has_implicit_self() if sig.decl.implicit_self.has_implicit_self()
&& !(self.avoid_breaking_exported_api && !(self.avoid_breaking_exported_api
&& cx.access_levels.is_exported(impl_item.def_id)) && cx.access_levels.is_exported(impl_item.def_id.def_id))
{ {
wrong_self_convention::check( wrong_self_convention::check(
cx, cx,

View File

@ -136,7 +136,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn {
// Const fns are not allowed as methods in a trait. // Const fns are not allowed as methods in a trait.
{ {
let parent = cx.tcx.hir().get_parent_item(hir_id); let parent = cx.tcx.hir().get_parent_item(hir_id).def_id;
if parent != CRATE_DEF_ID { if parent != CRATE_DEF_ID {
if let hir::Node::Item(item) = cx.tcx.hir().get_by_def_id(parent) { if let hir::Node::Item(item) = cx.tcx.hir().get_by_def_id(parent) {
if let hir::ItemKind::Trait(..) = &item.kind { if let hir::ItemKind::Trait(..) = &item.kind {

View File

@ -131,7 +131,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
hir::ItemKind::Fn(..) => { hir::ItemKind::Fn(..) => {
// ignore main() // ignore main()
if it.ident.name == sym::main { if it.ident.name == sym::main {
let at_root = cx.tcx.local_parent(it.def_id) == CRATE_DEF_ID; let at_root = cx.tcx.local_parent(it.def_id.def_id) == CRATE_DEF_ID;
if at_root { if at_root {
return; return;
} }

View File

@ -88,7 +88,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
return; return;
} }
if !cx.access_levels.is_exported(it.def_id) { if !cx.access_levels.is_exported(it.def_id.def_id) {
return; return;
} }
match it.kind { match it.kind {
@ -142,7 +142,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
} }
// If the item being implemented is not exported, then we don't need #[inline] // If the item being implemented is not exported, then we don't need #[inline]
if !cx.access_levels.is_exported(impl_item.def_id) { if !cx.access_levels.is_exported(impl_item.def_id.def_id) {
return; return;
} }
@ -159,7 +159,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
}; };
if let Some(trait_def_id) = trait_def_id { if let Some(trait_def_id) = trait_def_id {
if trait_def_id.is_local() && !cx.access_levels.is_exported(impl_item.def_id) { if trait_def_id.is_local() && !cx.access_levels.is_exported(impl_item.def_id.def_id) {
// If a trait is being implemented for an item, and the // If a trait is being implemented for an item, and the
// trait is not exported, we don't need #[inline] // trait is not exported, we don't need #[inline]
return; return;

View File

@ -89,7 +89,7 @@ impl<'tcx> LateLintPass<'tcx> for MutableKeyType {
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'tcx>) { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'tcx>) {
if let hir::ImplItemKind::Fn(ref sig, ..) = item.kind { if let hir::ImplItemKind::Fn(ref sig, ..) = item.kind {
if trait_ref_of_method(cx, item.def_id).is_none() { if trait_ref_of_method(cx, item.def_id.def_id).is_none() {
check_sig(cx, item.hir_id(), sig.decl); check_sig(cx, item.hir_id(), sig.decl);
} }
} }

View File

@ -84,7 +84,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault {
// can't be implemented for unsafe new // can't be implemented for unsafe new
return; return;
} }
if cx.tcx.is_doc_hidden(impl_item.def_id) { if cx.tcx.is_doc_hidden(impl_item.def_id.def_id) {
// shouldn't be implemented when it is hidden in docs // shouldn't be implemented when it is hidden in docs
return; return;
} }
@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault {
if_chain! { if_chain! {
if sig.decl.inputs.is_empty(); if sig.decl.inputs.is_empty();
if name == sym::new; if name == sym::new;
if cx.access_levels.is_reachable(impl_item.def_id); if cx.access_levels.is_reachable(impl_item.def_id.def_id);
let self_def_id = cx.tcx.hir().get_parent_item(id); let self_def_id = cx.tcx.hir().get_parent_item(id);
let self_ty = cx.tcx.type_of(self_def_id); let self_ty = cx.tcx.type_of(self_def_id);
if self_ty == return_ty(cx, id); if self_ty == return_ty(cx, id);

View File

@ -286,7 +286,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst {
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx ImplItem<'_>) { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx ImplItem<'_>) {
if let ImplItemKind::Const(hir_ty, body_id) = &impl_item.kind { if let ImplItemKind::Const(hir_ty, body_id) = &impl_item.kind {
let item_def_id = cx.tcx.hir().get_parent_item(impl_item.hir_id()); let item_def_id = cx.tcx.hir().get_parent_item(impl_item.hir_id()).def_id;
let item = cx.tcx.hir().expect_item(item_def_id); let item = cx.tcx.hir().expect_item(item_def_id);
match &item.kind { match &item.kind {

View File

@ -243,7 +243,7 @@ impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion {
.. ..
})) => { })) => {
#[allow(trivial_casts)] #[allow(trivial_casts)]
if let Some(Node::Item(item)) = get_parent_node(cx.tcx, cx.tcx.hir().local_def_id_to_hir_id(def_id)) if let Some(Node::Item(item)) = get_parent_node(cx.tcx, def_id.into())
&& let Some(trait_ref) = cx.tcx.impl_trait_ref(item.def_id) && let Some(trait_ref) = cx.tcx.impl_trait_ref(item.def_id)
&& let Some(trait_item_id) = cx.tcx.associated_item(def_id).trait_item_def_id && let Some(trait_item_id) = cx.tcx.associated_item(def_id).trait_item_def_id
{ {

View File

@ -28,7 +28,7 @@ pub(super) fn check<'tcx>(
if_chain! { if_chain! {
if let Some((_, lang_item)) = binop_traits(op.node); if let Some((_, lang_item)) = binop_traits(op.node);
if let Ok(trait_id) = cx.tcx.lang_items().require(lang_item); if let Ok(trait_id) = cx.tcx.lang_items().require(lang_item);
let parent_fn = cx.tcx.hir().get_parent_item(e.hir_id); let parent_fn = cx.tcx.hir().get_parent_item(e.hir_id).def_id;
if trait_ref_of_method(cx, parent_fn) if trait_ref_of_method(cx, parent_fn)
.map_or(true, |t| t.path.res.def_id() != trait_id); .map_or(true, |t| t.path.res.def_id() != trait_id);
if implements_trait(cx, ty, trait_id, &[rty.into()]); if implements_trait(cx, ty, trait_id, &[rty.into()]);

View File

@ -261,7 +261,7 @@ impl<'tcx> LateLintPass<'tcx> for PassByRefOrValue {
} }
if let hir::TraitItemKind::Fn(method_sig, _) = &item.kind { if let hir::TraitItemKind::Fn(method_sig, _) = &item.kind {
self.check_poly_fn(cx, item.def_id, method_sig.decl, None); self.check_poly_fn(cx, item.def_id.def_id, method_sig.decl, None);
} }
} }

View File

@ -46,8 +46,8 @@ impl_lint_pass!(RedundantPubCrate => [REDUNDANT_PUB_CRATE]);
impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate { impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
if_chain! { if_chain! {
if cx.tcx.visibility(item.def_id) == ty::Visibility::Restricted(CRATE_DEF_ID.to_def_id()); if cx.tcx.visibility(item.def_id.def_id) == ty::Visibility::Restricted(CRATE_DEF_ID.to_def_id());
if !cx.access_levels.is_exported(item.def_id) && self.is_exported.last() == Some(&false); if !cx.access_levels.is_exported(item.def_id.def_id) && self.is_exported.last() == Some(&false);
if is_not_macro_export(item); if is_not_macro_export(item);
then { then {
let span = item.span.with_hi(item.ident.span.hi()); let span = item.span.with_hi(item.ident.span.hi());
@ -70,7 +70,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate {
} }
if let ItemKind::Mod { .. } = item.kind { if let ItemKind::Mod { .. } = item.kind {
self.is_exported.push(cx.access_levels.is_exported(item.def_id)); self.is_exported.push(cx.access_levels.is_exported(item.def_id.def_id));
} }
} }

View File

@ -128,7 +128,7 @@ impl<'tcx> LateLintPass<'tcx> for ReturnSelfNotMustUse {
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'tcx>) { fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'tcx>) {
if let TraitItemKind::Fn(ref sig, _) = item.kind { if let TraitItemKind::Fn(ref sig, _) = item.kind {
check_method(cx, sig.decl, item.def_id, item.span, item.hir_id()); check_method(cx, sig.decl, item.def_id.def_id, item.span, item.hir_id());
} }
} }
} }

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