1
Fork 0

Make E0201 detect when duplicate function is a method.

This commit is contained in:
Nick Hamann 2015-06-03 01:34:39 -05:00
parent f1db9cd7c3
commit 037456a593
5 changed files with 9 additions and 5 deletions

View file

@ -752,7 +752,11 @@ fn convert_methods<'a,'tcx,'i,I>(ccx: &CrateCtxt<'a, 'tcx>,
let mut seen_methods = FnvHashSet(); let mut seen_methods = FnvHashSet();
for (sig, id, ident, vis, span) in methods { for (sig, id, ident, vis, span) in methods {
if !seen_methods.insert(ident.name) { if !seen_methods.insert(ident.name) {
span_err!(tcx.sess, span, E0201, "duplicate associated function"); let fn_desc = match sig.explicit_self.node {
ast::SelfStatic => "associated function",
_ => "method",
};
span_err!(tcx.sess, span, E0201, "duplicate {}", fn_desc);
} }
convert_method(ccx, convert_method(ccx,

View file

@ -901,7 +901,7 @@ trait Baz {
impl Baz for Foo { impl Baz for Foo {
fn baz(&self) -> bool { true } fn baz(&self) -> bool { true }
// error: duplicate associated function // error: duplicate method
fn baz(&self) -> bool { self.0 > 5 } fn baz(&self) -> bool { self.0 > 5 }
} }
``` ```

View file

@ -11,7 +11,7 @@
struct Foo; struct Foo;
impl Foo { impl Foo {
fn orange(&self){} fn orange(&self){}
fn orange(&self){} //~ ERROR duplicate associated function fn orange(&self){} //~ ERROR duplicate method
} }
fn main() {} fn main() {}

View file

@ -18,7 +18,7 @@ trait Bar {
impl Bar for Foo { impl Bar for Foo {
fn bar(&self) -> isize {1} fn bar(&self) -> isize {1}
fn bar(&self) -> isize {2} //~ ERROR duplicate associated function fn bar(&self) -> isize {2} //~ ERROR duplicate method
} }
fn main() { fn main() {

View file

@ -29,7 +29,7 @@ impl S {
// Cause an error. It shouldn't have any macro backtrace frames. // Cause an error. It shouldn't have any macro backtrace frames.
fn bar(&self) { } fn bar(&self) { }
fn bar(&self) { } //~ ERROR duplicate associated function fn bar(&self) { } //~ ERROR duplicate method
} }
fn main() { } fn main() { }