Unused generic parameters of anonymous constants #33
Labels
A-generic-exprs
Generic const expressions
A-unification
Unifying constants in the type system
C-design-docs
Category: This is part of our design documentation
K-impl
Document Kind: regarding implementation
P-necessary
Priority: will be needed at some point
S-active
What is this
This is a design document for const generics. Any discussions about its content should be on zulip. The conclusions of these discussions should then be edited back into this issue. Please do not post any comments directly in this issue.
Content
This is one of the core issues wrt generic constants in the type system.
With
feature(generic_const_exprs)
we would likefoo::<{ N + 3 }>
to be valid code.The current implementation gives anonymous constants all of the generics and where clauses of the parent item:
is desugared to
This causes a lot of issues.
Forcing all type parameters to be invariant
is desugared to
Generic arguments of anonymous constants are forced to be invariant. This
causes
'a
andT
be invariant even though they aren't actually used.Unsize coercions (#78369)
This compiles on stable but fails to compile if we provide
T
to the anonymous constant1 + 4
aswe now cannot unsize
T
anymore.Self referential closures (#85665)
The anonymous constant
N - 1
hasF
as a generic parameter. This means that the function signature ofF
containsF
itself, causing an error.How this might get fixed
As this is one of the core issues of const generics, we thought about quite a few potential solutions to this issue.
Completely replacing
ty::ConstKind::Unevaluated
By never representing anonymous constants as
ty::ConstKind::Unevaluated
and instead directly converting them into some abstractrepresentation, we can avoid these issues, for example:
This means we directly embed the fully expanded AbstractConst directly as a variant of
ty::ConstKind
.directly converts
hir
into thety::ConstKind::Expr
representation.be used in generic anonymous constants
The text was updated successfully, but these errors were encountered: