Hidden type of "discarded" and thus unconstrained RPIT(IT) opaque types gets inferred to be the unit type ()
#134311
Labels
A-impl-trait
Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.
A-inference
Area: Type inference
C-bug
Category: This is a bug.
fixed-by-next-solver
Fixed by the next-generation trait solver, `-Znext-solver`.
P-low
Low priority
T-types
Relevant to the types team, which will review and decide on the PR/issue.
This only affects RPIT(IT), not TAIT or ATPIT.
Fixing this issue would be a breaking change.
This exploits the issue #132212 (syntactically rejecting impl-Trait inside non-final path segments & inside fn ptr types is futile).
All subsequent snippets assume the following definitions:
RPIT check-pass reproducer (playground):
RPIT check-fail reproducer (playground):
I expected both reproducers to get rejected by the compiler due to uninferable types or unconstrained opaque types (with an error roughly of the form item does not constrain
demoN::{opaque#0}
, but has it in its signature (mirroring TAIT/ATPIT)). The opaque types should be unconstrained becauseDiscardT<{opaque}>
normalizes toPoint
which does not contain any opaque types.However, in both cases the hidden type gets inferred to be
()
. See also the compiler log for the first reproducer:It's odd that some sort of type inference fallback occurs (in case you're wondering: In Rust 2024, it also falls back to
()
, not!
(since we don't have anything diverging here)).Related: The fixed issue #96460 (
PhantomData<{opaque}>
).Ranking this P-low because it's pretty artificial and not unsound.
For completeness, RPITIT reproducers
For comparison, the TAIT and ATPIT analogues result in an error (though I'm not sure if that's an interesting comparison to draw).
TAIT/ATPIT
The text was updated successfully, but these errors were encountered: