Skip to content

Commit 52e530a

Browse files
committed
Auto merge of #25981 - nham:fix_E0201, r=alexcrichton
It seems better to use "associated function" here. Methods are associated functions that take a `self` parameter.
2 parents 0aeb9f6 + 037456a commit 52e530a

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
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 method");
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

+14-4
Original file line numberDiff line numberDiff line change
@@ -921,19 +921,29 @@ unsafe impl Bar for Foo { }
921921
"##,
922922

923923
E0201: r##"
924-
It is an error to define a method--a trait method or an inherent method--more
925-
than once.
924+
It is an error to define an associated function more than once.
926925
927-
For example,
926+
For example:
928927
929928
```
930929
struct Foo(u8);
931930
932931
impl Foo {
932+
fn bar(&self) -> bool { self.0 > 5 }
933+
934+
// error: duplicate associated function
933935
fn bar() {}
936+
}
937+
938+
trait Baz {
939+
fn baz(&self) -> bool;
940+
}
941+
942+
impl Baz for Foo {
943+
fn baz(&self) -> bool { true }
934944
935945
// error: duplicate method
936-
fn bar(&self) -> bool { self.0 > 5 }
946+
fn baz(&self) -> bool { self.0 > 5 }
937947
}
938948
```
939949
"##,

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 error: duplicate method
14+
fn orange(&self){} //~ ERROR duplicate method
1515
}
1616

1717
fn main() {}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl Foo {
1717
Foo { baz: 0 }.bar();
1818
}
1919

20-
fn bar() { //~ ERROR duplicate method
20+
fn bar() { //~ ERROR duplicate associated function
2121
}
2222
}
2323

0 commit comments

Comments
 (0)