-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.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
@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)
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.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.