do not suggest enum tuple variant for named field variant
This commit is contained in:
parent
dd6683fcda
commit
07776c111f
3 changed files with 27 additions and 2 deletions
|
@ -336,7 +336,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
let compatible_variants: Vec<String> = expected_adt
|
let compatible_variants: Vec<String> = expected_adt
|
||||||
.variants()
|
.variants()
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|variant| variant.fields.len() == 1)
|
.filter(|variant| {
|
||||||
|
variant.fields.len() == 1 && variant.ctor_kind == hir::def::CtorKind::Fn
|
||||||
|
})
|
||||||
.filter_map(|variant| {
|
.filter_map(|variant| {
|
||||||
let sole_field = &variant.fields[0];
|
let sole_field = &variant.fields[0];
|
||||||
let sole_field_ty = sole_field.ty(self.tcx, substs);
|
let sole_field_ty = sole_field.ty(self.tcx, substs);
|
||||||
|
|
|
@ -64,3 +64,18 @@ fn main() {
|
||||||
//~^ ERROR mismatched types
|
//~^ ERROR mismatched types
|
||||||
//~| HELP try wrapping
|
//~| HELP try wrapping
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum A {
|
||||||
|
B { b: B},
|
||||||
|
}
|
||||||
|
|
||||||
|
enum B {
|
||||||
|
Fst,
|
||||||
|
Snd,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn foo() {
|
||||||
|
// We don't want to suggest `A::B(B::Fst)` here.
|
||||||
|
let a: A = B::Fst;
|
||||||
|
//~^ ERROR mismatched types
|
||||||
|
}
|
|
@ -190,6 +190,14 @@ help: try wrapping the expression in `Some`
|
||||||
LL | let _ = Foo { bar: Some(bar) };
|
LL | let _ = Foo { bar: Some(bar) };
|
||||||
| ++++++++++ +
|
| ++++++++++ +
|
||||||
|
|
||||||
error: aborting due to 11 previous errors
|
error[E0308]: mismatched types
|
||||||
|
--> $DIR/compatible-variants.rs:79:16
|
||||||
|
|
|
||||||
|
LL | let a: A = B::Fst;
|
||||||
|
| - ^^^^^^ expected enum `A`, found enum `B`
|
||||||
|
| |
|
||||||
|
| expected due to this
|
||||||
|
|
||||||
|
error: aborting due to 12 previous errors
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0308`.
|
For more information about this error, try `rustc --explain E0308`.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue