Change:
This code compiles on nightly: Which it shouldn't, since variant has a field and the pattern doesn't mention it. This can also cause an ICE:
nightly-2016-02-17 is good, nightly-2016-02-21 is bad.

Discussion:
check_pat_enum(pcx, pat, path, subpats.as_ref().map(|v| &v[..]), expected, true); } PatKind::Path(ref path) => { <del> check_pat_enum(pcx, pat, path, None, expected, false); </del> <ins> check_pat_enum(pcx, pat, path, Some(&[]), expected, false); </ins> } PatKind::QPath(ref qself, ref path) => { let self_ty = fcx.to_ty(&qself.ty);

} } <del> pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>, pat: &hir::Pat, path: &hir::Path, subpats: Option<&'tcx [P<hir::Pat>]>, expected: Ty<'tcx>, is_tuple_struct_pat: bool) </del> <ins> fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>, pat: &hir::Pat, path: &hir::Path, subpats: Option<&'tcx [P<hir::Pat>]>, expected: Ty<'tcx>, is_tuple_struct_pat: bool) </ins> { // Typecheck the path. let fcx = pcx.fcx;

demand::eqtype(fcx, pat.span, expected, pat_ty); let real_path_ty = fcx.node_ty(pat.id); <del> let (arg_tys, kind_name): (Vec<_>, &'static str) = match real_path_ty.sty { </del> <ins> let (kind_name, variant, expected_substs) = match real_path_ty.sty { </ins> ty::TyEnum(enum_def, expected_substs) => { let variant = enum_def.variant_of_def(def); <del> if variant.kind() == ty::VariantKind::Struct { report_bad_struct_kind(false); return; } if is_tuple_struct_pat && variant.kind() != ty::VariantKind::Tuple { // Matching unit variants 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); if !is_special_case { return } } (variant.fields .iter() .map(|f| fcx.instantiate_type_scheme(pat.span, expected_substs, &f.unsubst_ty())) .collect(), "variant") </del> <ins> ("variant", variant, expected_substs) </ins> } ty::TyStruct(struct_def, expected_substs) => { let variant = struct_def.struct_variant(); <del> if is_tuple_struct_pat && variant.kind() != ty::VariantKind::Tuple { // 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 .iter() .map(|f| fcx.instantiate_type_scheme(pat.span, expected_substs, &f.unsubst_ty())) .collect(), "struct") </del> <ins> ("struct", variant, expected_substs) </ins> } _ => { report_bad_struct_kind(false);

} }; <ins> match (is_tuple_struct_pat, variant.kind()) { (true, ty::VariantKind::Unit) => { // Matching unit structs with tuple variant patterns (`UnitVariant(..)`) // is allowed for backward compatibility. report_bad_struct_kind(true); } (_, ty::VariantKind::Struct) => { report_bad_struct_kind(false); return } _ => {} } </ins> if let Some(subpats) = subpats { <del> if subpats.len() == arg_tys.len() { for (subpat, arg_ty) in subpats.iter().zip(arg_tys) { check_pat(pcx, &subpat, arg_ty); </del> <ins> if subpats.len() == variant.fields.len() { for (subpat, field) in subpats.iter().zip(&variant.fields) { let field_ty = fcx.field_ty(subpat.span, field, expected_substs); check_pat(pcx, &subpat, field_ty); </ins> } <del> } else if arg_tys.is_empty() { </del> <ins> } else if variant.fields.is_empty() { </ins> span_err!(tcx.sess, pat.span, E0024, "this pattern has {} field{}, but the corresponding {} has no fields", subpats.len(), if subpats.len() == 1 {""} else {"s"}, kind_name);

"this pattern has {} field{}, but the corresponding {} has {} field{}", subpats.len(), if subpats.len() == 1 {""} else {"s"}, kind_name, <del> arg_tys.len(), if arg_tys.len() == 1 {""} else {"s"}); </del> <ins> variant.fields.len(), if variant.fields.len() == 1 {""} else {"s"}); </ins> for pat in subpats { check_pat(pcx, &pat, tcx.types.err);

<ins> // Copyright 2016 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms. enum Foo { Bar(i32), Baz } struct S; fn main() { match Foo::Baz { Foo::Bar => {} //~^ ERROR this pattern has 0 fields, but the corresponding variant _ => {} } match S { S(()) => {} //~^ ERROR this pattern has 1 field, but the corresponding struct } } </ins>