mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-26 15:36:39 +00:00
commit
135ba946a2
@ -1226,11 +1226,25 @@ impl Resolver {
|
||||
// the same module that declared the type.
|
||||
|
||||
// Bail out early if there are no static methods.
|
||||
let mut methods_seen = HashMap::new();
|
||||
let mut has_static_methods = false;
|
||||
for methods.each |method| {
|
||||
match method.explicit_self.node {
|
||||
sty_static => has_static_methods = true,
|
||||
_ => {}
|
||||
_ => {
|
||||
// Make sure you can't define duplicate methods
|
||||
let ident = method.ident;
|
||||
let span = method.span;
|
||||
let old_sp = methods_seen.find_or_insert(ident, span);
|
||||
if *old_sp != span {
|
||||
self.session.span_err(span,
|
||||
fmt!("duplicate definition of method `%s`",
|
||||
*self.session.str_of(ident)));
|
||||
self.session.span_note(*old_sp,
|
||||
fmt!("first definition of method `%s` here",
|
||||
*self.session.str_of(ident)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1333,7 +1347,7 @@ impl Resolver {
|
||||
}
|
||||
|
||||
// Add the names of all the methods to the trait info.
|
||||
let mut method_names = HashSet::new();
|
||||
let mut method_names = HashMap::new();
|
||||
for methods.each |method| {
|
||||
let ty_m = trait_method_to_ty_method(method);
|
||||
|
||||
@ -1357,13 +1371,22 @@ impl Resolver {
|
||||
ty_m.span);
|
||||
}
|
||||
_ => {
|
||||
method_names.insert(ident);
|
||||
// Make sure you can't define duplicate methods
|
||||
let old_sp = method_names.find_or_insert(ident, ty_m.span);
|
||||
if *old_sp != ty_m.span {
|
||||
self.session.span_err(ty_m.span,
|
||||
fmt!("duplicate definition of method `%s`",
|
||||
*self.session.str_of(ident)));
|
||||
self.session.span_note(*old_sp,
|
||||
fmt!("first definition of method `%s` here",
|
||||
*self.session.str_of(ident)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let def_id = local_def(item.id);
|
||||
for method_names.each |name| {
|
||||
for method_names.each |name, _| {
|
||||
if !self.method_map.contains_key(name) {
|
||||
self.method_map.insert(*name, HashSet::new());
|
||||
}
|
||||
|
@ -722,11 +722,6 @@ impl FnCtxt {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn expr_to_str(&self, expr: @ast::expr) -> ~str {
|
||||
fmt!("expr(%?:%s)", expr.id,
|
||||
pprust::expr_to_str(expr, self.tcx().sess.intr()))
|
||||
}
|
||||
|
||||
pub fn block_region(&self) -> ty::Region {
|
||||
ty::re_scope(self.region_lb)
|
||||
}
|
||||
|
@ -1063,13 +1063,6 @@ impl Parser {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn token_is_lifetime(&self, tok: &token::Token) -> bool {
|
||||
match *tok {
|
||||
token::LIFETIME(_) => true,
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
||||
/// Parses a single lifetime
|
||||
// matches lifetime = ( LIFETIME ) | ( IDENT / )
|
||||
pub fn parse_lifetime(&self) -> ast::Lifetime {
|
||||
|
17
src/test/compile-fail/impl-duplicate-methods.rs
Normal file
17
src/test/compile-fail/impl-duplicate-methods.rs
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
struct Foo;
|
||||
impl Foo {
|
||||
fn orange(&self){}
|
||||
fn orange(&self){} //~ ERROR error: duplicate definition of method `orange`
|
||||
}
|
||||
|
||||
fn main() {}
|
16
src/test/compile-fail/trait-duplicate-methods.rs
Normal file
16
src/test/compile-fail/trait-duplicate-methods.rs
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
trait Foo {
|
||||
fn orange(&self);
|
||||
fn orange(&self); //~ ERROR error: duplicate definition of method `orange`
|
||||
}
|
||||
|
||||
fn main() {}
|
Loading…
Reference in New Issue
Block a user