librustc: Don't ICE on binding same field multiple times in struct

pattern.
This commit is contained in:
Jonathan Bailey 2014-06-29 22:29:33 -07:00
parent 9ae48286a9
commit 6821a18122
2 changed files with 22 additions and 0 deletions

View File

@ -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());

View File

@ -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
}