Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using existing fn as module, don't claim it doesn't exist #117964

Merged
merged 1 commit into from
Nov 18, 2023
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
14 changes: 13 additions & 1 deletion compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/suggestions/crate-or-module-typo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/suggestions/crate-or-module-typo.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading