Skip to content

Commit 8788df5

Browse files
committed
suggest similarly named type when use of undeclared type
1 parent be0501f commit 8788df5

File tree

5 files changed

+37
-3
lines changed

5 files changed

+37
-3
lines changed

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2059,7 +2059,13 @@ impl<'a> Resolver<'a> {
20592059
Applicability::MaybeIncorrect,
20602060
))
20612061
} else {
2062-
None
2062+
self.find_similarly_named_type(ident.name, ribs).map(|sugg| {
2063+
(
2064+
vec![(ident.span, sugg.to_string())],
2065+
String::from("there is a type with a similar name"),
2066+
Applicability::MaybeIncorrect,
2067+
)
2068+
})
20632069
};
20642070

20652071
(format!("use of undeclared type `{}`", ident), suggestion)

src/test/ui/generic-associated-types/equality-bound.stderr

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ error[E0433]: failed to resolve: use of undeclared type `I`
3636
--> $DIR/equality-bound.rs:9:41
3737
|
3838
LL | fn sum3<J: Iterator>(i: J) -> i32 where I::Item = i32 {
39-
| ^ use of undeclared type `I`
39+
| ^
40+
| |
41+
| use of undeclared type `I`
42+
| help: there is a type with a similar name: `J`
4043

4144
error: aborting due to 4 previous errors
4245

src/test/ui/pattern/pattern-error-continue.stderr

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ error[E0433]: failed to resolve: use of undeclared type `E`
22
--> $DIR/pattern-error-continue.rs:33:9
33
|
44
LL | E::V => {}
5-
| ^ use of undeclared type `E`
5+
| ^
6+
| |
7+
| use of undeclared type `E`
8+
| help: there is a type with a similar name: `Eq`
69

710
error[E0532]: expected tuple struct or tuple variant, found unit variant `A::D`
811
--> $DIR/pattern-error-continue.rs:18:9
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
struct FooType {}
2+
3+
impl FooType {
4+
fn bar() {}
5+
}
6+
7+
fn main() {
8+
FooTyp::bar()
9+
//~^ ERROR failed to resolve: use of undeclared type `FooTyp`
10+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0433]: failed to resolve: use of undeclared type `FooTyp`
2+
--> $DIR/suggest-similar-type-name.rs:8:5
3+
|
4+
LL | FooTyp::bar()
5+
| ^^^^^^
6+
| |
7+
| use of undeclared type `FooTyp`
8+
| help: there is a type with a similar name: `FooType`
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0433`.

0 commit comments

Comments
 (0)