Closed
Description
I can't be sure that this behavior is unintended, but it definitely seems very strange and undesirable to me.
This code works fine:
$ cat trash2.rs
trait Tr<A, B> {
fn exec(a: A, b: B);
}
trait Q {
type T: Tr<u16, u16> + Tr<u8, u8>;
}
#[allow(dead_code)]
fn f<S: Q>()
{
<S as Q>::T::exec(0u8, 0u8)
}
fn main() {
}
$ rustc trash2.rs -o trash
But change the order of the trait bounds in the associated type T
, and it fails:
$ cat trash2.rs
trait Tr<A, B> {
fn exec(a: A, b: B);
}
trait Q {
type T: Tr<u8, u8> + Tr<u16, u16>;
}
#[allow(dead_code)]
fn f<S: Q>()
{
<S as Q>::T::exec(0u8, 0u8)
}
fn main() {
}
$ rustc trash2.rs -o trash
error[E0308]: mismatched types
--> trash2.rs:12:23
|
12 | <S as Q>::T::exec(0u8, 0u8)
| ^^^ expected u16, found u8
help: you can cast an `u8` to `u16`, which will zero-extend the source value
|
12 | <S as Q>::T::exec(0u8.into(), 0u8)
| ^^^^^^^^^^
error[E0308]: mismatched types
--> trash2.rs:12:28
|
12 | <S as Q>::T::exec(0u8, 0u8)
| ^^^ expected u16, found u8
help: you can cast an `u8` to `u16`, which will zero-extend the source value
|
12 | <S as Q>::T::exec(0u8, 0u8.into())
| ^^^^^^^^^^
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0308`.