@@ -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
@@ -1333,7 +1347,7 @@ impl Resolver {
13331347 }
13341348
13351349 // Add the names of all the methods to the trait info.
1336- let mut method_names = HashSet :: new ( ) ;
1350+ let mut method_names = HashMap :: new ( ) ;
13371351 for methods. each |method| {
13381352 let ty_m = trait_method_to_ty_method ( method) ;
13391353
@@ -1357,13 +1371,22 @@ impl Resolver {
13571371 ty_m. span ) ;
13581372 }
13591373 _ => {
1360- method_names. insert ( ident) ;
1374+ // Make sure you can't define duplicate methods
1375+ let old_sp = method_names. find_or_insert ( ident, ty_m. span ) ;
1376+ if * old_sp != ty_m. span {
1377+ self . session . span_err ( ty_m. span ,
1378+ fmt ! ( "duplicate definition of method `%s`" ,
1379+ * self . session. str_of( ident) ) ) ;
1380+ self . session . span_note ( * old_sp,
1381+ fmt ! ( "first definition of method `%s` here" ,
1382+ * self . session. str_of( ident) ) ) ;
1383+ }
13611384 }
13621385 }
13631386 }
13641387
13651388 let def_id = local_def ( item. id ) ;
1366- for method_names. each |name| {
1389+ for method_names. each |name, _ | {
13671390 if !self . method_map . contains_key ( name) {
13681391 self . method_map . insert ( * name, HashSet :: new ( ) ) ;
13691392 }
0 commit comments