Skip to content

Commit c6f3103

Browse files
committed
librustc: Don't allow duplicate methods on impls.
1 parent 8fc14b6 commit c6f3103

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/librustc/middle/resolve.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1226,11 +1226,25 @@ impl Resolver {
12261226
// the same module that declared the type.
12271227

12281228
// Bail out early if there are no static methods.
1229+
let mut methods_seen = HashMap::new();
12291230
let mut has_static_methods = false;
12301231
for methods.each |method| {
12311232
match method.explicit_self.node {
12321233
sty_static => has_static_methods = true,
1233-
_ => {}
1234+
_ => {
1235+
// Make sure you can't define duplicate methods
1236+
let ident = method.ident;
1237+
let span = method.span;
1238+
let old_sp = methods_seen.find_or_insert(ident, span);
1239+
if *old_sp != span {
1240+
self.session.span_err(span,
1241+
fmt!("duplicate definition of method %s",
1242+
*self.session.str_of(ident)));
1243+
self.session.span_note(*old_sp,
1244+
fmt!("first definition of method %s here",
1245+
*self.session.str_of(ident)));
1246+
}
1247+
}
12341248
}
12351249
}
12361250

0 commit comments

Comments
 (0)