diff --git a/compiler/rustc_lint/src/non_local_def.rs b/compiler/rustc_lint/src/non_local_def.rs index 6cb6fd1cbd550..9ba04ca9ea434 100644 --- a/compiler/rustc_lint/src/non_local_def.rs +++ b/compiler/rustc_lint/src/non_local_def.rs @@ -67,6 +67,10 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions { return; } + if !matches!(item.kind, ItemKind::Impl(_) | ItemKind::Macro(_, _)) { + return; + } + let parent = cx.tcx.parent(item.owner_id.def_id.into()); let parent_def_kind = cx.tcx.def_kind(parent); let parent_opt_item_name = cx.tcx.opt_item_name(parent);