Skip to content

Commit d4039c5

Browse files
committed
extend warning cycle to cover matching unit-structs via S(..)
(this makes them handled like enum unit-variants.)
1 parent 25d1f4b commit d4039c5

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/librustc_typeck/check/_match.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,12 @@ pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
659659
let report_bad_struct_kind = |is_warning| {
660660
bad_struct_kind_err(tcx.sess, pat.span, path, is_warning);
661661
if is_warning {
662+
// Boo! Too painful to attach this to the actual warning,
663+
// it should go away at some point though.
664+
tcx.sess.span_note_without_error(
665+
pat.span,
666+
"this warning will become a HARD ERROR in a future release. \
667+
See RFC 218 for details.");
662668
return;
663669
}
664670

@@ -699,12 +705,6 @@ pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
699705
report_bad_struct_kind(is_special_case);
700706
if !is_special_case {
701707
return
702-
} else {
703-
// Boo! Too painful to attach this to the actual warning,
704-
// it should go away at some point though.
705-
tcx.sess.span_note_without_error(pat.span,
706-
"this warning will become a HARD ERROR in a future release. \
707-
See RFC 218 for details.");
708708
}
709709
}
710710
(variant.fields
@@ -718,7 +718,10 @@ pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
718718
ty::TyStruct(struct_def, expected_substs) => {
719719
let variant = struct_def.struct_variant();
720720
if is_tuple_struct_pat && variant.kind() != ty::VariantKind::Tuple {
721-
report_bad_struct_kind(false);
721+
// Matching unit structs with tuple variant patterns (`UnitVariant(..)`)
722+
// is allowed for backward compatibility.
723+
let is_special_case = variant.kind() == ty::VariantKind::Unit;
724+
report_bad_struct_kind(is_special_case);
722725
return;
723726
}
724727
(variant.fields

0 commit comments

Comments
 (0)