Only store a LocalDefId in hir::ImplItem.
This commit is contained in:
parent
a871a0f111
commit
786a80e9ea
56 changed files with 163 additions and 165 deletions
|
@ -98,7 +98,7 @@ impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> {
|
|||
}
|
||||
AssocCtxt::Impl => {
|
||||
let hir_item = lctx.lower_impl_item(item);
|
||||
let id = hir::ImplItemId { hir_id: hir_item.hir_id };
|
||||
let id = hir_item.impl_item_id();
|
||||
lctx.impl_items.insert(id, hir_item);
|
||||
lctx.modules.get_mut(&lctx.current_module).unwrap().impl_items.insert(id);
|
||||
}
|
||||
|
@ -931,7 +931,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
let has_value = true;
|
||||
let (defaultness, _) = self.lower_defaultness(i.kind.defaultness(), has_value);
|
||||
hir::ImplItem {
|
||||
hir_id: self.lower_node_id(i.id),
|
||||
def_id: self.lower_node_id(i.id).expect_owner(),
|
||||
ident: i.ident,
|
||||
attrs: self.lower_attrs(&i.attrs),
|
||||
generics,
|
||||
|
@ -947,7 +947,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
let has_value = true;
|
||||
let (defaultness, _) = self.lower_defaultness(i.kind.defaultness(), has_value);
|
||||
hir::ImplItemRef {
|
||||
id: hir::ImplItemId { hir_id: self.lower_node_id(i.id) },
|
||||
id: hir::ImplItemId { def_id: self.lower_node_id(i.id).expect_owner() },
|
||||
ident: i.ident,
|
||||
span: i.span,
|
||||
vis: self.lower_visibility(&i.vis, Some(i.id)),
|
||||
|
|
|
@ -1969,14 +1969,21 @@ pub enum TraitItemKind<'hir> {
|
|||
// so it can fetched later.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Encodable, Debug)]
|
||||
pub struct ImplItemId {
|
||||
pub hir_id: HirId,
|
||||
pub def_id: LocalDefId,
|
||||
}
|
||||
|
||||
impl ImplItemId {
|
||||
pub fn hir_id(&self) -> HirId {
|
||||
// Items are always HIR owners.
|
||||
HirId::make_owner(self.def_id)
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents anything within an `impl` block.
|
||||
#[derive(Debug)]
|
||||
pub struct ImplItem<'hir> {
|
||||
pub ident: Ident,
|
||||
pub hir_id: HirId,
|
||||
pub def_id: LocalDefId,
|
||||
pub vis: Visibility<'hir>,
|
||||
pub defaultness: Defaultness,
|
||||
pub attrs: &'hir [Attribute],
|
||||
|
@ -1985,6 +1992,17 @@ pub struct ImplItem<'hir> {
|
|||
pub span: Span,
|
||||
}
|
||||
|
||||
impl ImplItem<'_> {
|
||||
pub fn hir_id(&self) -> HirId {
|
||||
// Items are always HIR owners.
|
||||
HirId::make_owner(self.def_id)
|
||||
}
|
||||
|
||||
pub fn impl_item_id(&self) -> ImplItemId {
|
||||
ImplItemId { def_id: self.def_id }
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents various kinds of content within an `impl`.
|
||||
#[derive(Debug, HashStable_Generic)]
|
||||
pub enum ImplItemKind<'hir> {
|
||||
|
@ -2903,11 +2921,10 @@ impl<'hir> Node<'hir> {
|
|||
|
||||
pub fn hir_id(&self) -> Option<HirId> {
|
||||
match self {
|
||||
Node::Item(Item { def_id, .. }) | Node::TraitItem(TraitItem { def_id, .. }) => {
|
||||
Some(HirId::make_owner(*def_id))
|
||||
}
|
||||
Node::Item(Item { def_id, .. })
|
||||
| Node::TraitItem(TraitItem { def_id, .. })
|
||||
| Node::ImplItem(ImplItem { def_id, .. }) => Some(HirId::make_owner(*def_id)),
|
||||
Node::ForeignItem(ForeignItem { hir_id, .. })
|
||||
| Node::ImplItem(ImplItem { hir_id, .. })
|
||||
| Node::Field(StructField { hir_id, .. })
|
||||
| Node::AnonConst(AnonConst { hir_id, .. })
|
||||
| Node::Expr(Expr { hir_id, .. })
|
||||
|
|
|
@ -1004,7 +1004,7 @@ pub fn walk_trait_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_item_ref:
|
|||
pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplItem<'v>) {
|
||||
// N.B., deliberately force a compilation error if/when new fields are added.
|
||||
let ImplItem {
|
||||
hir_id: _,
|
||||
def_id: _,
|
||||
ident,
|
||||
ref vis,
|
||||
ref defaultness,
|
||||
|
@ -1021,7 +1021,7 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt
|
|||
visitor.visit_generics(generics);
|
||||
match *kind {
|
||||
ImplItemKind::Const(ref ty, body) => {
|
||||
visitor.visit_id(impl_item.hir_id);
|
||||
visitor.visit_id(impl_item.hir_id());
|
||||
visitor.visit_ty(ty);
|
||||
visitor.visit_nested_body(body);
|
||||
}
|
||||
|
@ -1031,11 +1031,11 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt
|
|||
&sig.decl,
|
||||
body_id,
|
||||
impl_item.span,
|
||||
impl_item.hir_id,
|
||||
impl_item.hir_id(),
|
||||
);
|
||||
}
|
||||
ImplItemKind::TyAlias(ref ty) => {
|
||||
visitor.visit_id(impl_item.hir_id);
|
||||
visitor.visit_id(impl_item.hir_id());
|
||||
visitor.visit_ty(ty);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,11 +53,11 @@ impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for TraitItemId {
|
|||
}
|
||||
|
||||
impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ImplItemId {
|
||||
type KeyType = (DefPathHash, ItemLocalId);
|
||||
type KeyType = DefPathHash;
|
||||
|
||||
#[inline]
|
||||
fn to_stable_hash_key(&self, hcx: &HirCtx) -> (DefPathHash, ItemLocalId) {
|
||||
self.hir_id.to_stable_hash_key(hcx)
|
||||
fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash {
|
||||
hcx.local_def_path_hash(self.def_id)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -103,7 +103,7 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ForeignItemId {
|
|||
|
||||
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ImplItemId {
|
||||
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
|
||||
hcx.hash_reference_to_item(self.hir_id, hasher)
|
||||
hcx.hash_reference_to_item(self.hir_id(), hasher)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -154,7 +154,7 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for TraitItem<'_> {
|
|||
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ImplItem<'_> {
|
||||
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
|
||||
let ImplItem {
|
||||
hir_id: _,
|
||||
def_id: _,
|
||||
ident,
|
||||
ref vis,
|
||||
defaultness,
|
||||
|
|
|
@ -973,7 +973,7 @@ impl<'a> State<'a> {
|
|||
}
|
||||
|
||||
pub fn print_impl_item(&mut self, ii: &hir::ImplItem<'_>) {
|
||||
self.ann.pre(self, AnnNode::SubItem(ii.hir_id));
|
||||
self.ann.pre(self, AnnNode::SubItem(ii.hir_id()));
|
||||
self.hardbreak_if_not_bol();
|
||||
self.maybe_print_comment(ii.span.lo());
|
||||
self.print_outer_attributes(&ii.attrs);
|
||||
|
@ -995,7 +995,7 @@ impl<'a> State<'a> {
|
|||
self.print_associated_type(ii.ident, &ii.generics, None, Some(ty));
|
||||
}
|
||||
}
|
||||
self.ann.post(self, AnnNode::SubItem(ii.hir_id))
|
||||
self.ann.post(self, AnnNode::SubItem(ii.hir_id()))
|
||||
}
|
||||
|
||||
pub fn print_local(&mut self, init: Option<&hir::Expr<'_>>, decl: impl Fn(&mut Self)) {
|
||||
|
|
|
@ -177,7 +177,7 @@ impl Visitor<'tcx> for IfThisChanged<'tcx> {
|
|||
}
|
||||
|
||||
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
|
||||
self.process_attrs(impl_item.hir_id, &impl_item.attrs);
|
||||
self.process_attrs(impl_item.hir_id(), &impl_item.attrs);
|
||||
intravisit::walk_impl_item(self, impl_item);
|
||||
}
|
||||
|
||||
|
|
|
@ -458,7 +458,7 @@ impl ItemLikeVisitor<'tcx> for DirtyCleanVisitor<'tcx> {
|
|||
}
|
||||
|
||||
fn visit_impl_item(&mut self, item: &hir::ImplItem<'_>) {
|
||||
self.check_item(item.hir_id, item.span);
|
||||
self.check_item(item.hir_id(), item.span);
|
||||
}
|
||||
|
||||
fn visit_foreign_item(&mut self, item: &hir::ForeignItem<'_>) {
|
||||
|
|
|
@ -7,9 +7,7 @@ use crate::traits::{ObligationCauseCode, UnifyReceiverContext};
|
|||
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorReported};
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::intravisit::{walk_ty, ErasedMap, NestedVisitorMap, Visitor};
|
||||
use rustc_hir::{
|
||||
self as hir, GenericBound, ImplItem, Item, ItemKind, Lifetime, LifetimeName, Node, TyKind,
|
||||
};
|
||||
use rustc_hir::{self as hir, GenericBound, Item, ItemKind, Lifetime, LifetimeName, Node, TyKind};
|
||||
use rustc_middle::ty::{self, AssocItemContainer, RegionKind, Ty, TypeFoldable, TypeVisitor};
|
||||
use rustc_span::symbol::Ident;
|
||||
use rustc_span::{MultiSpan, Span};
|
||||
|
@ -342,12 +340,12 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||
) -> Option<(Ident, &'tcx hir::Ty<'tcx>)> {
|
||||
let tcx = self.tcx();
|
||||
match tcx.hir().get_if_local(def_id) {
|
||||
Some(Node::ImplItem(ImplItem { ident, hir_id, .. })) => {
|
||||
match tcx.hir().find(tcx.hir().get_parent_item(*hir_id)) {
|
||||
Some(Node::ImplItem(impl_item)) => {
|
||||
match tcx.hir().find(tcx.hir().get_parent_item(impl_item.hir_id())) {
|
||||
Some(Node::Item(Item {
|
||||
kind: ItemKind::Impl(hir::Impl { self_ty, .. }),
|
||||
..
|
||||
})) => Some((*ident, self_ty)),
|
||||
})) => Some((impl_item.ident, self_ty)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -600,7 +600,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
|
|||
if let Some(Node::Item(item)) = cx.tcx.hir().find(hir_id) {
|
||||
if let hir::VisibilityKind::Inherited = item.vis.node {
|
||||
for impl_item_ref in items {
|
||||
self.private_traits.insert(impl_item_ref.id.hir_id);
|
||||
self.private_traits.insert(impl_item_ref.id.hir_id());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -644,15 +644,14 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
|
|||
|
||||
fn check_impl_item(&mut self, cx: &LateContext<'_>, impl_item: &hir::ImplItem<'_>) {
|
||||
// If the method is an impl for a trait, don't doc.
|
||||
if method_context(cx, impl_item.hir_id) == MethodLateContext::TraitImpl {
|
||||
if method_context(cx, impl_item.hir_id()) == MethodLateContext::TraitImpl {
|
||||
return;
|
||||
}
|
||||
|
||||
let def_id = cx.tcx.hir().local_def_id(impl_item.hir_id);
|
||||
let (article, desc) = cx.tcx.article_and_description(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,
|
||||
Some(impl_item.hir_id),
|
||||
Some(impl_item.hir_id()),
|
||||
&impl_item.attrs,
|
||||
impl_item.span,
|
||||
article,
|
||||
|
@ -1378,7 +1377,7 @@ impl<'tcx> LateLintPass<'tcx> for UnreachablePub {
|
|||
}
|
||||
|
||||
fn check_impl_item(&mut self, cx: &LateContext<'_>, impl_item: &hir::ImplItem<'_>) {
|
||||
self.perform_lint(cx, "item", impl_item.hir_id, &impl_item.vis, impl_item.span, false);
|
||||
self.perform_lint(cx, "item", impl_item.hir_id(), &impl_item.vis, impl_item.span, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -314,8 +314,8 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
|
|||
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
|
||||
let generics = self.context.generics.take();
|
||||
self.context.generics = Some(&impl_item.generics);
|
||||
self.with_lint_attrs(impl_item.hir_id, &impl_item.attrs, |cx| {
|
||||
cx.with_param_env(impl_item.hir_id, |cx| {
|
||||
self.with_lint_attrs(impl_item.hir_id(), &impl_item.attrs, |cx| {
|
||||
cx.with_param_env(impl_item.hir_id(), |cx| {
|
||||
lint_callback!(cx, check_impl_item, impl_item);
|
||||
hir_visit::walk_impl_item(cx, impl_item);
|
||||
lint_callback!(cx, check_impl_item_post, impl_item);
|
||||
|
|
|
@ -637,7 +637,7 @@ impl<'tcx> intravisit::Visitor<'tcx> for LintLevelMapBuilder<'_, 'tcx> {
|
|||
}
|
||||
|
||||
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
|
||||
self.with_lint_attrs(impl_item.hir_id, &impl_item.attrs, |builder| {
|
||||
self.with_lint_attrs(impl_item.hir_id(), &impl_item.attrs, |builder| {
|
||||
intravisit::walk_impl_item(builder, impl_item);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -235,7 +235,7 @@ impl<'a> FnLikeNode<'a> {
|
|||
},
|
||||
Node::ImplItem(ii) => match ii.kind {
|
||||
hir::ImplItemKind::Fn(ref sig, body) => {
|
||||
method(ii.hir_id, ii.ident, sig, Some(&ii.vis), body, ii.span, &ii.attrs)
|
||||
method(ii.hir_id(), ii.ident, sig, Some(&ii.vis), body, ii.span, &ii.attrs)
|
||||
}
|
||||
_ => bug!("impl method FnLikeNode that is not fn-like"),
|
||||
},
|
||||
|
|
|
@ -401,14 +401,10 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
|
|||
}
|
||||
|
||||
fn visit_impl_item(&mut self, ii: &'hir ImplItem<'hir>) {
|
||||
debug_assert_eq!(
|
||||
ii.hir_id.owner,
|
||||
self.definitions.opt_hir_id_to_local_def_id(ii.hir_id).unwrap()
|
||||
);
|
||||
self.with_dep_node_owner(ii.hir_id.owner, ii, |this, hash| {
|
||||
this.insert_with_hash(ii.span, ii.hir_id, Node::ImplItem(ii), hash);
|
||||
self.with_dep_node_owner(ii.def_id, ii, |this, hash| {
|
||||
this.insert_with_hash(ii.span, ii.hir_id(), Node::ImplItem(ii), hash);
|
||||
|
||||
this.with_parent(ii.hir_id, |this| {
|
||||
this.with_parent(ii.hir_id(), |this| {
|
||||
intravisit::walk_impl_item(this, ii);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -315,7 +315,7 @@ impl<'hir> Map<'hir> {
|
|||
}
|
||||
|
||||
pub fn impl_item(&self, id: ImplItemId) -> &'hir ImplItem<'hir> {
|
||||
match self.find(id.hir_id).unwrap() {
|
||||
match self.find(id.hir_id()).unwrap() {
|
||||
Node::ImplItem(item) => item,
|
||||
_ => bug!(),
|
||||
}
|
||||
|
|
|
@ -836,7 +836,7 @@ fn foo(&self) -> Self::T { String::new() }
|
|||
})) => {
|
||||
for item in &items[..] {
|
||||
if let hir::AssocItemKind::Type = item.kind {
|
||||
if self.type_of(self.hir().local_def_id(item.id.hir_id)) == found {
|
||||
if self.type_of(item.id.def_id) == found {
|
||||
db.span_label(item.span, "expected this associated type");
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1060,8 +1060,7 @@ impl ItemLikeVisitor<'v> for RootCollector<'_, 'v> {
|
|||
|
||||
fn visit_impl_item(&mut self, ii: &'v hir::ImplItem<'v>) {
|
||||
if let hir::ImplItemKind::Fn(hir::FnSig { .. }, _) = ii.kind {
|
||||
let def_id = self.tcx.hir().local_def_id(ii.hir_id);
|
||||
self.push_if_root(def_id);
|
||||
self.push_if_root(ii.def_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ pub(crate) fn target_from_impl_item<'tcx>(
|
|||
match impl_item.kind {
|
||||
hir::ImplItemKind::Const(..) => Target::AssocConst,
|
||||
hir::ImplItemKind::Fn(..) => {
|
||||
let parent_hir_id = tcx.hir().get_parent_item(impl_item.hir_id);
|
||||
let parent_hir_id = tcx.hir().get_parent_item(impl_item.hir_id());
|
||||
let containing_item = tcx.hir().expect_item(parent_hir_id);
|
||||
let containing_impl_is_for_trait = match &containing_item.kind {
|
||||
hir::ItemKind::Impl(impl_) => impl_.of_trait.is_some(),
|
||||
|
@ -1121,7 +1121,7 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
|
|||
|
||||
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
|
||||
let target = target_from_impl_item(self.tcx, impl_item);
|
||||
self.check_attributes(impl_item.hir_id, &impl_item.attrs, &impl_item.span, target, None);
|
||||
self.check_attributes(impl_item.hir_id(), &impl_item.attrs, &impl_item.span, target, None);
|
||||
intravisit::walk_impl_item(self, impl_item)
|
||||
}
|
||||
|
||||
|
|
|
@ -420,11 +420,11 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
|
|||
if of_trait.is_some()
|
||||
|| has_allow_dead_code_or_lang_attr(
|
||||
self.tcx,
|
||||
impl_item.hir_id,
|
||||
impl_item.hir_id(),
|
||||
&impl_item.attrs,
|
||||
)
|
||||
{
|
||||
self.worklist.push(impl_item_ref.id.hir_id);
|
||||
self.worklist.push(impl_item_ref.id.hir_id());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -664,9 +664,9 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> {
|
|||
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
|
||||
match impl_item.kind {
|
||||
hir::ImplItemKind::Const(_, body_id) => {
|
||||
if !self.symbol_is_live(impl_item.hir_id) {
|
||||
if !self.symbol_is_live(impl_item.hir_id()) {
|
||||
self.warn_dead_code(
|
||||
impl_item.hir_id,
|
||||
impl_item.hir_id(),
|
||||
impl_item.span,
|
||||
impl_item.ident.name,
|
||||
"used",
|
||||
|
@ -675,7 +675,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> {
|
|||
self.visit_nested_body(body_id)
|
||||
}
|
||||
hir::ImplItemKind::Fn(_, body_id) => {
|
||||
if !self.symbol_is_live(impl_item.hir_id) {
|
||||
if !self.symbol_is_live(impl_item.hir_id()) {
|
||||
// FIXME(66095): Because impl_item.span is annotated with things
|
||||
// like expansion data, and ident.span isn't, we use the
|
||||
// def_span method if it's part of a macro invocation
|
||||
|
@ -687,7 +687,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> {
|
|||
} else {
|
||||
impl_item.ident.span
|
||||
};
|
||||
self.warn_dead_code(impl_item.hir_id, span, impl_item.ident.name, "used");
|
||||
self.warn_dead_code(impl_item.hir_id(), span, impl_item.ident.name, "used");
|
||||
}
|
||||
self.visit_nested_body(body_id)
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ impl<'v, 'tcx> ItemLikeVisitor<'v> for DiagnosticItemCollector<'tcx> {
|
|||
}
|
||||
|
||||
fn visit_impl_item(&mut self, impl_item: &hir::ImplItem<'_>) {
|
||||
self.observe_item(&impl_item.attrs, impl_item.hir_id);
|
||||
self.observe_item(&impl_item.attrs, impl_item.hir_id());
|
||||
}
|
||||
|
||||
fn visit_foreign_item(&mut self, foreign_item: &hir::ForeignItem<'_>) {
|
||||
|
|
|
@ -66,7 +66,7 @@ impl<'a, 'hir> ItemLikeVisitor<'hir> for OuterVisitor<'a, 'hir> {
|
|||
|
||||
fn visit_impl_item(&mut self, i: &'hir hir::ImplItem<'hir>) {
|
||||
let mut inner_visitor = self.new_inner_visitor(self.hir_map);
|
||||
inner_visitor.check(i.hir_id, |this| intravisit::walk_impl_item(this, i));
|
||||
inner_visitor.check(i.hir_id(), |this| intravisit::walk_impl_item(this, i));
|
||||
}
|
||||
|
||||
fn visit_foreign_item(&mut self, i: &'hir hir::ForeignItem<'hir>) {
|
||||
|
|
|
@ -192,7 +192,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
|
|||
}
|
||||
|
||||
fn visit_impl_item(&mut self, ii: &'v hir::ImplItem<'v>) {
|
||||
self.record("ImplItem", Id::Node(ii.hir_id), ii);
|
||||
self.record("ImplItem", Id::Node(ii.hir_id()), ii);
|
||||
hir_visit::walk_impl_item(self, ii)
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ impl ItemLikeVisitor<'v> for LanguageItemCollector<'tcx> {
|
|||
fn visit_impl_item(&mut self, impl_item: &hir::ImplItem<'_>) {
|
||||
self.check_for_lang(
|
||||
target_from_impl_item(self.tcx, impl_item),
|
||||
impl_item.hir_id,
|
||||
impl_item.hir_id(),
|
||||
impl_item.attrs,
|
||||
)
|
||||
}
|
||||
|
|
|
@ -43,8 +43,8 @@ fn method_might_be_inlined(
|
|||
impl_item: &hir::ImplItem<'_>,
|
||||
impl_src: LocalDefId,
|
||||
) -> bool {
|
||||
let codegen_fn_attrs = tcx.codegen_fn_attrs(impl_item.hir_id.owner.to_def_id());
|
||||
let generics = tcx.generics_of(tcx.hir().local_def_id(impl_item.hir_id));
|
||||
let codegen_fn_attrs = tcx.codegen_fn_attrs(impl_item.hir_id().owner.to_def_id());
|
||||
let generics = tcx.generics_of(impl_item.def_id);
|
||||
if codegen_fn_attrs.requests_inline() || generics.requires_monomorphization(tcx) {
|
||||
return true;
|
||||
}
|
||||
|
@ -356,8 +356,7 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, 'tcx
|
|||
if !self.access_levels.is_reachable(item.hir_id()) {
|
||||
// FIXME(#53488) remove `let`
|
||||
let tcx = self.tcx;
|
||||
self.worklist
|
||||
.extend(items.iter().map(|ii_ref| tcx.hir().local_def_id(ii_ref.id.hir_id)));
|
||||
self.worklist.extend(items.iter().map(|ii_ref| ii_ref.id.def_id));
|
||||
|
||||
let trait_def_id = match trait_ref.path.res {
|
||||
Res::Def(DefKind::Trait, def_id) => def_id,
|
||||
|
|
|
@ -405,7 +405,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
|
|||
let kind =
|
||||
if self.in_trait_impl { AnnotationKind::Prohibited } else { AnnotationKind::Required };
|
||||
self.annotate(
|
||||
ii.hir_id,
|
||||
ii.hir_id(),
|
||||
&ii.attrs,
|
||||
ii.span,
|
||||
kind,
|
||||
|
@ -576,9 +576,9 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> {
|
|||
}
|
||||
|
||||
fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem<'tcx>) {
|
||||
let impl_def_id = self.tcx.hir().local_def_id(self.tcx.hir().get_parent_item(ii.hir_id));
|
||||
let impl_def_id = self.tcx.hir().local_def_id(self.tcx.hir().get_parent_item(ii.hir_id()));
|
||||
if self.tcx.impl_trait_ref(impl_def_id).is_none() {
|
||||
self.check_missing_stability(ii.hir_id, ii.span);
|
||||
self.check_missing_stability(ii.hir_id(), ii.span);
|
||||
}
|
||||
intravisit::walk_impl_item(self, ii);
|
||||
}
|
||||
|
|
|
@ -663,7 +663,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
|
|||
hir::ItemKind::Impl(ref impl_) => {
|
||||
for impl_item_ref in impl_.items {
|
||||
if impl_.of_trait.is_some() || impl_item_ref.vis.node.is_pub() {
|
||||
self.update(impl_item_ref.id.hir_id, item_level);
|
||||
self.update(impl_item_ref.id.hir_id(), item_level);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -769,9 +769,9 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
|
|||
self.reach(item.hir_id(), item_level).generics().predicates().ty().trait_ref();
|
||||
|
||||
for impl_item_ref in impl_.items {
|
||||
let impl_item_level = self.get(impl_item_ref.id.hir_id);
|
||||
let impl_item_level = self.get(impl_item_ref.id.hir_id());
|
||||
if impl_item_level.is_some() {
|
||||
self.reach(impl_item_ref.id.hir_id, impl_item_level)
|
||||
self.reach(impl_item_ref.id.hir_id(), impl_item_level)
|
||||
.generics()
|
||||
.predicates()
|
||||
.ty();
|
||||
|
@ -1526,7 +1526,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
|
|||
let impl_item = self.tcx.hir().impl_item(impl_item_ref.id);
|
||||
match impl_item.kind {
|
||||
hir::ImplItemKind::Const(..) | hir::ImplItemKind::Fn(..) => {
|
||||
self.access_levels.is_reachable(impl_item_ref.id.hir_id)
|
||||
self.access_levels.is_reachable(impl_item_ref.id.hir_id())
|
||||
}
|
||||
hir::ImplItemKind::TyAlias(_) => false,
|
||||
}
|
||||
|
@ -1546,8 +1546,10 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
|
|||
let impl_item = self.tcx.hir().impl_item(impl_item_ref.id);
|
||||
match impl_item.kind {
|
||||
hir::ImplItemKind::Const(..) | hir::ImplItemKind::Fn(..)
|
||||
if self
|
||||
.item_is_public(&impl_item.hir_id, &impl_item.vis) =>
|
||||
if self.item_is_public(
|
||||
&impl_item.hir_id(),
|
||||
&impl_item.vis,
|
||||
) =>
|
||||
{
|
||||
intravisit::walk_impl_item(self, impl_item)
|
||||
}
|
||||
|
@ -1588,7 +1590,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
|
|||
// methods will be visible as `Public::foo`.
|
||||
let mut found_pub_static = false;
|
||||
for impl_item_ref in impl_.items {
|
||||
if self.item_is_public(&impl_item_ref.id.hir_id, &impl_item_ref.vis) {
|
||||
if self.item_is_public(&impl_item_ref.id.hir_id(), &impl_item_ref.vis) {
|
||||
let impl_item = self.tcx.hir().impl_item(impl_item_ref.id);
|
||||
match impl_item_ref.kind {
|
||||
AssocItemKind::Const => {
|
||||
|
@ -2002,16 +2004,12 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx>
|
|||
self.check(item.hir_id(), impl_vis).generics().predicates();
|
||||
for impl_item_ref in impl_.items {
|
||||
let impl_item_vis = if impl_.of_trait.is_none() {
|
||||
min(
|
||||
tcx.visibility(tcx.hir().local_def_id(impl_item_ref.id.hir_id)),
|
||||
impl_vis,
|
||||
tcx,
|
||||
)
|
||||
min(tcx.visibility(impl_item_ref.id.def_id), impl_vis, tcx)
|
||||
} else {
|
||||
impl_vis
|
||||
};
|
||||
self.check_assoc_item(
|
||||
impl_item_ref.id.hir_id,
|
||||
impl_item_ref.id.hir_id(),
|
||||
impl_item_ref.kind,
|
||||
impl_item_ref.defaultness,
|
||||
impl_item_vis,
|
||||
|
|
|
@ -634,7 +634,8 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
|||
let parent_id = self.tcx.hir().get_parent_node(hir_id);
|
||||
let parent_item_id =
|
||||
hir::ItemId { def_id: parent_id.expect_owner() };
|
||||
let parent_impl_id = hir::ImplItemId { hir_id: parent_id };
|
||||
let parent_impl_id =
|
||||
hir::ImplItemId { def_id: parent_id.expect_owner() };
|
||||
let parent_trait_id =
|
||||
hir::TraitItemId { def_id: parent_id.expect_owner() };
|
||||
let krate = self.tcx.hir().krate();
|
||||
|
@ -803,7 +804,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
|||
self.missing_named_lifetime_spots.push((&impl_item.generics).into());
|
||||
let tcx = self.tcx;
|
||||
self.visit_early_late(
|
||||
Some(tcx.hir().get_parent_item(impl_item.hir_id)),
|
||||
Some(tcx.hir().get_parent_item(impl_item.hir_id())),
|
||||
&sig.decl,
|
||||
&impl_item.generics,
|
||||
|this| intravisit::walk_impl_item(this, impl_item),
|
||||
|
@ -2128,7 +2129,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
|||
{
|
||||
impl_self = Some(self_ty);
|
||||
assoc_item_kind =
|
||||
items.iter().find(|ii| ii.id.hir_id == parent).map(|ii| ii.kind);
|
||||
items.iter().find(|ii| ii.id.hir_id() == parent).map(|ii| ii.kind);
|
||||
}
|
||||
Some(body)
|
||||
}
|
||||
|
|
|
@ -1073,7 +1073,7 @@ impl<'tcx> DumpVisitor<'tcx> {
|
|||
hir::ImplItemKind::Const(ref ty, body) => {
|
||||
let body = self.tcx.hir().body(body);
|
||||
self.process_assoc_const(
|
||||
impl_item.hir_id,
|
||||
impl_item.hir_id(),
|
||||
impl_item.ident,
|
||||
&ty,
|
||||
Some(&body.value),
|
||||
|
@ -1086,7 +1086,7 @@ impl<'tcx> DumpVisitor<'tcx> {
|
|||
self.process_method(
|
||||
sig,
|
||||
Some(body),
|
||||
impl_item.hir_id,
|
||||
impl_item.hir_id(),
|
||||
impl_item.ident,
|
||||
&impl_item.generics,
|
||||
&impl_item.vis,
|
||||
|
|
|
@ -358,7 +358,7 @@ impl<'tcx> SaveContext<'tcx> {
|
|||
parent: None,
|
||||
children: items
|
||||
.iter()
|
||||
.map(|i| id_from_hir_id(i.id.hir_id, self))
|
||||
.map(|i| id_from_def_id(i.id.def_id.to_def_id()))
|
||||
.collect(),
|
||||
docs: String::new(),
|
||||
sig: None,
|
||||
|
|
|
@ -69,7 +69,7 @@ impl hir::itemlikevisit::ItemLikeVisitor<'tcx> for SymbolNamesTest<'tcx> {
|
|||
}
|
||||
|
||||
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
|
||||
self.process_attrs(impl_item.hir_id);
|
||||
self.process_attrs(impl_item.hir_id());
|
||||
}
|
||||
|
||||
fn visit_foreign_item(&mut self, foreign_item: &'tcx hir::ForeignItem<'tcx>) {
|
||||
|
|
|
@ -105,7 +105,7 @@ fn associated_item_from_impl_item_ref(
|
|||
parent_def_id: LocalDefId,
|
||||
impl_item_ref: &hir::ImplItemRef<'_>,
|
||||
) -> ty::AssocItem {
|
||||
let def_id = tcx.hir().local_def_id(impl_item_ref.id.hir_id);
|
||||
let def_id = impl_item_ref.id.def_id;
|
||||
let (kind, has_self) = match impl_item_ref.kind {
|
||||
hir::AssocItemKind::Const => (ty::AssocKind::Const, false),
|
||||
hir::AssocItemKind::Fn { has_self } => (ty::AssocKind::Fn, has_self),
|
||||
|
@ -130,7 +130,9 @@ fn associated_item(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AssocItem {
|
|||
let parent_item = tcx.hir().expect_item(parent_id);
|
||||
match parent_item.kind {
|
||||
hir::ItemKind::Impl(ref impl_) => {
|
||||
if let Some(impl_item_ref) = impl_.items.iter().find(|i| i.id.hir_id == id) {
|
||||
if let Some(impl_item_ref) =
|
||||
impl_.items.iter().find(|i| i.id.def_id.to_def_id() == def_id)
|
||||
{
|
||||
let assoc_item =
|
||||
associated_item_from_impl_item_ref(tcx, parent_def_id, impl_item_ref);
|
||||
debug_assert_eq!(assoc_item.def_id, def_id);
|
||||
|
@ -201,11 +203,7 @@ fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: DefId) -> &[DefId] {
|
|||
trait_item_refs.iter().map(|trait_item_ref| trait_item_ref.id.def_id.to_def_id()),
|
||||
),
|
||||
hir::ItemKind::Impl(ref impl_) => tcx.arena.alloc_from_iter(
|
||||
impl_
|
||||
.items
|
||||
.iter()
|
||||
.map(|impl_item_ref| impl_item_ref.id)
|
||||
.map(|id| tcx.hir().local_def_id(id.hir_id).to_def_id()),
|
||||
impl_.items.iter().map(|impl_item_ref| impl_item_ref.id.def_id.to_def_id()),
|
||||
),
|
||||
hir::ItemKind::TraitAlias(..) => &[],
|
||||
_ => span_bug!(item.span, "associated_item_def_ids: not impl or trait"),
|
||||
|
|
|
@ -928,7 +928,7 @@ pub(super) fn check_impl_items_against_trait<'tcx>(
|
|||
// Check existing impl methods to see if they are both present in trait
|
||||
// and compatible with trait signature
|
||||
for impl_item in impl_items {
|
||||
let ty_impl_item = tcx.associated_item(tcx.hir().local_def_id(impl_item.hir_id));
|
||||
let ty_impl_item = tcx.associated_item(impl_item.def_id);
|
||||
|
||||
let mut items =
|
||||
associated_items.filter_by_name(tcx, ty_impl_item.ident, impl_trait_ref.def_id);
|
||||
|
|
|
@ -826,8 +826,8 @@ fn compare_synthetic_generics<'tcx>(
|
|||
let trait_m = trait_m.def_id.as_local()?;
|
||||
let trait_m = tcx.hir().trait_item(hir::TraitItemId { def_id: trait_m });
|
||||
|
||||
let impl_m = tcx.hir().local_def_id_to_hir_id(impl_m.def_id.as_local()?);
|
||||
let impl_m = tcx.hir().impl_item(hir::ImplItemId { hir_id: impl_m });
|
||||
let impl_m = impl_m.def_id.as_local()?;
|
||||
let impl_m = tcx.hir().impl_item(hir::ImplItemId { def_id: impl_m });
|
||||
|
||||
// in case there are no generics, take the spot between the function name
|
||||
// and the opening paren of the argument list
|
||||
|
@ -860,8 +860,8 @@ fn compare_synthetic_generics<'tcx>(
|
|||
(None, Some(hir::SyntheticTyParamKind::ImplTrait)) => {
|
||||
err.span_label(impl_span, "expected `impl Trait`, found generic parameter");
|
||||
(|| {
|
||||
let impl_m = tcx.hir().local_def_id_to_hir_id(impl_m.def_id.as_local()?);
|
||||
let impl_m = tcx.hir().impl_item(hir::ImplItemId { hir_id: impl_m });
|
||||
let impl_m = impl_m.def_id.as_local()?;
|
||||
let impl_m = tcx.hir().impl_item(hir::ImplItemId { def_id: impl_m });
|
||||
let input_tys = match impl_m.kind {
|
||||
hir::ImplItemKind::Fn(ref sig, _) => sig.decl.inputs,
|
||||
_ => unreachable!(),
|
||||
|
|
|
@ -271,7 +271,7 @@ pub fn check_impl_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
|||
_ => None,
|
||||
};
|
||||
|
||||
check_associated_item(tcx, impl_item.hir_id, impl_item.span, method_sig);
|
||||
check_associated_item(tcx, impl_item.hir_id(), impl_item.span, method_sig);
|
||||
}
|
||||
|
||||
fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) {
|
||||
|
@ -1360,8 +1360,7 @@ impl Visitor<'tcx> for CheckTypeWellFormedVisitor<'tcx> {
|
|||
|
||||
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
|
||||
debug!("visit_impl_item: {:?}", impl_item);
|
||||
let def_id = self.tcx.hir().local_def_id(impl_item.hir_id);
|
||||
self.tcx.ensure().check_impl_item_well_formed(def_id);
|
||||
self.tcx.ensure().check_impl_item_well_formed(impl_item.def_id);
|
||||
hir_visit::walk_impl_item(self, impl_item);
|
||||
}
|
||||
|
||||
|
|
|
@ -286,7 +286,7 @@ impl Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
|
|||
}
|
||||
|
||||
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
|
||||
convert_impl_item(self.tcx, impl_item.hir_id);
|
||||
convert_impl_item(self.tcx, impl_item.impl_item_id());
|
||||
intravisit::walk_impl_item(self, impl_item);
|
||||
}
|
||||
}
|
||||
|
@ -849,12 +849,12 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
|
|||
tcx.ensure().predicates_of(trait_item_id.def_id);
|
||||
}
|
||||
|
||||
fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::HirId) {
|
||||
let def_id = tcx.hir().local_def_id(impl_item_id);
|
||||
fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) {
|
||||
let def_id = impl_item_id.def_id;
|
||||
tcx.ensure().generics_of(def_id);
|
||||
tcx.ensure().type_of(def_id);
|
||||
tcx.ensure().predicates_of(def_id);
|
||||
let impl_item = tcx.hir().expect_impl_item(impl_item_id);
|
||||
let impl_item = tcx.hir().impl_item(impl_item_id);
|
||||
match impl_item.kind {
|
||||
hir::ImplItemKind::Fn(..) => {
|
||||
tcx.ensure().fn_sig(def_id);
|
||||
|
|
|
@ -590,10 +590,9 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
|
|||
}
|
||||
fn visit_impl_item(&mut self, it: &'tcx ImplItem<'tcx>) {
|
||||
debug!("find_existential_constraints: visiting {:?}", it);
|
||||
let def_id = self.tcx.hir().local_def_id(it.hir_id);
|
||||
// The opaque type itself or its children are not within its reveal scope.
|
||||
if def_id.to_def_id() != self.def_id {
|
||||
self.check(def_id);
|
||||
if it.def_id.to_def_id() != self.def_id {
|
||||
self.check(it.def_id);
|
||||
intravisit::walk_impl_item(self, it);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -130,7 +130,7 @@ fn enforce_impl_params_are_constrained(
|
|||
// Disallow unconstrained lifetimes, but only if they appear in assoc types.
|
||||
let lifetimes_in_associated_types: FxHashSet<_> = impl_item_refs
|
||||
.iter()
|
||||
.map(|item_ref| tcx.hir().local_def_id(item_ref.id.hir_id))
|
||||
.map(|item_ref| item_ref.id.def_id)
|
||||
.flat_map(|def_id| {
|
||||
let item = tcx.associated_item(def_id);
|
||||
match item.kind {
|
||||
|
|
|
@ -104,7 +104,7 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for ConstraintContext<'a, 'tcx> {
|
|||
|
||||
fn visit_impl_item(&mut self, impl_item: &hir::ImplItem<'_>) {
|
||||
if let hir::ImplItemKind::Fn(..) = impl_item.kind {
|
||||
self.visit_node_helper(impl_item.hir_id);
|
||||
self.visit_node_helper(impl_item.hir_id());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -165,7 +165,7 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for TermsContext<'a, 'tcx> {
|
|||
|
||||
fn visit_impl_item(&mut self, impl_item: &hir::ImplItem<'_>) {
|
||||
if let hir::ImplItemKind::Fn(..) = impl_item.kind {
|
||||
self.add_inferreds_for_item(impl_item.hir_id);
|
||||
self.add_inferreds_for_item(impl_item.hir_id());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue