From d4039c5d402033e28744b91b95ea1c560fa4ab0b Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Thu, 7 Jan 2016 00:45:13 +0100 Subject: [PATCH] extend warning cycle to cover matching unit-structs via `S(..)` (this makes them handled like enum unit-variants.) --- src/librustc_typeck/check/_match.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index 926d7fd6e25e..2e69ff100bf4 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -659,6 +659,12 @@ pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>, let report_bad_struct_kind = |is_warning| { bad_struct_kind_err(tcx.sess, pat.span, path, is_warning); if is_warning { + // Boo! Too painful to attach this to the actual warning, + // it should go away at some point though. + tcx.sess.span_note_without_error( + pat.span, + "this warning will become a HARD ERROR in a future release. \ + See RFC 218 for details."); return; } @@ -699,12 +705,6 @@ pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>, report_bad_struct_kind(is_special_case); if !is_special_case { return - } else { - // Boo! Too painful to attach this to the actual warning, - // it should go away at some point though. - tcx.sess.span_note_without_error(pat.span, - "this warning will become a HARD ERROR in a future release. \ - See RFC 218 for details."); } } (variant.fields @@ -718,7 +718,10 @@ pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>, ty::TyStruct(struct_def, expected_substs) => { let variant = struct_def.struct_variant(); if is_tuple_struct_pat && variant.kind() != ty::VariantKind::Tuple { - report_bad_struct_kind(false); + // Matching unit structs with tuple variant patterns (`UnitVariant(..)`) + // is allowed for backward compatibility. + let is_special_case = variant.kind() == ty::VariantKind::Unit; + report_bad_struct_kind(is_special_case); return; } (variant.fields