about summary refs log tree commit diff
path: root/clippy_utils
diff options
context:
space:
mode:
authordswij <dharmasw@outlook.com>2025-05-10 16:55:19 +0000
committerGitHub <noreply@github.com>2025-05-10 16:55:19 +0000
commitf60807dfeee8be4725a04bf08b712ef8db719579 (patch)
tree06598787bd692d972448186b3b90b8f1c93dc9d3 /clippy_utils
parent5262ab24164d03733ce15ef06deee2512ea7d758 (diff)
parente4d82aefd95ee2cf035b02f6dcf15b0ea49b0171 (diff)
downloadrust-f60807dfeee8be4725a04bf08b712ef8db719579.tar.gz
rust-f60807dfeee8be4725a04bf08b712ef8db719579.zip
Resolve through local re-exports in `lookup_path` (#14772)
Fixes https://github.com/rust-lang/rust-clippy/issues/14767

A long standing issue revealed by
https://github.com/rust-lang/rust-clippy/pull/14397

changelog: none
Diffstat (limited to 'clippy_utils')
-rw-r--r--clippy_utils/src/paths.rs19
1 files changed, 15 insertions, 4 deletions
diff --git a/clippy_utils/src/paths.rs b/clippy_utils/src/paths.rs
index 795fb502c9c..e5179e479cc 100644
--- a/clippy_utils/src/paths.rs
+++ b/clippy_utils/src/paths.rs
@@ -8,9 +8,9 @@ use crate::{MaybePath, path_def_id, sym};
 use rustc_ast::Mutability;
 use rustc_data_structures::fx::FxHashMap;
 use rustc_hir::def::Namespace::{MacroNS, TypeNS, ValueNS};
-use rustc_hir::def::{DefKind, Namespace};
+use rustc_hir::def::{DefKind, Namespace, Res};
 use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId};
-use rustc_hir::{ImplItemRef, ItemKind, Node, OwnerId, TraitItemRef};
+use rustc_hir::{ImplItemRef, ItemKind, Node, OwnerId, TraitItemRef, UseKind};
 use rustc_lint::LateContext;
 use rustc_middle::ty::fast_reject::SimplifiedType;
 use rustc_middle::ty::{FloatTy, IntTy, Ty, TyCtxt, UintTy};
@@ -302,8 +302,19 @@ fn local_item_child_by_name(tcx: TyCtxt<'_>, local_id: LocalDefId, ns: PathNS, n
 
     match item_kind {
         ItemKind::Mod(_, r#mod) => r#mod.item_ids.iter().find_map(|&item_id| {
-            let ident = tcx.hir_item(item_id).kind.ident()?;
-            res(ident, item_id.owner_id)
+            let item = tcx.hir_item(item_id);
+            if let ItemKind::Use(path, UseKind::Single(ident)) = item.kind {
+                if ident.name == name {
+                    path.res
+                        .iter()
+                        .find(|res| ns.matches(res.ns()))
+                        .and_then(Res::opt_def_id)
+                } else {
+                    None
+                }
+            } else {
+                res(item.kind.ident()?, item_id.owner_id)
+            }
         }),
         ItemKind::Impl(r#impl) => r#impl
             .items