Skip to content

Commit 890ce26

Browse files
committed
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.
1 parent 6d069a0 commit 890ce26

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

compiler/rustc_resolve/src/diagnostics.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -2028,7 +2028,19 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
20282028
},
20292029
)
20302030
});
2031-
(format!("use of undeclared crate or module `{ident}`"), suggestion)
2031+
if let Ok(binding) = self.early_resolve_ident_in_lexical_scope(
2032+
ident,
2033+
ScopeSet::All(ValueNS),
2034+
parent_scope,
2035+
None,
2036+
false,
2037+
ignore_binding,
2038+
) {
2039+
let descr = binding.res().descr();
2040+
(format!("{descr} `{ident}` is not a crate or module"), suggestion)
2041+
} else {
2042+
(format!("use of undeclared crate or module `{ident}`"), suggestion)
2043+
}
20322044
}
20332045
}
20342046

tests/ui/suggestions/crate-or-module-typo.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use st::cell::Cell; //~ ERROR failed to resolve: use of undeclared crate or module `st`
44

55
mod bar {
6-
pub fn bar() { bar::baz(); } //~ ERROR failed to resolve: use of undeclared crate or module `bar`
6+
pub fn bar() { bar::baz(); } //~ ERROR failed to resolve: function `bar` is not a crate or module
77

88
fn baz() {}
99
}

tests/ui/suggestions/crate-or-module-typo.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ LL - bar: st::cell::Cell<bool>
4242
LL + bar: cell::Cell<bool>
4343
|
4444

45-
error[E0433]: failed to resolve: use of undeclared crate or module `bar`
45+
error[E0433]: failed to resolve: function `bar` is not a crate or module
4646
--> $DIR/crate-or-module-typo.rs:6:20
4747
|
4848
LL | pub fn bar() { bar::baz(); }
49-
| ^^^ use of undeclared crate or module `bar`
49+
| ^^^ function `bar` is not a crate or module
5050

5151
error: aborting due to 4 previous errors
5252

0 commit comments

Comments
 (0)