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
This commit is contained in:
commit
f60807dfee
4 changed files with 53 additions and 19 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -14,4 +14,7 @@ disallowed-methods = [
|
|||
"conf_disallowed_methods::Struct::method",
|
||||
"conf_disallowed_methods::Trait::provided_method",
|
||||
"conf_disallowed_methods::Trait::implemented_method",
|
||||
# re-exports
|
||||
"conf_disallowed_methods::identity",
|
||||
"conf_disallowed_methods::renamed",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -8,6 +8,9 @@ extern crate regex;
|
|||
use futures::stream::{empty, select_all};
|
||||
use regex::Regex;
|
||||
|
||||
use std::convert::identity;
|
||||
use std::hint::black_box as renamed;
|
||||
|
||||
fn local_fn() {}
|
||||
|
||||
struct Struct;
|
||||
|
|
@ -71,4 +74,9 @@ fn main() {
|
|||
//~^ disallowed_methods
|
||||
s.implemented_method();
|
||||
//~^ disallowed_methods
|
||||
|
||||
identity(());
|
||||
//~^ disallowed_methods
|
||||
renamed(1);
|
||||
//~^ disallowed_methods
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: use of a disallowed method `regex::Regex::new`
|
||||
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:33:14
|
||||
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:36:14
|
||||
|
|
||||
LL | let re = Regex::new(r"ab.*c").unwrap();
|
||||
| ^^^^^^^^^^
|
||||
|
|
@ -8,7 +8,7 @@ LL | let re = Regex::new(r"ab.*c").unwrap();
|
|||
= help: to override `-D warnings` add `#[allow(clippy::disallowed_methods)]`
|
||||
|
||||
error: use of a disallowed method `regex::Regex::is_match`
|
||||
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:35:8
|
||||
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:38:8
|
||||
|
|
||||
LL | re.is_match("abc");
|
||||
| ^^^^^^^^
|
||||
|
|
@ -16,76 +16,88 @@ LL | re.is_match("abc");
|
|||
= note: no matching allowed
|
||||
|
||||
error: use of a disallowed method `std::iter::Iterator::sum`
|
||||
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:39:14
|
||||
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:42:14
|
||||
|
|
||||
LL | a.iter().sum::<i32>();
|
||||
| ^^^
|
||||
|
||||
error: use of a disallowed method `slice::sort_unstable`
|
||||
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:42:7
|
||||
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:45:7
|
||||
|
|
||||
LL | a.sort_unstable();
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: use of a disallowed method `f32::clamp`
|
||||
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:46:20
|
||||
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:49:20
|
||||
|
|
||||
LL | let _ = 2.0f32.clamp(3.0f32, 4.0f32);
|
||||
| ^^^^^
|
||||
|
||||
error: use of a disallowed method `regex::Regex::new`
|
||||
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:50:61
|
||||
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:53:61
|
||||
|
|
||||
LL | let indirect: fn(&str) -> Result<Regex, regex::Error> = Regex::new;
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: use of a disallowed method `f32::clamp`
|
||||
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:54:28
|
||||
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:57:28
|
||||
|
|
||||
LL | let in_call = Box::new(f32::clamp);
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: use of a disallowed method `regex::Regex::new`
|
||||
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:56:53
|
||||
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:59:53
|
||||
|
|
||||
LL | let in_method_call = ["^", "$"].into_iter().map(Regex::new);
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: use of a disallowed method `futures::stream::select_all`
|
||||
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:60:31
|
||||
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:63:31
|
||||
|
|
||||
LL | let same_name_as_module = select_all(vec![empty::<()>()]);
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: use of a disallowed method `conf_disallowed_methods::local_fn`
|
||||
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:63:5
|
||||
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:66:5
|
||||
|
|
||||
LL | local_fn();
|
||||
| ^^^^^^^^
|
||||
|
||||
error: use of a disallowed method `conf_disallowed_methods::local_mod::f`
|
||||
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:65:5
|
||||
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:68:5
|
||||
|
|
||||
LL | local_mod::f();
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: use of a disallowed method `conf_disallowed_methods::Struct::method`
|
||||
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:68:7
|
||||
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:71:7
|
||||
|
|
||||
LL | s.method();
|
||||
| ^^^^^^
|
||||
|
||||
error: use of a disallowed method `conf_disallowed_methods::Trait::provided_method`
|
||||
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:70:7
|
||||
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:73:7
|
||||
|
|
||||
LL | s.provided_method();
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: use of a disallowed method `conf_disallowed_methods::Trait::implemented_method`
|
||||
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:72:7
|
||||
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:75:7
|
||||
|
|
||||
LL | s.implemented_method();
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 14 previous errors
|
||||
error: use of a disallowed method `conf_disallowed_methods::identity`
|
||||
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:78:5
|
||||
|
|
||||
LL | identity(());
|
||||
| ^^^^^^^^
|
||||
|
||||
error: use of a disallowed method `conf_disallowed_methods::renamed`
|
||||
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:80:5
|
||||
|
|
||||
LL | renamed(1);
|
||||
| ^^^^^^^
|
||||
|
||||
error: aborting due to 16 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue