Only store a LocalDefId in hir::TraitItem.

This commit is contained in:
Camille GILLOT 2021-01-30 20:46:50 +01:00
parent 2dc65397ee
commit fc9bc33bba
9 changed files with 15 additions and 19 deletions

View file

@ -246,7 +246,7 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
let headers = check_attrs(cx, &self.valid_idents, &item.attrs);
if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind {
if !in_external_macro(cx.tcx.sess, item.span) {
lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers, None, None);
lint_for_missing_headers(cx, item.hir_id(), item.span, sig, headers, None, None);
}
}
}

View file

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

View file

@ -339,7 +339,7 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
if sig.header.abi == Abi::Rust {
self.check_arg_number(cx, &sig.decl, item.span.with_hi(sig.decl.output.span().hi()));
}
let is_public = cx.access_levels.is_exported(item.hir_id);
let is_public = cx.access_levels.is_exported(item.hir_id());
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
if is_public {
check_result_unit_err(cx, &sig.decl, item.span, fn_header_span);
@ -347,11 +347,11 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
let attr = must_use_attr(&item.attrs);
if let Some(attr) = attr {
check_needless_must_use(cx, &sig.decl, item.hir_id, item.span, fn_header_span, attr);
check_needless_must_use(cx, &sig.decl, item.hir_id(), item.span, fn_header_span, attr);
}
if let hir::TraitFn::Provided(eid) = *eid {
let body = cx.tcx.hir().body(eid);
Self::check_raw_ptr(cx, sig.header.unsafety, &sig.decl, body, item.hir_id);
Self::check_raw_ptr(cx, sig.header.unsafety, &sig.decl, body, item.hir_id());
if attr.is_none() && is_public && !is_proc_macro(cx.sess(), &item.attrs) {
check_must_use_candidate(
@ -359,7 +359,7 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
&sig.decl,
body,
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",
);

View file

@ -159,10 +159,7 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, trait_items
fn is_named_self(cx: &LateContext<'_>, item: &TraitItemRef, name: &str) -> bool {
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
}

View file

@ -1791,7 +1791,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
if let Some(first_arg_ty) = sig.decl.inputs.iter().next();
let first_arg_span = first_arg_ty.span;
let first_arg_ty = hir_ty_to_ty(cx.tcx, first_arg_ty);
let self_ty = TraitRef::identity(cx.tcx, item.hir_id.owner.to_def_id()).self_ty();
let self_ty = TraitRef::identity(cx.tcx, item.def_id.to_def_id()).self_ty();
then {
lint_wrong_self_convention(cx, &item.ident.name.as_str(), false, self_ty, first_arg_ty, first_arg_span);
@ -1801,8 +1801,8 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
if_chain! {
if item.ident.name == sym::new;
if let TraitItemKind::Fn(_, _) = item.kind;
let ret_ty = return_ty(cx, item.hir_id);
let self_ty = TraitRef::identity(cx.tcx, item.hir_id.owner.to_def_id()).self_ty();
let ret_ty = return_ty(cx, item.hir_id());
let self_ty = TraitRef::identity(cx.tcx, item.def_id.to_def_id()).self_ty();
if !contains_ty(ret_ty, self_ty);
then {

View file

@ -164,8 +164,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
}
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, trait_item: &'tcx hir::TraitItem<'_>) {
let def_id = cx.tcx.hir().local_def_id(trait_item.hir_id);
let (article, desc) = cx.tcx.article_and_description(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.attrs, trait_item.span, article, desc);
}

View file

@ -71,7 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for MutableKeyType {
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'tcx>) {
if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind {
check_sig(cx, item.hir_id, &sig.decl);
check_sig(cx, item.hir_id(), &sig.decl);
}
}

View file

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

View file

@ -147,7 +147,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {
} else {
None
};
check_fn(cx, &sig.decl, item.hir_id, body_id);
check_fn(cx, &sig.decl, item.hir_id(), body_id);
}
}