Skip to content

Commit b295e09

Browse files
oli-obkmark-i-m
authored andcommitted
Explain our stability attributes
1 parent 9256cce commit b295e09

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- [Using `compiletest` + commands to control test execution](./compiletest.md)
1616
- [Walkthrough: a typical contribution](./walkthrough.md)
1717
- [Implementing new features](./implementing_new_features.md)
18+
- [Stability attributes](./stability.md)
1819
- [Stabilizing Features](./stabilization_guide.md)
1920
- [Debugging the Compiler](./compiler-debugging.md)
2021
- [Profiling the compiler](./profiling.md)

src/stability.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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

Comments
 (0)