@@ -92,24 +92,32 @@ and the associated
92
92
93
93
## allow_internal_unstable
94
94
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
96
96
site. To work around not being able to use unstable things in the standard
97
97
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,
108
116
because the addresses of things are nondeterministic and often unknown at
109
117
compile-time.
110
118
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 ` .
113
121
114
122
## staged_api
115
123
0 commit comments