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

Trait alias makes method call ambigous #60021

Closed
athre0z opened this issue Apr 16, 2019 · 3 comments · Fixed by #72556
Closed

Trait alias makes method call ambigous #60021

athre0z opened this issue Apr 16, 2019 · 3 comments · Fixed by #72556
Labels
A-traits Area: Trait system C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@athre0z
Copy link
Contributor

athre0z commented Apr 16, 2019

When a trait alias to a trait with a method with the same name as a method on a struct is in scope, rustc is suddenly unable to disambiguate the trait method from the struct method.

Playground link

#![feature(trait_alias)]

trait SomeTrait {
    fn map(&self) {}
}

impl<T> SomeTrait for Option<T> {}

trait SomeAlias = SomeTrait; // comment this out and everything works

fn main() {
    let x = Some(123);
    Option::map(x, |z| z);  // Error: multiple `map` found

    let x = Some(123);
    x.map(|z| z);  // Fine, no error.
}
error[E0034]: multiple applicable items in scope
  --> src/main.rs:13:5
   |
13 |     Option::map(x, |z| z);  // Error: multiple `map` found
   |     ^^^^^^^^^^^ multiple `map` found
   |
note: candidate #1 is defined in an impl of the trait `SomeTrait` for the type `std::option::Option<_>`
  --> src/main.rs:4:5
   |
4  |     fn map(&self) {}
   |     ^^^^^^^^^^^^^
   = note: candidate #2 is defined in an impl for the type `std::option::Option<_>`
@jonas-schievink jonas-schievink added A-traits Area: Trait system C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 16, 2019
@jonas-schievink
Copy link
Contributor

cc #55628

@Centril
Copy link
Contributor

Centril commented Apr 16, 2019

cc @seanmonstar, @alexreg, and @petrochenkov -- Is trait SomeAlias = SomeTrait; importing the trait with higher priority than inherent items?

@petrochenkov
Copy link
Contributor

Is trait SomeAlias = SomeTrait; importing the trait with higher priority than inherent items?

It shouldn't do that, looks like a bug.
A method introduced into scope via trait alias (import) should behave identically to methods introduced with a trait (import), that means lower priority than inherent items.

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Jun 13, 2020
…rent-impl, r=estebank

Fix trait alias inherent impl resolution

Fixes rust-lang#60021 and fixes rust-lang#72415.

Obviously, the fix was very easy, but getting started with the testing and debugging rust compiler was an interesting experience. Now I can cross it off my bucket list!
RalfJung added a commit to RalfJung/rust that referenced this issue Jun 15, 2020
…rent-impl, r=estebank

Fix trait alias inherent impl resolution

Fixes rust-lang#60021 and fixes rust-lang#72415.

Obviously, the fix was very easy, but getting started with the testing and debugging rust compiler was an interesting experience. Now I can cross it off my bucket list!
RalfJung added a commit to RalfJung/rust that referenced this issue Jun 15, 2020
…rent-impl, r=estebank

Fix trait alias inherent impl resolution

Fixes rust-lang#60021 and fixes rust-lang#72415.

Obviously, the fix was very easy, but getting started with the testing and debugging rust compiler was an interesting experience. Now I can cross it off my bucket list!
@bors bors closed this as completed in 98eb29c Jun 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-traits Area: Trait system C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants