Skip to content

Commit 037456a

Browse files
author
Nick Hamann
committed
Make E0201 detect when duplicate function is a method.
1 parent f1db9cd commit 037456a

File tree

5 files changed

+9
-5
lines changed

5 files changed

+9
-5
lines changed

src/librustc_typeck/collect.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,11 @@ fn convert_methods<'a,'tcx,'i,I>(ccx: &CrateCtxt<'a, 'tcx>,
752752
let mut seen_methods = FnvHashSet();
753753
for (sig, id, ident, vis, span) in methods {
754754
if !seen_methods.insert(ident.name) {
755-
span_err!(tcx.sess, span, E0201, "duplicate associated function");
755+
let fn_desc = match sig.explicit_self.node {
756+
ast::SelfStatic => "associated function",
757+
_ => "method",
758+
};
759+
span_err!(tcx.sess, span, E0201, "duplicate {}", fn_desc);
756760
}
757761

758762
convert_method(ccx,

src/librustc_typeck/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ trait Baz {
901901
impl Baz for Foo {
902902
fn baz(&self) -> bool { true }
903903
904-
// error: duplicate associated function
904+
// error: duplicate method
905905
fn baz(&self) -> bool { self.0 > 5 }
906906
}
907907
```

src/test/compile-fail/impl-duplicate-methods.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
struct Foo;
1212
impl Foo {
1313
fn orange(&self){}
14-
fn orange(&self){} //~ ERROR duplicate associated function
14+
fn orange(&self){} //~ ERROR duplicate method
1515
}
1616

1717
fn main() {}

src/test/compile-fail/issue-8153.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ trait Bar {
1818

1919
impl Bar for Foo {
2020
fn bar(&self) -> isize {1}
21-
fn bar(&self) -> isize {2} //~ ERROR duplicate associated function
21+
fn bar(&self) -> isize {2} //~ ERROR duplicate method
2222
}
2323

2424
fn main() {

src/test/compile-fail/method-macro-backtrace.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl S {
2929

3030
// Cause an error. It shouldn't have any macro backtrace frames.
3131
fn bar(&self) { }
32-
fn bar(&self) { } //~ ERROR duplicate associated function
32+
fn bar(&self) { } //~ ERROR duplicate method
3333
}
3434

3535
fn main() { }

0 commit comments

Comments
 (0)