Skip to content

Commit be1d3c4

Browse files
oli-obkRalfJungJohnTitorcamelid
authored
We stopped using allow_internal_unstable a while ago (#1142)
Co-authored-by: Ralf Jung <[email protected]> Co-authored-by: Yuki Okushi <[email protected]> Co-authored-by: Noah Lev <[email protected]>
1 parent 3a63b12 commit be1d3c4

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

src/stability.md

+21-13
Original file line numberDiff line numberDiff line change
@@ -92,24 +92,32 @@ and the associated
9292

9393
## allow_internal_unstable
9494

95-
Macros, compiler desugarings and `const fn`s expose their bodies to the call
95+
Macros and compiler desugarings expose their bodies to the call
9696
site. To work around not being able to use unstable things in the standard
9797
library's macros, there's the `#[allow_internal_unstable(feature1, feature2)]`
98-
attribute that allows the given features to be used in stable macros or
99-
`const fn`s.
100-
101-
Note that `const fn`s are even more special in this regard. You can't just
102-
allow any feature, the features need an implementation in
103-
`qualify_min_const_fn.rs`. For example the `const_fn_union` feature gate allows
104-
accessing fields of unions inside stable `const fn`s. The rules for when it's
105-
ok to use such a feature gate are that behavior matches the runtime behavior of
106-
the same code (see also [this blog post][blog]). This means that you may not
107-
create a `const fn` that e.g. transmutes a memory address to an integer,
98+
attribute that allows the given features to be used in stable macros.
99+
100+
## rustc_allow_const_fn_unstable
101+
102+
`const fn`, while not directly exposing their body to the world, are going to get
103+
evaluated at compile time in stable crates. If their body does something const-unstable,
104+
that could lock us into certain features indefinitely by accident. Thus no unstable const
105+
features are allowed inside stable `const fn`.
106+
107+
However, sometimes we do know that a feature will get
108+
stabilized, just not when, or there is a stable (but e.g. runtime-slow) workaround, so we
109+
could always fall back to some stable version if we scrapped the unstable feature.
110+
In those cases, the rustc_allow_const_fn_unstable attribute can be used to allow some
111+
unstable features in the body of a stable `const fn`.
112+
113+
You also need to take care to uphold the `const fn` invariant that calling it at runtime and
114+
compile-time needs to behave the same (see also [this blog post][blog]). This means that you
115+
may not create a `const fn` that e.g. transmutes a memory address to an integer,
108116
because the addresses of things are nondeterministic and often unknown at
109117
compile-time.
110118

111-
Always ping @oli-obk, @RalfJung, and @Centril if you are adding more
112-
`allow_internal_unstable` attributes to any `const fn`
119+
Always ping @rust-lang/wg-const-eval if you are adding more
120+
`rustc_allow_const_fn_unstable` attributes to any `const fn`.
113121

114122
## staged_api
115123

0 commit comments

Comments
 (0)