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
{{ message }}
Repository navigation
Require explicit stabilization of the constness of functions #58775
if you have an unstable const function and you stabilize it, you automatically stabilize the constness, too.
if you have a stable non-const function, adding const to it will automatically stabilize the constness
You can opt-out of the stability of the constness of a function via rustc_const_unstable
What's missing is the ability to explicitly mark the constness as stable, just like we have an explicit scheme to mark items as stable. This would prevent accidental stablization of any constness. Not that any has happened so far, but #58750 (comment) made me realize that it's not always easy to gauge the stability of constness.
It might also be helpful if documentation showed since when the constness has been stabilized.
I have an idea for an alternative without introducing even more attributes: Add a const_since parameter to #[stable(..)]. I don't know if you can cover all mentioned cases with it, but I wanted to share thoughts once.
It would probably be simpler and less error-prone to add modifiers to #[rustc_stable] and #[rustc_unstabe] than to introduce new attributes for const stability.
We don't have to care, as we cannot stabilize a const fn without the non-const fn
I don't think this actually requires explicit stabilization in full. You do reduce some of the risk and it serves as better documentation, but you also do not cover the case when there's no #[stable(..)] for a stably exposed function. However, this is a general problem with #[stable(..)] not exclusive to const fns.
As long as we are cognizant of what problems we solve and which we don't, then I think your solution will work well.
Activity
Centril commentedon Feb 27, 2019
cc #57562 (comment)
cc @rust-lang/libs @rust-lang/rustdoc
So... re. semantics, I think
#[const_stable(..)]should have the semantics that:#[const_stable(..)]is attached:staged_api=> errorconst fn=> error#[const_unstable(..)]attached => contradiction! => error#[stable(..)]is not attached => errormin_const_fnstaged_api=> same semantics as today.const fn=> same semantics as today.#[const_unstable(..)]attached => same semantics as today.#[stable(..)]is not attached => ???-- What do we do for internal APIs?
-- Do we have protections against accidental omissions of
#[stable(..)]?min_const_fnIs there any case I missed?
TimDiekmann commentedon Feb 27, 2019
I have an idea for an alternative without introducing even more attributes: Add a
const_sinceparameter to#[stable(..)]. I don't know if you can cover all mentioned cases with it, but I wanted to share thoughts once.petrochenkov commentedon Feb 27, 2019
It would probably be simpler and less error-prone to add modifiers to
#[rustc_stable]and#[rustc_unstabe]than to introduce new attributes for const stability.Centril commentedon Feb 27, 2019
You'd also need a way to name the feature-gate, not just the equivalent of
since, e.g.If
const_featureis omitted, we can assume the feature gate name is the same as the usual one.This hasn't really addressed the ??? part tho; only repainted the syntax.
TimDiekmann commentedon Feb 28, 2019
We don't have to care, as we cannot stabilize a
const fnwithout the non-constfnI'd go this way:
#[stable(..)]is attached:const_since:const fn=> errormin_const_fn=> errorconst_feature:const_since!=since=> errorfeatureas gateconst_feature=> success => usesconst_featureas gate#[unstable(const_feature = "...")]=> successEvery other case should have been captured by
#[stable(..)]/#[unstable(..)].Examples:
Centril commentedon Feb 28, 2019
I don't think this actually requires explicit stabilization in full. You do reduce some of the risk and it serves as better documentation, but you also do not cover the case when there's no
#[stable(..)]for a stably exposed function. However, this is a general problem with#[stable(..)]not exclusive toconst fns.As long as we are cognizant of what problems we solve and which we don't, then I think your solution will work well.
RalfJung commentedon Sep 21, 2020
@oli-obk isn't this resolved by
#[rustc_const_stable]?oli-obk commentedon Sep 21, 2020
Yes