-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Tracking issue for a minimal subset of RFC 911, const fn #53555
Copy link
Copy link
Closed
Labels
B-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.Blocker: Approved by a merged RFC but not yet implemented.B-RFC-implementedBlocker: Approved by a merged RFC and implemented but not stabilized.Blocker: Approved by a merged RFC and implemented but not stabilized.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-langRelevant to the language teamRelevant to the language teamdisposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Metadata
Metadata
Assignees
Labels
B-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.Blocker: Approved by a merged RFC but not yet implemented.B-RFC-implementedBlocker: Approved by a merged RFC and implemented but not stabilized.Blocker: Approved by a merged RFC and implemented but not stabilized.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-langRelevant to the language teamRelevant to the language teamdisposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
This is a tracking issue for the RFC "Const functions and inherent methods" (rust-lang/rfcs#911).
This issue only tracks a minimal subset of the proposal in 911 that we are (hopefully) comfortable with stabilizing. To opt into the minimal subset, use
#![feature(min_const_fn)]. To use the more expansive feature set, you can continue using#![feature(const_fn)]and other associated feature gates.The minimal set will not include items from the following (incomplete) list:
const fns with type parameters with bounds (includingwhereclauses) in scope (including from the parent e.g.impl) other than: lifetimes,Sized, or (the "un"-bound)?SizedThis restriction exists because we are not sure about our story around what bounds mean in a
const fncontext. See RFC: const bounds and methods rfcs#2237,const fnand generics const-eval#1, and https://github.com/Centril/rfc-effects/ for a discussion on this.const fns with argument types or return types that containfnpointers,dyn Trait, orimpl Trait.This is checked recursively.
The restriction ensures that you may not reach a value of these types by any means.
This restriction exists for the same reasons as in 1.
const fns with any operations on floating-point numbers. This is achieved by making any floating-point operation not beconstinsideconst fn.This restriction exists because we are not sure about the story wrt. determinism, achieving the same results on compile-time / run-time (including other machines) and floating points.
using a
const fncall in a pattern, e.g.;anything else that is not currently in
const_fnor constantsusizecast (e.g.*const/mut T -> usize).if/if let/match.loop/while.letand destructuring.union field access.
code requiring
unsafeblocks.Exhaustive list of features supported in
const fnwith#![feature(min_const_fn)]:type parameters where the parameters have any of the following as part of their bounds (either on
whereor directly on the parameters):SizedThis means that
<T: 'a + ?Sized>and<T: 'b + Sized>+<T>are all permitted.Note that
?Sizedis the absence of a constraint when bounds have been fully elaboratedwhich includes adding implicit
Sizedbounds.This entails that permitting
Sized+ lifetimes allows the above examples.This rule also applies to type parameters of items that contain
const fns.arithmetic operators on integers
boolean operators (except for
&&and||which are banned since they are short-circuiting).any kind of aggregate constructor (array,
struct,enum, tuple, ...)calls to other
const fns (methods and functions)index operations on arrays and slices
field accesses on structs and tuples
reading from constants (but not statics, not even taking a reference to a static)
&and*(only dereferencing of references, not raw pointers)casts except for raw pointer to
usizecastsconst unsafe fnis allowed, but the body must consist of safe operations onlyThe bar for stabilizing
const fns in libcore/liballoc/libstd will be that they are writable in stable user code (unless they are wrappers for intrinsics, i.e.size_ofandalign_of). This means that they must work withmin_const_fn.Things to be done before stabilizing:
min_const_fnfeature gate. (Implement themin_const_fnfeature gate #53604)Unresolved questions:
None.
Vocabulary: