Skip to content

Commit 135ba94

Browse files
committed
auto merge of #7064 : luqmana/rust/issue-7062, r=sanxiyn
Fixes #7062
2 parents 4a52ff0 + aa9a992 commit 135ba94

File tree

5 files changed

+60
-16
lines changed

5 files changed

+60
-16
lines changed

src/librustc/middle/resolve.rs

+27-4
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

@@ -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
}

src/librustc/middle/typeck/check/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -722,11 +722,6 @@ impl FnCtxt {
722722
}
723723
}
724724

725-
pub fn expr_to_str(&self, expr: @ast::expr) -> ~str {
726-
fmt!("expr(%?:%s)", expr.id,
727-
pprust::expr_to_str(expr, self.tcx().sess.intr()))
728-
}
729-
730725
pub fn block_region(&self) -> ty::Region {
731726
ty::re_scope(self.region_lb)
732727
}

src/libsyntax/parse/parser.rs

-7
Original file line numberDiff line numberDiff line change
@@ -1063,13 +1063,6 @@ impl Parser {
10631063
}
10641064
}
10651065

1066-
pub fn token_is_lifetime(&self, tok: &token::Token) -> bool {
1067-
match *tok {
1068-
token::LIFETIME(_) => true,
1069-
_ => false
1070-
}
1071-
}
1072-
10731066
/// Parses a single lifetime
10741067
// matches lifetime = ( LIFETIME ) | ( IDENT / )
10751068
pub fn parse_lifetime(&self) -> ast::Lifetime {
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 Foo;
12+
impl Foo {
13+
fn orange(&self){}
14+
fn orange(&self){} //~ ERROR error: duplicate definition of method `orange`
15+
}
16+
17+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
trait Foo {
12+
fn orange(&self);
13+
fn orange(&self); //~ ERROR error: duplicate definition of method `orange`
14+
}
15+
16+
fn main() {}

0 commit comments

Comments
 (0)