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
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.
I think it may be a good idea to have a MVP for allowing associated constants to be used in const generics, basically we'd introduce a attribute #[usable_in_const_generic] (to be bikesheded) where all associated constants decorated with that attribute are restricted such that they're usable in const generics:
pubtraitMyTrait{#[usable_in_const_generic]constC:usize;}pubstructS<constC:usize>;impl<constC:usize>S<C>{#[usable_in_const_generic]pubconstC2:usize = C;// works since C can be used in a const generic}impl<constC:usize>MyTraitforS<C>{constC:usize = C;// works since C can be used in a const generic// const C: usize = C + 1; // doesn't work without `#![feature(generic_const_exprs)]`}pubstructS2<T:MyTrait>([u8;T::C]);// works, since C has #[usable_in_const_generic]pubstructS3<T:MyTrait>([u8;T::C2]);// works, since C2 also has #[usable_in_const_generic]
the idea is that #[usable_in_const_generic] would be stabilized to allow much more ergonomic use of const generics with associated consts rather than having to use an associated type C = Const<42> instead of const C: usize = 42.
If at some later point const generics no longer need to be restricted (which seems doubtful considering the lack of even theoretical progress on generic_const_exprs in years), then usable_in_const_generic would become a no-op and be (soft-?)deprecated and removed from the next edition.
The text was updated successfully, but these errors were encountered:
👍 I think this is pretty similar to the plan for min_generic_const_exprs, never ended up seeing this until now xd
Going to write a full document outlining the plan for min_generic_const_exprs soon that also outlines all the issues with generic_const_exprs and why we need to do something like this. (basically a much more filled out design doc)
Wish I had gotten around to reading this beforehand though because we'd have been able to start on this a few months ago instead lol Thanks for the idea regardless, it's a good one and solves a lot of problems with generic_const_exprs 🎉
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
originally on Rust Internals
I think it may be a good idea to have a MVP for allowing associated constants to be used in const generics, basically we'd introduce a attribute
#[usable_in_const_generic]
(to be bikesheded) where all associated constants decorated with that attribute are restricted such that they're usable in const generics:the idea is that
#[usable_in_const_generic]
would be stabilized to allow much more ergonomic use of const generics with associated consts rather than having to use an associatedtype C = Const<42>
instead ofconst C: usize = 42
.If at some later point const generics no longer need to be restricted (which seems doubtful considering the lack of even theoretical progress on generic_const_exprs in years), then
usable_in_const_generic
would become a no-op and be (soft-?)deprecated and removed from the next edition.The text was updated successfully, but these errors were encountered: