Closed fmease closed 1 year ago
As before, I'm happy to second/liason an experiment for this. We already have None::<i32>
that sure looks like a generic const, so experimenting with a "real" version of that makes good sense to me.
cc @rust-lang/lang in case anyone wants to raise an objection.
@fmease We briefly raised this in the lang team meeting today, and there were still no objections, so the experiment is approved to move forward!
In the current version of Rust it is impossible to place generic parameters and where-clauses on free and associated constant items. This limits developers in their expressive power and renders certain desired functionality unattainable.
I hereby propose an experiment carried out by me in which the compiler gets extended to support generic const items addressing the aforementioned shortcoming of the language in an attempt to identify benefits and concerns in preparation for an RFC.
Motivation and use-cases
In no particular order:
TyCtxtConsts::<'tcx>::DEREF_PROJECTION
(example kindly provided by @compiler-errors)generic_const_exprs
) on constant items unblocking many useful patterns. See also rust-lang/rust#104400.generic_const_exprs
. See also https://lcnr.de/blog/generic-const-expressions/where Self: Sized
to each associated constant just like they would do with associated functions and types. See also rust-lang/rust#112319.Links
Initial people involved