about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-11-17 23:04:23 +0100
committerGitHub <noreply@github.com>2023-11-17 23:04:23 +0100
commit8792e81f29f105efff5ae926b5ae21e5ff7d3d56 (patch)
treee6f85d85837f90e6edbd4b228d5e7bb9baabfd24
parent6227455345359fd16e959f45538e652a983da149 (diff)
parent890ce26213c1cdc12ae269a91a62e3502a3165cc (diff)
downloadrust-8792e81f29f105efff5ae926b5ae21e5ff7d3d56.tar.gz
rust-8792e81f29f105efff5ae926b5ae21e5ff7d3d56.zip
Rollup merge of #117964 - estebank:issue-81232, r=petrochenkov
When using existing fn as module, don't claim it doesn't exist

Tweak wording of module not found in resolve, when the name exists but belongs to a non-`mod` item.

Fix #81232.
-rw-r--r--compiler/rustc_resolve/src/diagnostics.rs14
-rw-r--r--tests/ui/suggestions/crate-or-module-typo.rs2
-rw-r--r--tests/ui/suggestions/crate-or-module-typo.stderr4
3 files changed, 16 insertions, 4 deletions
diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs
index 93db6cfc463..28e6fe9b4b7 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 2471b11c61e..b12ad495e9f 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 9ece31e76f0..457d7790646 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<bool>
 LL +     bar: cell::Cell<bool>
    |
 
-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