Skip to content

Commit 8fc14b6

Browse files
committed
librustc: Don't allow duplicate methods on a trait.
1 parent 4a52ff0 commit 8fc14b6

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/librustc/middle/resolve.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,7 @@ impl Resolver {
13331333
}
13341334

13351335
// Add the names of all the methods to the trait info.
1336-
let mut method_names = HashSet::new();
1336+
let mut method_names = HashMap::new();
13371337
for methods.each |method| {
13381338
let ty_m = trait_method_to_ty_method(method);
13391339

@@ -1357,13 +1357,22 @@ impl Resolver {
13571357
ty_m.span);
13581358
}
13591359
_ => {
1360-
method_names.insert(ident);
1360+
// Make sure you can't define duplicate methods
1361+
let old_sp = method_names.find_or_insert(ident, ty_m.span);
1362+
if *old_sp != ty_m.span {
1363+
self.session.span_err(ty_m.span,
1364+
fmt!("duplicate definition of method %s",
1365+
*self.session.str_of(ident)));
1366+
self.session.span_note(*old_sp,
1367+
fmt!("first definition of method %s here",
1368+
*self.session.str_of(ident)));
1369+
}
13611370
}
13621371
}
13631372
}
13641373

13651374
let def_id = local_def(item.id);
1366-
for method_names.each |name| {
1375+
for method_names.each |name, _| {
13671376
if !self.method_map.contains_key(name) {
13681377
self.method_map.insert(*name, HashSet::new());
13691378
}

0 commit comments

Comments
 (0)