Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/librustc_resolve/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions src/librustc_resolve/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())) {
Expand All @@ -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))
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2256,7 +2256,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))
});
Expand Down
5 changes: 0 additions & 5 deletions src/test/ui/lexical-scopes.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions src/test/ui/proc-macro/mixed-site-span.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down