Skip to content

s/method/associated function/ in E0201 #25981

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,11 @@ fn convert_methods<'a,'tcx,'i,I>(ccx: &CrateCtxt<'a, 'tcx>,
let mut seen_methods = FnvHashSet();
for (sig, id, ident, vis, span) in methods {
if !seen_methods.insert(ident.name) {
span_err!(tcx.sess, span, E0201, "duplicate method");
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,
Expand Down
18 changes: 14 additions & 4 deletions src/librustc_typeck/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -880,19 +880,29 @@ unsafe impl Bar for Foo { }
"##,

E0201: r##"
It is an error to define a method--a trait method or an inherent method--more
than once.
It is an error to define an associated function more than once.

For example,
For example:

```
struct Foo(u8);

impl Foo {
fn bar(&self) -> bool { self.0 > 5 }

// error: duplicate associated function
fn bar() {}
}

trait Baz {
fn baz(&self) -> bool;
}

impl Baz for Foo {
fn baz(&self) -> bool { true }

// error: duplicate method
fn bar(&self) -> bool { self.0 > 5 }
fn baz(&self) -> bool { self.0 > 5 }
}
```
"##,
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/impl-duplicate-methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
struct Foo;
impl Foo {
fn orange(&self){}
fn orange(&self){} //~ ERROR error: duplicate method
fn orange(&self){} //~ ERROR duplicate method
}

fn main() {}
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-4265.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl Foo {
Foo { baz: 0 }.bar();
}

fn bar() { //~ ERROR duplicate method
fn bar() { //~ ERROR duplicate associated function
}
}

Expand Down