suggest wrapping in struct tuples as well

This commit is contained in:
Michael Goulet 2022-03-27 16:15:26 -07:00
parent 07776c111f
commit fc289a0796
3 changed files with 25 additions and 7 deletions

View file

@ -268,10 +268,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expr_ty: Ty<'tcx>,
) {
if let ty::Adt(expected_adt, substs) = expected.kind() {
if !expected_adt.is_enum() {
return;
}
// If the expression is of type () and it's the return expression of a block,
// we suggest adding a separate return expression instead.
// (To avoid things like suggesting `Ok(while .. { .. })`.)

View file

@ -69,6 +69,8 @@ enum A {
B { b: B},
}
struct A2(B);
enum B {
Fst,
Snd,
@ -78,4 +80,11 @@ fn foo() {
// We don't want to suggest `A::B(B::Fst)` here.
let a: A = B::Fst;
//~^ ERROR mismatched types
}
}
fn bar() {
// But we _do_ want to suggest `A2(B::Fst)` here!
let a: A2 = B::Fst;
//~^ ERROR mismatched types
//~| HELP try wrapping
}

View file

@ -191,13 +191,26 @@ LL | let _ = Foo { bar: Some(bar) };
| ++++++++++ +
error[E0308]: mismatched types
--> $DIR/compatible-variants.rs:79:16
--> $DIR/compatible-variants.rs:81:16
|
LL | let a: A = B::Fst;
| - ^^^^^^ expected enum `A`, found enum `B`
| |
| expected due to this
error: aborting due to 12 previous errors
error[E0308]: mismatched types
--> $DIR/compatible-variants.rs:87:17
|
LL | let a: A2 = B::Fst;
| -- ^^^^^^ expected struct `A2`, found enum `B`
| |
| expected due to this
|
help: try wrapping the expression in `A2`
|
LL | let a: A2 = A2(B::Fst);
| +++ +
error: aborting due to 13 previous errors
For more information about this error, try `rustc --explain E0308`.