|
| 1 | +# Stability |
| 2 | + |
| 3 | +This section is about the stability attributes and schemes that allow stable APIs to use unstable |
| 4 | +APIs internally in the rustc standard library. |
| 5 | + |
| 6 | +For instructions on stabilizing a feature see [Stabilizing Features](./stabilization_guide.md). |
| 7 | + |
| 8 | +# unstable |
| 9 | + |
| 10 | +The `#[unstable(feature = "foo", issue = "1234", reason = "lorem ipsum")]` attribute explicitly |
| 11 | +marks an item as unstable. This infects all sub-items, where the attribute doesn't have to be |
| 12 | +reapplied. So if you apply this to a module, all items in the module will be unstable. |
| 13 | + |
| 14 | +# stable |
| 15 | + |
| 16 | +The `#[stable(feature = "foo", "since = "1.420.69")]` attribute explicitly marks an item as |
| 17 | +stabilized. In order to do this follow the instructions in |
| 18 | +[Stabilizing Features](./stabilization_guide.md). |
| 19 | + |
| 20 | +Note that stable functions may use unstable things in their body. |
| 21 | + |
| 22 | +# allow_internal_unstable |
| 23 | + |
| 24 | +Macros, compiler desugarings and `const fn`s expose their bodies to the call site. In order to |
| 25 | +work around not being able to use unstable things in the standard libraries macros, there's the |
| 26 | +`#[allow_internal_unstable(feature1, feature2)]` attribute that whitelists the given features for |
| 27 | +usage in stable macros or `const fn`s. |
| 28 | + |
| 29 | +Note that `const fn`s are even more special in this regard. You can't just whitelist any feature, |
| 30 | +the features need an implementation in `qualify_min_const_fn.rs`. For example the `const_fn_union` |
| 31 | +feature gate allows accessing fields of unions inside stable `const fn`s. The rules for when it's |
| 32 | +ok to use such a feature gate are that behavior matches the runtime behavior of the same code |
| 33 | +(see also https://www.ralfj.de/blog/2018/07/19/const.html). This means that you may not create a |
| 34 | +`const fn` that e.g. transmutes a memory address to an integer, because the addresses of things |
| 35 | +are nondeterministic and often unknown at compile-time. |
0 commit comments