Skip to content

Commit 2dc6539

Browse files
committed
Only store a LocalDefId in hir::Item.
Items are guaranteed to be HIR owner.
1 parent 5b68fc1 commit 2dc6539

22 files changed

+41
-56
lines changed

clippy_lints/src/copy_iterator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl<'tcx> LateLintPass<'tcx> for CopyIterator {
3838
..
3939
}) = item.kind
4040
{
41-
let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id(item.hir_id));
41+
let ty = cx.tcx.type_of(item.def_id);
4242

4343
if is_copy(cx, ty) && match_path(&trait_ref.path, &paths::ITERATOR) {
4444
span_lint_and_note(

clippy_lints/src/derive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ impl<'tcx> LateLintPass<'tcx> for Derive {
169169
..
170170
}) = item.kind
171171
{
172-
let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id(item.hir_id));
172+
let ty = cx.tcx.type_of(item.def_id);
173173
let is_automatically_derived = is_automatically_derived(&*item.attrs);
174174

175175
check_hash_peq(cx, item.span, trait_ref, ty, is_automatically_derived);

clippy_lints/src/doc.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,18 +216,17 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
216216
let headers = check_attrs(cx, &self.valid_idents, &item.attrs);
217217
match item.kind {
218218
hir::ItemKind::Fn(ref sig, _, body_id) => {
219-
if !(is_entrypoint_fn(cx, cx.tcx.hir().local_def_id(item.hir_id).to_def_id())
219+
if !(is_entrypoint_fn(cx, item.def_id.to_def_id())
220220
|| in_external_macro(cx.tcx.sess, item.span))
221221
{
222222
let body = cx.tcx.hir().body(body_id);
223-
let impl_item_def_id = cx.tcx.hir().local_def_id(item.hir_id);
224223
let mut fpu = FindPanicUnwrap {
225224
cx,
226-
typeck_results: cx.tcx.typeck(impl_item_def_id),
225+
typeck_results: cx.tcx.typeck(item.def_id),
227226
panic_span: None,
228227
};
229228
fpu.visit_expr(&body.value);
230-
lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers, Some(body_id), fpu.panic_span);
229+
lint_for_missing_headers(cx, item.hir_id(), item.span, sig, headers, Some(body_id), fpu.panic_span);
231230
}
232231
},
233232
hir::ItemKind::Impl(ref impl_) => {

clippy_lints/src/empty_enum.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ impl<'tcx> LateLintPass<'tcx> for EmptyEnum {
4949
return;
5050
}
5151

52-
let did = cx.tcx.hir().local_def_id(item.hir_id);
5352
if let ItemKind::Enum(..) = item.kind {
54-
let ty = cx.tcx.type_of(did);
53+
let ty = cx.tcx.type_of(item.def_id);
5554
let adt = ty.ty_adt_def().expect("already checked whether this is an enum");
5655
if adt.variants.is_empty() {
5756
span_lint_and_help(

clippy_lints/src/exhaustive_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl LateLintPass<'_> for ExhaustiveItems {
7272
fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
7373
if_chain! {
7474
if let ItemKind::Enum(..) | ItemKind::Struct(..) = item.kind;
75-
if cx.access_levels.is_exported(item.hir_id);
75+
if cx.access_levels.is_exported(item.hir_id());
7676
if !item.attrs.iter().any(|a| a.has_name(sym::non_exhaustive));
7777
then {
7878
let (lint, msg) = if let ItemKind::Struct(ref v, ..) = item.kind {

clippy_lints/src/fallible_impl_from.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,9 @@ declare_lint_pass!(FallibleImplFrom => [FALLIBLE_IMPL_FROM]);
5252
impl<'tcx> LateLintPass<'tcx> for FallibleImplFrom {
5353
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
5454
// check for `impl From<???> for ..`
55-
let impl_def_id = cx.tcx.hir().local_def_id(item.hir_id);
5655
if_chain! {
5756
if let hir::ItemKind::Impl(impl_) = &item.kind;
58-
if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(impl_def_id);
57+
if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(item.def_id);
5958
if cx.tcx.is_diagnostic_item(sym::from_trait, impl_trait_ref.def_id);
6059
then {
6160
lint_impl_body(cx, item.span, impl_.items);

clippy_lints/src/from_over_into.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,9 @@ impl LateLintPass<'_> for FromOverInto {
6060
return;
6161
}
6262

63-
let impl_def_id = cx.tcx.hir().local_def_id(item.hir_id);
6463
if_chain! {
6564
if let hir::ItemKind::Impl{ .. } = &item.kind;
66-
if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(impl_def_id);
65+
if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(item.def_id);
6766
if match_def_path(cx, impl_trait_ref.def_id, &INTO);
6867

6968
then {

clippy_lints/src/functions.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,13 +283,13 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
283283
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
284284
let attr = must_use_attr(&item.attrs);
285285
if let hir::ItemKind::Fn(ref sig, ref _generics, ref body_id) = item.kind {
286-
let is_public = cx.access_levels.is_exported(item.hir_id);
286+
let is_public = cx.access_levels.is_exported(item.hir_id());
287287
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
288288
if is_public {
289289
check_result_unit_err(cx, &sig.decl, item.span, fn_header_span);
290290
}
291291
if let Some(attr) = attr {
292-
check_needless_must_use(cx, &sig.decl, item.hir_id, item.span, fn_header_span, attr);
292+
check_needless_must_use(cx, &sig.decl, item.hir_id(), item.span, fn_header_span, attr);
293293
return;
294294
}
295295
if is_public && !is_proc_macro(cx.sess(), &item.attrs) && attr_by_name(&item.attrs, "no_mangle").is_none() {
@@ -298,7 +298,7 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
298298
&sig.decl,
299299
cx.tcx.hir().body(*body_id),
300300
item.span,
301-
item.hir_id,
301+
item.hir_id(),
302302
item.span.with_hi(sig.decl.output.span().hi()),
303303
"this function could have a `#[must_use]` attribute",
304304
);

clippy_lints/src/inherent_impl.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,15 @@ impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl {
5959
// but filter out implementations that have generic params (type or lifetime)
6060
// or are derived from a macro
6161
if !in_macro(item.span) && generics.params.is_empty() {
62-
self.impls.insert(item.hir_id.owner.to_def_id(), item.span);
62+
self.impls.insert(item.def_id.to_def_id(), item.span);
6363
}
6464
}
6565
}
6666

6767
fn check_crate_post(&mut self, cx: &LateContext<'tcx>, krate: &'tcx Crate<'_>) {
68-
if let Some(item) = krate.items.values().next() {
68+
if !krate.items.is_empty() {
6969
// Retrieve all inherent implementations from the crate, grouped by type
70-
for impls in cx
71-
.tcx
72-
.crate_inherent_impls(item.hir_id.owner.to_def_id().krate)
73-
.inherent_impls
74-
.values()
75-
{
70+
for impls in cx.tcx.crate_inherent_impls(def_id::LOCAL_CRATE).inherent_impls.values() {
7671
// Filter out implementations that have generic params (type or lifetime)
7772
let mut impl_spans = impls.iter().filter_map(|impl_def| self.impls.get(impl_def));
7873
if let Some(initial_span) = impl_spans.next() {

clippy_lints/src/large_enum_variant.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,8 @@ impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant {
6262
if in_external_macro(cx.tcx.sess, item.span) {
6363
return;
6464
}
65-
let did = cx.tcx.hir().local_def_id(item.hir_id);
6665
if let ItemKind::Enum(ref def, _) = item.kind {
67-
let ty = cx.tcx.type_of(did);
66+
let ty = cx.tcx.type_of(item.def_id);
6867
let adt = ty.ty_adt_def().expect("already checked whether this is an enum");
6968

7069
let mut largest_variant: Option<(_, _)> = None;

0 commit comments

Comments
 (0)