@@ -1226,11 +1226,25 @@ impl Resolver {
1226
1226
// the same module that declared the type.
1227
1227
1228
1228
// Bail out early if there are no static methods.
1229
+ let mut methods_seen = HashMap :: new ( ) ;
1229
1230
let mut has_static_methods = false ;
1230
1231
for methods. each |method| {
1231
1232
match method. explicit_self . node {
1232
1233
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
+ }
1234
1248
}
1235
1249
}
1236
1250
@@ -1333,7 +1347,7 @@ impl Resolver {
1333
1347
}
1334
1348
1335
1349
// 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 ( ) ;
1337
1351
for methods. each |method| {
1338
1352
let ty_m = trait_method_to_ty_method ( method) ;
1339
1353
@@ -1357,13 +1371,22 @@ impl Resolver {
1357
1371
ty_m. span ) ;
1358
1372
}
1359
1373
_ => {
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
+ }
1361
1384
}
1362
1385
}
1363
1386
}
1364
1387
1365
1388
let def_id = local_def ( item. id ) ;
1366
- for method_names. each |name| {
1389
+ for method_names. each |name, _ | {
1367
1390
if !self . method_map . contains_key ( name) {
1368
1391
self . method_map . insert ( * name, HashSet :: new ( ) ) ;
1369
1392
}
0 commit comments