From 6c4eadd74746eaa21c6da1756c440b1fdabf0729 Mon Sep 17 00:00:00 2001 From: Urgau Date: Thu, 29 Feb 2024 21:00:35 +0100 Subject: [PATCH] Add early-return when checking if a path is local --- compiler/rustc_lint/src/non_local_def.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_lint/src/non_local_def.rs b/compiler/rustc_lint/src/non_local_def.rs index 597010b8925e0..1ae1c72b6e8f4 100644 --- a/compiler/rustc_lint/src/non_local_def.rs +++ b/compiler/rustc_lint/src/non_local_def.rs @@ -223,7 +223,9 @@ fn path_has_local_parent( impl_parent_parent: Option, ) -> bool { path.res.opt_def_id().is_some_and(|did| { - let res_parent = cx.tcx.parent(did); - res_parent == impl_parent || Some(res_parent) == impl_parent_parent + did.is_local() && { + let res_parent = cx.tcx.parent(did); + res_parent == impl_parent || Some(res_parent) == impl_parent_parent + } }) }