-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-bugCategory: This is a bug.Category: This is a bug.P-highHigh priorityHigh priorityT-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.
Description
Note: All examples in this post was fixed in #112842. However the issue persists for lifetime arguments. See this comment for more.
The following compiles since v1.62:
fn foo<T>() -> impl Sized {
let _: () = foo::<u8>();
}
While the equivalent TAIT version doesn't compile because Opaque<u8> == u8
is not a valid defining use for Opaque
(because it is ambiguous whether Opaque<T> = T
or Opaque<T> = u8
):
#![feature(type_alias_impl_trait)]
type Opaque<T> = impl Sized;
fn foo<T>() -> Opaque<T> {
let _: () = foo::<u8>();
//~^ ERROR expected generic type parameter, found `u8`
}
I believe that TAIT behavior is the correct one because it's maximally compatible with future changes. Keeping this behavior for RPIT can also result in some surprising errors:
fn foo<T>(val: T) -> impl Sized {
let _: u8 = foo(0u8);
val
//~^ ERROR concrete type differs from previous defining opaque type use
}
This was stabilized (most likely unintentionally) in #94081. Cc @oli-obk.
See related code:
fn check_opaque_type_parameter_valid( |
Metadata
Metadata
Assignees
Labels
A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-bugCategory: This is a bug.Category: This is a bug.P-highHigh priorityHigh priorityT-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.