diff options
| -rw-r--r-- | src/librustc/middle/typeck/check/_match.rs | 3 | ||||
| -rw-r--r-- | src/test/compile-fail/issue-15260.rs | 19 |
2 files changed, 22 insertions, 0 deletions
diff --git a/src/librustc/middle/typeck/check/_match.rs b/src/librustc/middle/typeck/check/_match.rs index 67437da44c5..60ce9508dc4 100644 --- a/src/librustc/middle/typeck/check/_match.rs +++ b/src/librustc/middle/typeck/check/_match.rs @@ -318,6 +318,9 @@ pub fn check_struct_pat_fields(pcx: &pat_ctxt, for field in fields.iter() { match field_map.find_mut(&field.ident.name) { Some(&(_, true)) => { + // Check the pattern anyway, so that attempts to look + // up its type won't fail + check_pat(pcx, &*field.pat, ty::mk_err()); tcx.sess.span_err(span, format!("field `{}` bound twice in pattern", token::get_ident(field.ident)).as_slice()); diff --git a/src/test/compile-fail/issue-15260.rs b/src/test/compile-fail/issue-15260.rs new file mode 100644 index 00000000000..06826139884 --- /dev/null +++ b/src/test/compile-fail/issue-15260.rs @@ -0,0 +1,19 @@ +// 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 <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. + +struct Foo { + a: uint, +} + +fn main(){ + let Foo {a: _, a: _} = Foo {a: 29}; + //~^ ERROR field `a` bound twice in pattern +} + |
