File tree 2 files changed +26
-4
lines changed
librustc/middle/typeck/check
2 files changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -294,17 +294,24 @@ pub fn check_struct_pat_fields(pcx: &pat_ctxt,
294
294
etc: bool) {
295
295
let tcx = pcx.fcx.ccx.tcx;
296
296
297
- // Index the class fields.
297
+ // Index the class fields. The second argument in the tuple is whether the
298
+ // field has been bound yet or not.
298
299
let mut field_map = HashMap::new();
299
300
for (i, class_field) in class_fields.iter().enumerate() {
300
- field_map.insert(class_field.name, i );
301
+ field_map.insert(class_field.name, (i, false) );
301
302
}
302
303
303
304
// Typecheck each field.
304
305
let mut found_fields = HashSet::new();
305
306
for field in fields.iter() {
306
- match field_map.find(&field.ident.name) {
307
- Some(&index) => {
307
+ match field_map.find_mut(&field.ident.name) {
308
+ Some(&(_, true)) => {
309
+ tcx.sess.span_err(span,
310
+ format!(" field `{ } ` bound twice in pattern",
311
+ tcx.sess.str_of(field.ident)));
312
+ }
313
+ Some(&(index, ref mut used)) => {
314
+ *used = true;
308
315
let class_field = class_fields[index];
309
316
let field_type = ty::lookup_field_type(tcx,
310
317
class_id,
Original file line number Diff line number Diff line change
1
+ // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2
+ // file at the top-level directory of this distribution and at
3
+ // http://rust-lang.org/COPYRIGHT.
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6
+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7
+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8
+ // option. This file may not be copied, modified, or distributed
9
+ // except according to those terms.
10
+
11
+ struct A { foo : int }
12
+
13
+ fn main ( ) {
14
+ let A { foo, foo } = A { foo : 3 } ; //~ ERROR: field `foo` bound twice
15
+ }
You can’t perform that action at this time.
0 commit comments