From 9763472e2b162aeb56b4950a28d829a7e6dd85ee Mon Sep 17 00:00:00 2001 From: yukang Date: Fri, 7 Jul 2023 09:49:39 +0800 Subject: [PATCH] smart_resolve_partial_mod_path_errors should not suggest parent --- compiler/rustc_resolve/src/late/diagnostics.rs | 7 ++++--- tests/ui/resolve/export-fully-qualified-2018.stderr | 5 ----- tests/ui/resolve/export-fully-qualified.stderr | 5 ----- tests/ui/suggestions/crate-or-module-typo.stderr | 5 ----- 4 files changed, 4 insertions(+), 18 deletions(-) diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index cf1c1787cb5..73865f81b6d 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -350,9 +350,10 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { .filter(|candidate| { if let Some(def_id) = candidate.did && let Some(module) = self.r.get_module(def_id) { - self.r.resolutions(module).borrow().iter().any(|(key, _r)| { - key.ident.name == following_seg.ident.name - }) + Some(def_id) != self.parent_scope.module.opt_def_id() && + self.r.resolutions(module).borrow().iter().any(|(key, _r)| { + key.ident.name == following_seg.ident.name + }) } else { false } diff --git a/tests/ui/resolve/export-fully-qualified-2018.stderr b/tests/ui/resolve/export-fully-qualified-2018.stderr index 366ffd9bb2b..b724da930df 100644 --- a/tests/ui/resolve/export-fully-qualified-2018.stderr +++ b/tests/ui/resolve/export-fully-qualified-2018.stderr @@ -3,11 +3,6 @@ error[E0433]: failed to resolve: use of undeclared crate or module `foo` | LL | pub fn bar() { foo::baz(); } | ^^^ use of undeclared crate or module `foo` - | -help: consider importing this module - | -LL + use crate::foo; - | error: aborting due to previous error diff --git a/tests/ui/resolve/export-fully-qualified.stderr b/tests/ui/resolve/export-fully-qualified.stderr index 0cd516ee1b1..a8af0c7c9b8 100644 --- a/tests/ui/resolve/export-fully-qualified.stderr +++ b/tests/ui/resolve/export-fully-qualified.stderr @@ -3,11 +3,6 @@ error[E0433]: failed to resolve: use of undeclared crate or module `foo` | LL | pub fn bar() { foo::baz(); } | ^^^ use of undeclared crate or module `foo` - | -help: consider importing this module - | -LL + use foo; - | error: aborting due to previous error diff --git a/tests/ui/suggestions/crate-or-module-typo.stderr b/tests/ui/suggestions/crate-or-module-typo.stderr index 5e7a7685ab0..98b88b4fb92 100644 --- a/tests/ui/suggestions/crate-or-module-typo.stderr +++ b/tests/ui/suggestions/crate-or-module-typo.stderr @@ -36,11 +36,6 @@ error[E0433]: failed to resolve: use of undeclared crate or module `bar` | LL | pub fn bar() { bar::baz(); } | ^^^ use of undeclared crate or module `bar` - | -help: consider importing this module - | -LL + use crate::bar; - | error: aborting due to 4 previous errors