Syntactically rejecting impl-Trait inside non-final path segments & inside fn ptr types is futile #132212
Labels
A-impl-trait
Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.
C-bug
Category: This is a bug.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
T-types
Relevant to the types team, which will review and decide on the PR/issue.
This concerns both universal and existential impl-Trait.
Since #48084 (2018) we reject impl-Trait inside qselves and non-final path segments (during AST
validationlowering (since #132214)).Since #45918 (2017) we reject impl-Trait inside fn ptr types (during AST lowering).
However, both checks are purely syntactic / syntax-driven as they happen before HIR analysis1.
Therefore we can simply circumvent them by introducing indirection via type aliases.
Examples:
This calls into question the very existence of these checks.
Should we just remove them? Are they historical remnants? Or should we keep them to prevent users from shooting themselves into the foot? Some of these types are actually quite useful (e.g., the
fn() -> impl Sized
as seen infn_ptr0_e_neg
) but a lot of them are not at all what you want. Some of them are completely useless (by containing unredeemably uninferable types). I don't think any of them lead to soundness issues.Footnotes
They could've been syntactic modulo (eager) type alias expansion (≠ normalization). ↩
The text was updated successfully, but these errors were encountered: