diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 93db6cfc4635d..28e6fe9b4b739 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -2028,7 +2028,19 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { }, ) }); - (format!("use of undeclared crate or module `{ident}`"), suggestion) + if let Ok(binding) = self.early_resolve_ident_in_lexical_scope( + ident, + ScopeSet::All(ValueNS), + parent_scope, + None, + false, + ignore_binding, + ) { + let descr = binding.res().descr(); + (format!("{descr} `{ident}` is not a crate or module"), suggestion) + } else { + (format!("use of undeclared crate or module `{ident}`"), suggestion) + } } } diff --git a/tests/ui/suggestions/crate-or-module-typo.rs b/tests/ui/suggestions/crate-or-module-typo.rs index 2471b11c61efd..b12ad495e9fd5 100644 --- a/tests/ui/suggestions/crate-or-module-typo.rs +++ b/tests/ui/suggestions/crate-or-module-typo.rs @@ -3,7 +3,7 @@ use st::cell::Cell; //~ ERROR failed to resolve: use of undeclared crate or module `st` mod bar { - pub fn bar() { bar::baz(); } //~ ERROR failed to resolve: use of undeclared crate or module `bar` + pub fn bar() { bar::baz(); } //~ ERROR failed to resolve: function `bar` is not a crate or module fn baz() {} } diff --git a/tests/ui/suggestions/crate-or-module-typo.stderr b/tests/ui/suggestions/crate-or-module-typo.stderr index 9ece31e76f005..457d779064682 100644 --- a/tests/ui/suggestions/crate-or-module-typo.stderr +++ b/tests/ui/suggestions/crate-or-module-typo.stderr @@ -42,11 +42,11 @@ LL - bar: st::cell::Cell LL + bar: cell::Cell | -error[E0433]: failed to resolve: use of undeclared crate or module `bar` +error[E0433]: failed to resolve: function `bar` is not a crate or module --> $DIR/crate-or-module-typo.rs:6:20 | LL | pub fn bar() { bar::baz(); } - | ^^^ use of undeclared crate or module `bar` + | ^^^ function `bar` is not a crate or module error: aborting due to 4 previous errors