diff --git a/src/librustc/middle/typeck/check/_match.rs b/src/librustc/middle/typeck/check/_match.rs index 92b30cd7af8..cdfd607d067 100644 --- a/src/librustc/middle/typeck/check/_match.rs +++ b/src/librustc/middle/typeck/check/_match.rs @@ -379,7 +379,8 @@ pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>, pat: &ast::Pat, let real_path_ty = fcx.node_ty(pat.id); let (arg_tys, kind_name) = match real_path_ty.sty { - ty::ty_enum(enum_def_id, ref expected_substs) => { + ty::ty_enum(enum_def_id, ref expected_substs) + if def == def::DefVariant(enum_def_id, def.def_id(), false) => { let variant = ty::enum_variant_with_id(tcx, enum_def_id, def.def_id()); (variant.args.iter().map(|t| t.subst(tcx, expected_substs)).collect::>(), "variant") @@ -392,7 +393,7 @@ pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>, pat: &ast::Pat, _ => { let name = pprust::path_to_string(path); span_err!(tcx.sess, pat.span, E0164, - "`{}` does not name a variant or a tuple struct", name); + "`{}` does not name a non-struct variant or a tuple struct", name); fcx.write_error(pat.id); if let Some(ref subpats) = *subpats { diff --git a/src/test/compile-fail/issue-19086.rs b/src/test/compile-fail/issue-19086.rs new file mode 100644 index 00000000000..9fd1f228984 --- /dev/null +++ b/src/test/compile-fail/issue-19086.rs @@ -0,0 +1,21 @@ +// Copyright 2014 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + enum Foo { + FooB { x: i32, y: i32 } + } + + let f = FooB { x: 3, y: 4 }; + match f { + FooB(a, b) => println!("{} {}", a, b), +//~^ ERROR `FooB` does not name a non-struct variant or a tuple struct + } +}