Skip to content

Commit 3c6a203

Browse files
committed
Fix suggestion inside module
1 parent 9863a9b commit 3c6a203

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

src/librustc_resolve/diagnostics.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1006,10 +1006,11 @@ impl<'a> Resolver<'a> {
10061006
crate fn make_undeclared_type_suggestion(
10071007
&mut self,
10081008
ident: Ident,
1009+
parent_scope: &ParentScope<'a>,
1010+
ns: Namespace,
10091011
) -> (String, Option<Suggestion>) {
1010-
let parent_scope = &ParentScope::module(self.graph_root);
10111012
let typo_suggestion = self.early_lookup_typo_candidate(
1012-
ScopeSet::AbsolutePath(TypeNS),
1013+
ScopeSet::All(ns, false),
10131014
parent_scope,
10141015
ident,
10151016
&|_| true,

src/librustc_resolve/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2195,7 +2195,7 @@ impl<'a> Resolver<'a> {
21952195
return PathResult::NonModule(PartialRes::new(Res::Err));
21962196
}
21972197
} else if i == 0 {
2198-
self.make_undeclared_type_suggestion(ident)
2198+
self.make_undeclared_type_suggestion(ident, &parent_scope, ns)
21992199
} else {
22002200
(format!("could not find `{}` in `{}`", ident, path[i - 1].ident), None)
22012201
};

src/test/ui/resolve/suggest-type.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
use std::ffi::CString;
22

33
mod foo {
4-
fn bar() {}
4+
use std::collections::HashMap;
5+
6+
fn bar() {
7+
let _ = HashNap::new();
8+
//~^ ERROR failed to resolve: use of undeclared type or module `HashNap`
9+
//~| HELP a struct with a similar name exists
10+
//~| SUGGESTION HashMap
11+
}
512
}
613

714
fn main() {
+12-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1+
error[E0433]: failed to resolve: use of undeclared type or module `HashNap`
2+
--> $DIR/suggest-type.rs:7:17
3+
|
4+
LL | let _ = HashNap::new();
5+
| ^^^^^^^
6+
| |
7+
| use of undeclared type or module `HashNap`
8+
| help: a struct with a similar name exists: `HashMap`
9+
110
error[E0433]: failed to resolve: use of undeclared type or module `Cstring`
2-
--> $DIR/suggest-type.rs:8:13
11+
--> $DIR/suggest-type.rs:15:13
312
|
413
LL | let _ = Cstring::new("hello").unwrap();
514
| ^^^^^^^
@@ -8,14 +17,14 @@ LL | let _ = Cstring::new("hello").unwrap();
817
| help: a struct with a similar name exists (notice the capitalization): `CString`
918

1019
error[E0433]: failed to resolve: use of undeclared type or module `foO`
11-
--> $DIR/suggest-type.rs:13:13
20+
--> $DIR/suggest-type.rs:20:13
1221
|
1322
LL | let _ = foO::bar();
1423
| ^^^
1524
| |
1625
| use of undeclared type or module `foO`
1726
| help: a module with a similar name exists (notice the capitalization): `foo`
1827

19-
error: aborting due to 2 previous errors
28+
error: aborting due to 3 previous errors
2029

2130
For more information about this error, try `rustc --explain E0433`.

0 commit comments

Comments
 (0)