Skip to content

Commit 8a66362

Browse files
committed
Diagnostic note when matching tuple enum with struct pattern
1 parent 14039a4 commit 8a66362

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/librustc_typeck/check/_match.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -787,11 +787,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
787787
for field in variant.fields
788788
.iter()
789789
.filter(|field| !used_fields.contains_key(&field.name)) {
790-
struct_span_err!(tcx.sess, span, E0027,
791-
"pattern does not mention field `{}`",
792-
field.name)
793-
.span_label(span, format!("missing field `{}`", field.name))
794-
.emit();
790+
let mut diag = struct_span_err!(tcx.sess, span, E0027,
791+
"pattern does not mention field `{}`",
792+
field.name);
793+
diag.span_label(span, format!("missing field `{}`", field.name));
794+
if variant.ctor_kind == CtorKind::Fn {
795+
diag.note("trying to match a tuple variant with a struct variant pattern");
796+
}
797+
diag.emit();
795798
}
796799
}
797800
}

0 commit comments

Comments
 (0)