Rollup merge of #72789 - petrochenkov:impcand, r=davidtwco
resolve: Do not suggest imports from the same module in which we are resolving Based on the idea from https://github.com/rust-lang/rust/pull/72623.
This commit is contained in:
commit
78d08a2269
5 changed files with 14 additions and 13 deletions
|
@ -629,6 +629,7 @@ impl<'a> Resolver<'a> {
|
|||
&mut self,
|
||||
lookup_ident: Ident,
|
||||
namespace: Namespace,
|
||||
parent_scope: &ParentScope<'a>,
|
||||
start_module: Module<'a>,
|
||||
crate_name: Ident,
|
||||
filter_fn: FilterFn,
|
||||
|
@ -655,7 +656,11 @@ impl<'a> Resolver<'a> {
|
|||
}
|
||||
|
||||
// collect results based on the filter function
|
||||
if ident.name == lookup_ident.name && ns == namespace {
|
||||
// avoid suggesting anything from the same module in which we are resolving
|
||||
if ident.name == lookup_ident.name
|
||||
&& ns == namespace
|
||||
&& !ptr::eq(in_module, parent_scope.module)
|
||||
{
|
||||
let res = name_binding.res();
|
||||
if filter_fn(res) {
|
||||
// create the path
|
||||
|
@ -722,6 +727,7 @@ impl<'a> Resolver<'a> {
|
|||
&mut self,
|
||||
lookup_ident: Ident,
|
||||
namespace: Namespace,
|
||||
parent_scope: &ParentScope<'a>,
|
||||
filter_fn: FilterFn,
|
||||
) -> Vec<ImportSuggestion>
|
||||
where
|
||||
|
@ -730,6 +736,7 @@ impl<'a> Resolver<'a> {
|
|||
let mut suggestions = self.lookup_import_candidates_from_module(
|
||||
lookup_ident,
|
||||
namespace,
|
||||
parent_scope,
|
||||
self.graph_root,
|
||||
Ident::with_dummy_span(kw::Crate),
|
||||
&filter_fn,
|
||||
|
@ -754,6 +761,7 @@ impl<'a> Resolver<'a> {
|
|||
suggestions.extend(self.lookup_import_candidates_from_module(
|
||||
lookup_ident,
|
||||
namespace,
|
||||
parent_scope,
|
||||
crate_root,
|
||||
ident,
|
||||
&filter_fn,
|
||||
|
|
|
@ -212,7 +212,7 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
|
|||
let ident = path.last().unwrap().ident;
|
||||
let candidates = self
|
||||
.r
|
||||
.lookup_import_candidates(ident, ns, is_expected)
|
||||
.lookup_import_candidates(ident, ns, &self.parent_scope, is_expected)
|
||||
.drain(..)
|
||||
.filter(|ImportSuggestion { did, .. }| {
|
||||
match (did, res.and_then(|res| res.opt_def_id())) {
|
||||
|
@ -223,7 +223,8 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
|
|||
.collect::<Vec<_>>();
|
||||
let crate_def_id = DefId::local(CRATE_DEF_INDEX);
|
||||
if candidates.is_empty() && is_expected(Res::Def(DefKind::Enum, crate_def_id)) {
|
||||
let enum_candidates = self.r.lookup_import_candidates(ident, ns, is_enum_variant);
|
||||
let enum_candidates =
|
||||
self.r.lookup_import_candidates(ident, ns, &self.parent_scope, is_enum_variant);
|
||||
let mut enum_candidates = enum_candidates
|
||||
.iter()
|
||||
.map(|suggestion| import_candidate_to_enum_paths(&suggestion))
|
||||
|
|
|
@ -2235,7 +2235,8 @@ impl<'a> Resolver<'a> {
|
|||
Res::Def(DefKind::Mod, _) => true,
|
||||
_ => false,
|
||||
};
|
||||
let mut candidates = self.lookup_import_candidates(ident, TypeNS, is_mod);
|
||||
let mut candidates =
|
||||
self.lookup_import_candidates(ident, TypeNS, parent_scope, is_mod);
|
||||
candidates.sort_by_cached_key(|c| {
|
||||
(c.path.segments.len(), pprust::path_to_string(&c.path))
|
||||
});
|
||||
|
|
|
@ -3,11 +3,6 @@ error[E0574]: expected struct, variant or union type, found type parameter `T`
|
|||
|
|
||||
LL | let t = T { i: 0 };
|
||||
| ^ not a struct, variant or union type
|
||||
|
|
||||
help: consider importing this struct instead
|
||||
|
|
||||
LL | use T;
|
||||
|
|
||||
|
||||
error[E0599]: no function or associated item named `f` found for type parameter `Foo` in the current scope
|
||||
--> $DIR/lexical-scopes.rs:10:10
|
||||
|
|
|
@ -27,10 +27,6 @@ LL | pass_dollar_crate!();
|
|||
| ^^^^^^^^^^^^^^^^^^^^^ not found in `$crate`
|
||||
|
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
help: consider importing this struct
|
||||
|
|
||||
LL | use ItemUse;
|
||||
|
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue