diff options
| author | Alex Macleod <alex@macleod.io> | 2025-05-09 22:03:49 +0000 |
|---|---|---|
| committer | Alex Macleod <alex@macleod.io> | 2025-05-09 22:13:35 +0000 |
| commit | e4d82aefd95ee2cf035b02f6dcf15b0ea49b0171 (patch) | |
| tree | e4e5daf3ba1ab20832010d67753e1f7f320a5761 /clippy_utils | |
| parent | 16fd2a83d791d1a4eddbe620ebac37da208e25c4 (diff) | |
| download | rust-e4d82aefd95ee2cf035b02f6dcf15b0ea49b0171.tar.gz rust-e4d82aefd95ee2cf035b02f6dcf15b0ea49b0171.zip | |
Resolve through local re-exports in `lookup_path`
Diffstat (limited to 'clippy_utils')
| -rw-r--r-- | clippy_utils/src/paths.rs | 19 |
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 |
