1
Fork 0

Do not issue E0071 if a type error has already been reported

This commit is contained in:
Fabian Wolff 2021-09-12 23:07:23 +02:00
parent c7dbe7a830
commit ab83d501a4
4 changed files with 54 additions and 18 deletions

View file

@ -15,13 +15,13 @@ form of initializer was used.
For example, the code above can be fixed to: For example, the code above can be fixed to:
``` ```
enum Foo { type U32 = u32;
FirstValue(i32) let t: U32 = 4;
} ```
fn main() { or:
let u = Foo::FirstValue(0i32);
```
let t = 4; struct U32 { value: u32 }
} let t = U32 { value: 4 };
``` ```

View file

@ -494,15 +494,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Some((variant, ty)) Some((variant, ty))
} else { } else {
struct_span_err!( match ty.kind() {
self.tcx.sess, ty::Error(_) => {
path_span, // E0071 might be caused by a spelling error, which will have
E0071, // already caused an error message and probably a suggestion
"expected struct, variant or union type, found {}", // elsewhere. Refrain from emitting more unhelpful errors here
ty.sort_string(self.tcx) // (issue #88844).
) }
.span_label(path_span, "not a struct") _ => {
.emit(); struct_span_err!(
self.tcx.sess,
path_span,
E0071,
"expected struct, variant or union type, found {}",
ty.sort_string(self.tcx)
)
.span_label(path_span, "not a struct")
.emit();
}
}
None None
} }
} }

View file

@ -0,0 +1,14 @@
// Regression test for #88844.
struct Struct { value: i32 }
//~^ NOTE: similarly named struct `Struct` defined here
impl Stuct {
//~^ ERROR: cannot find type `Stuct` in this scope [E0412]
//~| HELP: a struct with a similar name exists
fn new() -> Self {
Self { value: 42 }
}
}
fn main() {}

View file

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