You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
It makes constant items more consistent with other similar items, those being type aliases, associated types, free & associated functions, ADTs, traits and implementations. This is especially true for associated constants whose two siblings both already support generic parameters and where-clauses.
It allows for increased conciseness. While generic parameters on free & associated constant items can (always?) be emulated by moving them up to the parent of the constant (i.e. the corresponding trait or type which may require defining such a parent beforehand and converting a free to an associated constant), this approach is cumbersome and unintuitive for both the author and the consumer. As for a concrete example, one does not have to look any further than the compiler itself: TyCtxtConsts::<'tcx>::DEREF_PROJECTION (example kindly provided by @compiler-errors)
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 no place to add evaluatable bounds to assoc const items rust#104400.generic_const_exprs. See also https://lcnr.de/blog/generic-const-expressions/where Self: Sizedto each associated constant just like they would do with associated functions and types. See also Don't require associated types with Self: Sized bounds indyn Traitobjects rust#112319.Links
Initial people involved