Skip to content
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

Duplicate methods defined in multiple inherent impls do not report as duplicates #32491

Closed
shepmaster opened this issue Mar 25, 2016 · 1 comment

Comments

@shepmaster
Copy link
Member

Given this code:

struct A;

impl A {
    fn get(&self) -> u8 { 42 }
}

impl A {
    fn get(&self) -> u8 { 24 }
}

fn main() {
    let a = A;
    a.get();
}

I would expect to get

error: duplicate method

but instead I get

error: multiple applicable items in scope

As far as I am aware, there's no way to actually pick one of the multiple methods, is there?

This seems to be highly related to #22889, but the same behavior occurs with the nightly on the playground, even when using static methods instead of instance methods.

@bluss
Copy link
Member

bluss commented Mar 25, 2016

If you remove the use (line with a.get()) you see this new warning for this in nightly:

dup.rs:4:5: 4:31 warning: duplicate definitions with name `get`, #[warn(overlapping_inherent_impls)] on by default
dup.rs:4     fn get(&self) -> u8 { 42 }
             ^~~~~~~~~~~~~~~~~~~~~~~~~~
dup.rs:4:5: 4:31 warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
dup.rs:4:5: 4:31 note: for more information, see issue #22889 <https://github.com/rust-lang/rust/issues/22889>
dup.rs:4:5: 4:31 warning: method is never used: `get`, #[warn(dead_code)] on by default
dup.rs:4     fn get(&self) -> u8 { 42 }

So it used to be allowed but is now a warning and will be an error in the future. Methods with the same name but with some kind of type difference in the implementing type will still be allowed. I think this issue is fixed in nightly for this reason.

@bluss bluss closed this as completed Mar 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants