Skip to content

Commit 7bcde87

Browse files
author
jihyun
committed
Fixes #7377
1 parent 36d7f60 commit 7bcde87

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/librustc/middle/resolve.rs

+21
Original file line numberDiff line numberDiff line change
@@ -3886,6 +3886,27 @@ impl Resolver {
38863886
generics: &Generics,
38873887
fields: &[@struct_field],
38883888
visitor: ResolveVisitor) {
3889+
let mut ident_map = HashMap::new::<ast::ident, @struct_field>();
3890+
for fields.iter().advance |&field| {
3891+
match field.node.kind {
3892+
named_field(ident, _) => {
3893+
match ident_map.find(&ident) {
3894+
Some(&prev_field) => {
3895+
let ident_str = self.session.str_of(ident);
3896+
self.session.span_err(field.span,
3897+
fmt!("field `%s` is already declared", ident_str));
3898+
self.session.span_note(prev_field.span,
3899+
"Previously declared here");
3900+
},
3901+
None => {
3902+
ident_map.insert(ident, field);
3903+
}
3904+
}
3905+
}
3906+
_ => ()
3907+
}
3908+
}
3909+
38893910
// If applicable, create a rib for the type parameters.
38903911
do self.with_type_parameter_rib(HasTypeParameters
38913912
(generics, id, 0,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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 BuildData {
12+
foo: int,
13+
foo: int, //~ ERROR field `foo` is already declared
14+
}
15+
16+
fn main() {
17+
}

0 commit comments

Comments
 (0)