Closed
Description
@jonas-schievink pointed out that the "expected/found" ordering for -> impl trait
return types can be quite confusing:
trait Tr {
type A;
}
impl<A> Tr for A {
type A = A;
}
fn f() -> impl Tr<A=u8> {
()
}
gives
error[E0271]: type mismatch resolving `<() as Tr>::A == u8`
--> src/lib.rs:9:11
|
9 | fn f() -> impl Tr<A=u8> {
| ^^^^^^^^^^^^^ expected (), found u8
|
= note: expected type `()`
found type `u8`
= note: the return type of a function must have a statically known size
Additionally, the second note is wrong (()
is Sized
).
This does not happen when changing the code to use a boxed trait instead (expected and found are in the right order).
Originally posted by @jonas-schievink in #54326 (comment)