Skip to content

Commit ab83d50

Browse files
committed
Do not issue E0071 if a type error has already been reported
1 parent c7dbe7a commit ab83d50

File tree

4 files changed

+52
-16
lines changed

4 files changed

+52
-16
lines changed

compiler/rustc_error_codes/src/error_codes/E0071.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ form of initializer was used.
1515
For example, the code above can be fixed to:
1616

1717
```
18-
enum Foo {
19-
FirstValue(i32)
20-
}
18+
type U32 = u32;
19+
let t: U32 = 4;
20+
```
2121

22-
fn main() {
23-
let u = Foo::FirstValue(0i32);
22+
or:
2423

25-
let t = 4;
26-
}
24+
```
25+
struct U32 { value: u32 }
26+
let t = U32 { value: 4 };
2727
```

compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

+19-9
Original file line numberDiff line numberDiff line change
@@ -494,15 +494,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
494494

495495
Some((variant, ty))
496496
} else {
497-
struct_span_err!(
498-
self.tcx.sess,
499-
path_span,
500-
E0071,
501-
"expected struct, variant or union type, found {}",
502-
ty.sort_string(self.tcx)
503-
)
504-
.span_label(path_span, "not a struct")
505-
.emit();
497+
match ty.kind() {
498+
ty::Error(_) => {
499+
// E0071 might be caused by a spelling error, which will have
500+
// already caused an error message and probably a suggestion
501+
// elsewhere. Refrain from emitting more unhelpful errors here
502+
// (issue #88844).
503+
}
504+
_ => {
505+
struct_span_err!(
506+
self.tcx.sess,
507+
path_span,
508+
E0071,
509+
"expected struct, variant or union type, found {}",
510+
ty.sort_string(self.tcx)
511+
)
512+
.span_label(path_span, "not a struct")
513+
.emit();
514+
}
515+
}
506516
None
507517
}
508518
}

src/test/ui/typeck/issue-88844.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Regression test for #88844.
2+
3+
struct Struct { value: i32 }
4+
//~^ NOTE: similarly named struct `Struct` defined here
5+
6+
impl Stuct {
7+
//~^ ERROR: cannot find type `Stuct` in this scope [E0412]
8+
//~| HELP: a struct with a similar name exists
9+
fn new() -> Self {
10+
Self { value: 42 }
11+
}
12+
}
13+
14+
fn main() {}

src/test/ui/typeck/issue-88844.stderr

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0412]: cannot find type `Stuct` in this scope
2+
--> $DIR/issue-88844.rs:6:6
3+
|
4+
LL | struct Struct { value: i32 }
5+
| ------------- similarly named struct `Struct` defined here
6+
...
7+
LL | impl Stuct {
8+
| ^^^^^ help: a struct with a similar name exists: `Struct`
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0412`.

0 commit comments

Comments
 (0)