Skip to content

Commit e01ae5e

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

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/librustc_typeck/check/_match.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,12 @@ pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
636636
let report_bad_struct_kind = |is_warning| {
637637
bad_struct_kind_err(tcx.sess, pat.span, path, is_warning);
638638
if is_warning {
639+
// Boo! Too painful to attach this to the actual warning,
640+
// it should go away at some point though.
641+
tcx.sess.span_note_without_error(
642+
pat.span,
643+
"this warning will become a HARD ERROR in a future release. \
644+
See RFC 218 for details.");
639645
return
640646
}
641647

@@ -676,10 +682,6 @@ pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
676682
report_bad_struct_kind(is_special_case);
677683
if !is_special_case {
678684
return
679-
} else {
680-
span_note!(tcx.sess, pat.span,
681-
"this warning will become a HARD ERROR in a future release. \
682-
See RFC 218 for details.");
683685
}
684686
}
685687
(variant.fields
@@ -693,7 +695,10 @@ pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
693695
ty::TyStruct(struct_def, expected_substs) => {
694696
let variant = struct_def.struct_variant();
695697
if is_tuple_struct_pat && variant.kind() != ty::VariantKind::Tuple {
696-
report_bad_struct_kind(false);
698+
// Matching unit structs with tuple variant patterns (`UnitVariant(..)`)
699+
// is allowed for backward compatibility.
700+
let is_special_case = variant.kind() == ty::VariantKind::Unit;
701+
report_bad_struct_kind(is_special_case);
697702
return;
698703
}
699704
(variant.fields

0 commit comments

Comments
 (0)