mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 02:03:53 +00:00
Only store a LocalDefId in hir::ImplItem.
This commit is contained in:
parent
a871a0f111
commit
786a80e9ea
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1085,7 +1085,7 @@ impl Clean<Item> for hir::TraitItem<'_> {
|
||||
|
||||
impl Clean<Item> for hir::ImplItem<'_> {
|
||||
fn clean(&self, cx: &DocContext<'_>) -> Item {
|
||||
let local_did = cx.tcx.hir().local_def_id(self.hir_id).to_def_id();
|
||||
let local_did = self.def_id.to_def_id();
|
||||
cx.with_param_env(local_did, || {
|
||||
let inner = match self.kind {
|
||||
hir::ImplItemKind::Const(ref ty, expr) => {
|
||||
@ -1116,7 +1116,7 @@ impl Clean<Item> for hir::ImplItem<'_> {
|
||||
|
||||
let what_rustc_thinks =
|
||||
Item::from_def_id_and_parts(local_did, Some(self.ident.name), inner, cx);
|
||||
let parent_item = cx.tcx.hir().expect_item(cx.tcx.hir().get_parent_item(self.hir_id));
|
||||
let parent_item = cx.tcx.hir().expect_item(cx.tcx.hir().get_parent_item(self.hir_id()));
|
||||
if let hir::ItemKind::Impl(impl_) = &parent_item.kind {
|
||||
if impl_.of_trait.is_some() {
|
||||
// Trait impl items always inherit the impl's visibility --
|
||||
|
@ -1068,9 +1068,15 @@ impl<'a, 'hir, 'tcx> intravisit::Visitor<'hir> for HirCollector<'a, 'hir, 'tcx>
|
||||
}
|
||||
|
||||
fn visit_impl_item(&mut self, item: &'hir hir::ImplItem<'_>) {
|
||||
self.visit_testable(item.ident.to_string(), &item.attrs, item.hir_id, item.span, |this| {
|
||||
self.visit_testable(
|
||||
item.ident.to_string(),
|
||||
&item.attrs,
|
||||
item.hir_id(),
|
||||
item.span,
|
||||
|this| {
|
||||
intravisit::walk_impl_item(this, item);
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
fn visit_foreign_item(&mut self, item: &'hir hir::ForeignItem<'_>) {
|
||||
|
@ -258,14 +258,13 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
|
||||
}
|
||||
if let hir::ImplItemKind::Fn(ref sig, body_id) = item.kind {
|
||||
let body = cx.tcx.hir().body(body_id);
|
||||
let impl_item_def_id = cx.tcx.hir().local_def_id(item.hir_id);
|
||||
let mut fpu = FindPanicUnwrap {
|
||||
cx,
|
||||
typeck_results: cx.tcx.typeck(impl_item_def_id),
|
||||
typeck_results: cx.tcx.typeck(item.def_id),
|
||||
panic_span: None,
|
||||
};
|
||||
fpu.visit_expr(&body.value);
|
||||
lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers, Some(body_id), fpu.panic_span);
|
||||
lint_for_missing_headers(cx, item.hir_id(), item.span, sig, headers, Some(body_id), fpu.panic_span);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -116,10 +116,9 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[h
|
||||
then {
|
||||
// check the body for `begin_panic` or `unwrap`
|
||||
let body = cx.tcx.hir().body(body_id);
|
||||
let impl_item_def_id = cx.tcx.hir().local_def_id(impl_item.id.hir_id);
|
||||
let mut fpu = FindPanicUnwrap {
|
||||
lcx: cx,
|
||||
typeck_results: cx.tcx.typeck(impl_item_def_id),
|
||||
typeck_results: cx.tcx.typeck(impl_item.id.def_id),
|
||||
result: Vec::new(),
|
||||
};
|
||||
fpu.visit_expr(&body.value);
|
||||
|
@ -308,24 +308,24 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
|
||||
|
||||
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) {
|
||||
if let hir::ImplItemKind::Fn(ref sig, ref body_id) = item.kind {
|
||||
let is_public = cx.access_levels.is_exported(item.hir_id);
|
||||
let is_public = cx.access_levels.is_exported(item.hir_id());
|
||||
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
|
||||
if is_public && trait_ref_of_method(cx, item.hir_id).is_none() {
|
||||
if is_public && trait_ref_of_method(cx, item.hir_id()).is_none() {
|
||||
check_result_unit_err(cx, &sig.decl, item.span, fn_header_span);
|
||||
}
|
||||
let attr = must_use_attr(&item.attrs);
|
||||
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(), &item.attrs)
|
||||
&& trait_ref_of_method(cx, item.hir_id).is_none()
|
||||
&& trait_ref_of_method(cx, item.hir_id()).is_none()
|
||||
{
|
||||
check_must_use_candidate(
|
||||
cx,
|
||||
&sig.decl,
|
||||
cx.tcx.hir().body(*body_id),
|
||||
item.span,
|
||||
item.hir_id,
|
||||
item.hir_id(),
|
||||
item.span.with_hi(sig.decl.output.span().hi()),
|
||||
"this method could have a `#[must_use]` attribute",
|
||||
);
|
||||
|
@ -108,10 +108,10 @@ impl<'tcx> LateLintPass<'tcx> for InherentToString {
|
||||
if decl.inputs.len() == 1;
|
||||
|
||||
// Check if return type is String
|
||||
if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id), sym::string_type);
|
||||
if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::string_type);
|
||||
|
||||
// Filters instances of to_string which are required by a trait
|
||||
if trait_ref_of_method(cx, impl_item.hir_id).is_none();
|
||||
if trait_ref_of_method(cx, impl_item.hir_id()).is_none();
|
||||
|
||||
then {
|
||||
show_lint(cx, impl_item);
|
||||
@ -124,8 +124,7 @@ fn show_lint(cx: &LateContext<'_>, item: &ImplItem<'_>) {
|
||||
let display_trait_id = get_trait_def_id(cx, &paths::DISPLAY_TRAIT).expect("Failed to get trait ID of `Display`!");
|
||||
|
||||
// Get the real type of 'self'
|
||||
let fn_def_id = cx.tcx.hir().local_def_id(item.hir_id);
|
||||
let self_type = cx.tcx.fn_sig(fn_def_id).input(0);
|
||||
let self_type = cx.tcx.fn_sig(item.def_id).input(0);
|
||||
let self_type = self_type.skip_binder().peel_refs();
|
||||
|
||||
// Emit either a warning or an error
|
||||
|
@ -206,17 +206,14 @@ fn check_impl_items(cx: &LateContext<'_>, item: &Item<'_>, impl_items: &[ImplIte
|
||||
fn is_named_self(cx: &LateContext<'_>, item: &ImplItemRef<'_>, name: &str) -> bool {
|
||||
item.ident.name.as_str() == name
|
||||
&& if let AssocItemKind::Fn { has_self } = item.kind {
|
||||
has_self && {
|
||||
let did = cx.tcx.hir().local_def_id(item.id.hir_id);
|
||||
cx.tcx.fn_sig(did).inputs().skip_binder().len() == 1
|
||||
}
|
||||
has_self && cx.tcx.fn_sig(item.id.def_id).inputs().skip_binder().len() == 1
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
let is_empty = if let Some(is_empty) = impl_items.iter().find(|i| is_named_self(cx, i, "is_empty")) {
|
||||
if cx.access_levels.is_exported(is_empty.id.hir_id) {
|
||||
if cx.access_levels.is_exported(is_empty.id.hir_id()) {
|
||||
return;
|
||||
}
|
||||
"a private"
|
||||
@ -225,7 +222,7 @@ fn check_impl_items(cx: &LateContext<'_>, item: &Item<'_>, impl_items: &[ImplIte
|
||||
};
|
||||
|
||||
if let Some(i) = impl_items.iter().find(|i| is_named_self(cx, i, "len")) {
|
||||
if cx.access_levels.is_exported(i.id.hir_id) {
|
||||
if cx.access_levels.is_exported(i.id.hir_id()) {
|
||||
let ty = cx.tcx.type_of(item.def_id);
|
||||
|
||||
span_lint(
|
||||
|
@ -87,7 +87,7 @@ impl<'tcx> LateLintPass<'tcx> for Lifetimes {
|
||||
|
||||
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) {
|
||||
if let ImplItemKind::Fn(ref sig, id) = item.kind {
|
||||
let report_extra_lifetimes = trait_ref_of_method(cx, item.hir_id).is_none();
|
||||
let report_extra_lifetimes = trait_ref_of_method(cx, item.hir_id()).is_none();
|
||||
check_fn_inner(
|
||||
cx,
|
||||
&sig.decl,
|
||||
|
@ -1685,7 +1685,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
|
||||
return;
|
||||
}
|
||||
let name = impl_item.ident.name.as_str();
|
||||
let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id);
|
||||
let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id());
|
||||
let item = cx.tcx.hir().expect_item(parent);
|
||||
let self_ty = cx.tcx.type_of(item.def_id);
|
||||
|
||||
@ -1698,8 +1698,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
|
||||
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();
|
||||
|
||||
let method_def_id = cx.tcx.hir().local_def_id(impl_item.hir_id);
|
||||
let method_sig = cx.tcx.fn_sig(method_def_id);
|
||||
let method_sig = cx.tcx.fn_sig(impl_item.def_id);
|
||||
let method_sig = cx.tcx.erase_late_bound_regions(method_sig);
|
||||
|
||||
let first_arg_ty = &method_sig.inputs().iter().next();
|
||||
@ -1708,7 +1707,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
|
||||
if let Some(first_arg_ty) = first_arg_ty;
|
||||
|
||||
then {
|
||||
if cx.access_levels.is_exported(impl_item.hir_id) {
|
||||
if cx.access_levels.is_exported(impl_item.hir_id()) {
|
||||
// check missing trait implementations
|
||||
for method_config in &TRAIT_METHODS {
|
||||
if name == method_config.method_name &&
|
||||
@ -1750,7 +1749,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
|
||||
}
|
||||
|
||||
if let hir::ImplItemKind::Fn(_, _) = impl_item.kind {
|
||||
let ret_ty = return_ty(cx, impl_item.hir_id);
|
||||
let ret_ty = return_ty(cx, impl_item.hir_id());
|
||||
|
||||
// walk the return type and check for Self (this does not check associated types)
|
||||
if contains_ty(ret_ty, self_ty) {
|
||||
|
@ -171,8 +171,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
|
||||
|
||||
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) {
|
||||
// If the method is an impl for a trait, don't doc.
|
||||
let def_id = cx.tcx.hir().local_def_id(impl_item.hir_id);
|
||||
match cx.tcx.associated_item(def_id).container {
|
||||
match cx.tcx.associated_item(impl_item.def_id).container {
|
||||
ty::TraitContainer(_) => return,
|
||||
ty::ImplContainer(cid) => {
|
||||
if cx.tcx.impl_trait_ref(cid).is_some() {
|
||||
@ -181,7 +180,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
|
||||
},
|
||||
}
|
||||
|
||||
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, &impl_item.attrs, impl_item.span, article, desc);
|
||||
}
|
||||
|
||||
|
@ -138,7 +138,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
|
||||
}
|
||||
|
||||
// If the item being implemented is not exported, then we don't need #[inline]
|
||||
if !cx.access_levels.is_exported(impl_item.hir_id) {
|
||||
if !cx.access_levels.is_exported(impl_item.hir_id()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -147,14 +147,13 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
|
||||
hir::ImplItemKind::Const(..) | hir::ImplItemKind::TyAlias(_) => return,
|
||||
};
|
||||
|
||||
let def_id = cx.tcx.hir().local_def_id(impl_item.hir_id);
|
||||
let trait_def_id = match cx.tcx.associated_item(def_id).container {
|
||||
let trait_def_id = match cx.tcx.associated_item(impl_item.def_id).container {
|
||||
TraitContainer(cid) => Some(cid),
|
||||
ImplContainer(cid) => cx.tcx.impl_trait_ref(cid).map(|t| t.def_id),
|
||||
};
|
||||
|
||||
if let Some(trait_def_id) = trait_def_id {
|
||||
if trait_def_id.is_local() && !cx.access_levels.is_exported(impl_item.hir_id) {
|
||||
if trait_def_id.is_local() && !cx.access_levels.is_exported(impl_item.hir_id()) {
|
||||
// If a trait is being implemented for an item, and the
|
||||
// trait is not exported, we don't need #[inline]
|
||||
return;
|
||||
|
@ -63,8 +63,8 @@ impl<'tcx> LateLintPass<'tcx> for MutableKeyType {
|
||||
|
||||
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'tcx>) {
|
||||
if let hir::ImplItemKind::Fn(ref sig, ..) = item.kind {
|
||||
if trait_ref_of_method(cx, item.hir_id).is_none() {
|
||||
check_sig(cx, item.hir_id, &sig.decl);
|
||||
if trait_ref_of_method(cx, item.hir_id()).is_none() {
|
||||
check_sig(cx, item.hir_id(), &sig.decl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault {
|
||||
}
|
||||
if let hir::ImplItemKind::Fn(ref sig, _) = impl_item.kind {
|
||||
let name = impl_item.ident.name;
|
||||
let id = impl_item.hir_id;
|
||||
let id = impl_item.hir_id();
|
||||
if sig.header.constness == hir::Constness::Const {
|
||||
// can't be implemented by default
|
||||
return;
|
||||
|
@ -271,7 +271,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst {
|
||||
|
||||
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx ImplItem<'_>) {
|
||||
if let ImplItemKind::Const(hir_ty, body_id) = &impl_item.kind {
|
||||
let item_hir_id = cx.tcx.hir().get_parent_node(impl_item.hir_id);
|
||||
let item_hir_id = cx.tcx.hir().get_parent_node(impl_item.hir_id());
|
||||
let item = cx.tcx.hir().expect_item(item_hir_id);
|
||||
|
||||
match &item.kind {
|
||||
|
@ -44,7 +44,7 @@ impl<'tcx> LateLintPass<'tcx> for PartialEqNeImpl {
|
||||
span_lint_hir(
|
||||
cx,
|
||||
PARTIALEQ_NE_IMPL,
|
||||
impl_item.id.hir_id,
|
||||
impl_item.id.hir_id(),
|
||||
impl_item.span,
|
||||
"re-implementing `PartialEq::ne` is unnecessary",
|
||||
);
|
||||
|
@ -130,13 +130,13 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {
|
||||
|
||||
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) {
|
||||
if let ImplItemKind::Fn(ref sig, body_id) = item.kind {
|
||||
let parent_item = cx.tcx.hir().get_parent_item(item.hir_id);
|
||||
let parent_item = cx.tcx.hir().get_parent_item(item.hir_id());
|
||||
if let Some(Node::Item(it)) = cx.tcx.hir().find(parent_item) {
|
||||
if let ItemKind::Impl(Impl { of_trait: Some(_), .. }) = it.kind {
|
||||
return; // ignore trait impls
|
||||
}
|
||||
}
|
||||
check_fn(cx, &sig.decl, item.hir_id, Some(body_id));
|
||||
check_fn(cx, &sig.decl, item.hir_id(), Some(body_id));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,10 +44,9 @@ impl<'tcx> LateLintPass<'tcx> for UnusedSelf {
|
||||
if impl_item.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id);
|
||||
let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id());
|
||||
let parent_item = cx.tcx.hir().expect_item(parent);
|
||||
let def_id = cx.tcx.hir().local_def_id(impl_item.hir_id);
|
||||
let assoc_item = cx.tcx.associated_item(def_id);
|
||||
let assoc_item = cx.tcx.associated_item(impl_item.def_id);
|
||||
if_chain! {
|
||||
if let ItemKind::Impl(Impl { of_trait: None, .. }) = parent_item.kind;
|
||||
if assoc_item.fn_has_self_parameter;
|
||||
|
@ -57,8 +57,8 @@ impl<'tcx> LateLintPass<'tcx> for UnwrapInResult {
|
||||
// first check if it's a method or function
|
||||
if let hir::ImplItemKind::Fn(ref _signature, _) = impl_item.kind;
|
||||
// checking if its return type is `result` or `option`
|
||||
if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id), sym::result_type)
|
||||
|| is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id), sym::option_type);
|
||||
if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::result_type)
|
||||
|| is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::option_type);
|
||||
then {
|
||||
lint_impl_body(cx, impl_item.span, impl_item);
|
||||
}
|
||||
@ -114,10 +114,9 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_item: &'tc
|
||||
if let ImplItemKind::Fn(_, body_id) = impl_item.kind;
|
||||
then {
|
||||
let body = cx.tcx.hir().body(body_id);
|
||||
let impl_item_def_id = cx.tcx.hir().local_def_id(impl_item.hir_id);
|
||||
let mut fpu = FindExpectUnwrap {
|
||||
lcx: cx,
|
||||
typeck_results: cx.tcx.typeck(impl_item_def_id),
|
||||
typeck_results: cx.tcx.typeck(impl_item.def_id),
|
||||
result: Vec::new(),
|
||||
};
|
||||
fpu.visit_expr(&body.value);
|
||||
|
Loading…
Reference in New Issue
Block a user