You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
#![feature(trait_alias)]traitSomeTrait{fnmap(&self){}}impl<T>SomeTraitforOption<T>{}traitSomeAlias = SomeTrait;// comment this out and everything worksfnmain(){let x = Some(123);Option::map(x, |z| z);// Error: multiple `map` foundlet 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<_>`
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.
Activity
jonas-schievink commentedon Apr 16, 2019
cc #55628
Centril commentedon Apr 16, 2019
cc @seanmonstar, @alexreg, and @petrochenkov -- Is
trait SomeAlias = SomeTrait;importing the trait with higher priority than inherent items?petrochenkov commentedon Apr 16, 2019
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.
Fix trait alias inherent impl resolution
Rollup merge of rust-lang#72556 - matthew-mcallister:trait-alias-inhe…
Rollup merge of rust-lang#72556 - matthew-mcallister:trait-alias-inhe…
Rollup merge of rust-lang#72556 - matthew-mcallister:trait-alias-inhe…