-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Open
Description
The code below does not compile because the compiler very strangely thinks it should search for the function in B
, when it is not mentioned anywhere inside the function f
.
trait A { fn run() -> bool; }
trait B { fn run() -> bool; }
impl A for bool { fn run() -> bool { true } }
impl B for bool { fn run() -> bool { true } }
fn f<T>() where T: A {
if T::run() {
}
}
fn main() {
f::<bool>();
}
Fails with:
|
8 |
9 | fn f<T>() where T: A {
10 | if T::run() {
| ^^^ Multiple applicable items in scope.
Disambiguate the associated function for candidate #0
<bool as A>::run
Disambiguate the associated function for candidate #1
<bool as B>::run
11 |
12 | }
|
Now, if we do make f
ambiguous like:
fn f<T>() where T: A + B {
if T::run() {
}
}
The error message also does not help, as it should suggest to write <T as A>::run()
or <T as B>::run()
, and not bool
, which is the concrete type.
Metadata
Metadata
Assignees
Labels
No labels