-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-inferenceArea: Type inferenceArea: Type inferenceA-trait-systemArea: Trait systemArea: Trait systemE-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
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`.
vmarkushin
Metadata
Metadata
Assignees
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-inferenceArea: Type inferenceArea: Type inferenceA-trait-systemArea: Trait systemArea: Trait systemE-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.