Skip to content

Commit f9a3889

Browse files
committed
sembr src/stability.md
1 parent 9fddf7d commit f9a3889

1 file changed

Lines changed: 58 additions & 34 deletions

File tree

src/stability.md

Lines changed: 58 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,68 +3,79 @@
33
This section is about the stability attributes and schemes that allow stable
44
APIs to use unstable APIs internally in the rustc standard library.
55

6-
**NOTE**: this section is for *library* features, not *language* features. For instructions on
6+
**NOTE**: this section is for *library* features, not *language* features.
7+
For instructions on
78
stabilizing a language feature see [Stabilizing Features](./stabilization-guide.md).
89

910
## unstable
1011

1112
The `#[unstable(feature = "foo", issue = "1234", reason = "lorem ipsum")]`
12-
attribute explicitly marks an item as unstable. Items that are marked as
13+
attribute explicitly marks an item as unstable.
14+
Items that are marked as
1315
"unstable" cannot be used without a corresponding `#![feature]` attribute on
14-
the crate, even on a nightly compiler. This restriction only applies across
15-
crate boundaries, unstable items may be used within the crate that defines
16-
them.
16+
the crate, even on a nightly compiler.
17+
This restriction only applies across
18+
crate boundaries, unstable items may be used within the crate that defines them.
1719

18-
The `issue` field specifies the associated GitHub [issue number]. This field is
19-
required and all unstable features should have an associated tracking issue. In
20-
rare cases where there is no sensible value `issue = "none"` is used.
20+
The `issue` field specifies the associated GitHub [issue number].
21+
This field is
22+
required and all unstable features should have an associated tracking issue.
23+
In rare cases where there is no sensible value `issue = "none"` is used.
2124

2225
The `unstable` attribute infects all sub-items, where the attribute doesn't
23-
have to be reapplied. So if you apply this to a module, all items in the module
24-
will be unstable.
26+
have to be reapplied.
27+
So if you apply this to a module, all items in the module will be unstable.
2528

2629
If you rename a feature, you can add `old_name = "old_name"` to produce a
2730
useful error message.
2831

2932
You can make specific sub-items stable by using the `#[stable]` attribute on
30-
them. The stability scheme works similarly to how `pub` works. You can have
33+
them.
34+
The stability scheme works similarly to how `pub` works.
35+
You can have
3136
public functions of nonpublic modules and you can have stable functions in
3237
unstable modules or vice versa.
3338

3439
Previously, due to a [rustc bug], stable items inside unstable modules were
3540
available to stable code in that location.
3641
As of <!-- date-check --> September 2024, items with [accidentally stabilized
3742
paths] are marked with the `#[rustc_allowed_through_unstable_modules]` attribute
38-
to prevent code dependent on those paths from breaking. Do *not* add this attribute
43+
to prevent code dependent on those paths from breaking.
44+
Do *not* add this attribute
3945
to any more items unless that is needed to avoid breaking changes.
4046

4147
The `unstable` attribute may also have the `soft` value, which makes it a
42-
future-incompatible deny-by-default lint instead of a hard error. This is used
43-
by the `bench` attribute which was accidentally accepted in the past. This
44-
prevents breaking dependencies by leveraging Cargo's lint capping.
48+
future-incompatible deny-by-default lint instead of a hard error.
49+
This is used
50+
by the `bench` attribute which was accidentally accepted in the past.
51+
This prevents breaking dependencies by leveraging Cargo's lint capping.
4552

4653
[issue number]: https://github.com/rust-lang/rust/issues
4754
[rustc bug]: https://github.com/rust-lang/rust/issues/15702
4855
[accidentally stabilized paths]: https://github.com/rust-lang/rust/issues/113387
4956

5057
## stable
5158
The `#[stable(feature = "foo", since = "1.420.69")]` attribute explicitly
52-
marks an item as stabilized. Note that stable functions may use unstable things in their body.
59+
marks an item as stabilized.
60+
Note that stable functions may use unstable things in their body.
5361

5462
## rustc_const_unstable
5563

5664
The `#[rustc_const_unstable(feature = "foo", issue = "1234", reason = "lorem
57-
ipsum")]` has the same interface as the `unstable` attribute. It is used to mark
58-
`const fn` as having their constness be unstable. This is only needed in rare cases:
65+
ipsum")]` has the same interface as the `unstable` attribute.
66+
It is used to mark `const fn` as having their constness be unstable.
67+
This is only needed in rare cases:
5968
- If a `const fn` makes use of unstable language features or intrinsics.
6069
(The compiler will tell you to add the attribute if you run into this.)
6170
- If a `const fn` is `#[stable]` but not yet intended to be const-stable.
6271
- To change the feature gate that is required to call a const-unstable intrinsic.
6372

6473
Const-stability differs from regular stability in that it is *recursive*: a
65-
`#[rustc_const_unstable(...)]` function cannot even be indirectly called from stable code. This is
74+
`#[rustc_const_unstable(...)]` function cannot even be indirectly called from stable code.
75+
This is
6676
to avoid accidentally leaking unstable compiler implementation artifacts to stable code or locking
67-
us into the accidental quirks of an incomplete implementation. See the rustc_const_stable_indirect
77+
us into the accidental quirks of an incomplete implementation.
78+
See the rustc_const_stable_indirect
6879
and rustc_allow_const_fn_unstable attributes below for how to fine-tune this check.
6980

7081
## rustc_const_stable
@@ -75,7 +86,8 @@ a `const fn` as having its constness be `stable`.
7586
## rustc_const_stable_indirect
7687

7788
The `#[rustc_const_stable_indirect]` attribute can be added to a `#[rustc_const_unstable(...)]`
78-
function to make it callable from `#[rustc_const_stable(...)]` functions. This indicates that the
89+
function to make it callable from `#[rustc_const_stable(...)]` functions.
90+
This indicates that the
7991
function is ready for stable in terms of its implementation (i.e., it doesn't use any unstable
8092
compiler features); the only reason it is not const-stable yet are API concerns.
8193

@@ -105,7 +117,8 @@ To stabilize a feature, follow these steps:
105117
1. Ask a **@T-libs-api** member to start an FCP on the tracking issue and wait for
106118
the FCP to complete (with `disposition-merge`).
107119
2. Change `#[unstable(...)]` to `#[stable(since = "CURRENT_RUSTC_VERSION")]`.
108-
3. Remove `#![feature(...)]` from any test or doc-test for this API. If the feature is used in the
120+
3. Remove `#![feature(...)]` from any test or doc-test for this API.
121+
If the feature is used in the
109122
compiler or tools, remove it from there as well.
110123
4. If this is a `const fn`, add `#[rustc_const_stable(since = "CURRENT_RUSTC_VERSION")]`.
111124
Alternatively, if this is not supposed to be const-stabilized yet,
@@ -121,14 +134,15 @@ and the associated
121134

122135
## allow_internal_unstable
123136

124-
Macros and compiler desugarings expose their bodies to the call
125-
site. To work around not being able to use unstable things in the standard
137+
Macros and compiler desugarings expose their bodies to the call site.
138+
To work around not being able to use unstable things in the standard
126139
library's macros, there's the `#[allow_internal_unstable(feature1, feature2)]`
127140
attribute that allows the given features to be used in stable macros.
128141

129142
Note that if a macro is used in const context and generates a call to a
130143
`#[rustc_const_unstable(...)]` function, that will *still* be rejected even with
131-
`allow_internal_unstable`. Add `#[rustc_const_stable_indirect]` to the function to ensure the macro
144+
`allow_internal_unstable`.
145+
Add `#[rustc_const_stable_indirect]` to the function to ensure the macro
132146
cannot accidentally bypass the recursive const stability checks.
133147

134148
## rustc_allow_const_fn_unstable
@@ -138,12 +152,14 @@ indirectly.
138152

139153
However, sometimes we do know that a feature will get stabilized, just not when, or there is a
140154
stable (but e.g. runtime-slow) workaround, so we could always fall back to some stable version if we
141-
scrapped the unstable feature. In those cases, the `[rustc_allow_const_fn_unstable(feature1,
155+
scrapped the unstable feature.
156+
In those cases, the `[rustc_allow_const_fn_unstable(feature1,
142157
feature2)]` attribute can be used to allow some unstable features in the body of a stable (or
143158
indirectly stable) `const fn`.
144159

145160
You also need to take care to uphold the `const fn` invariant that calling it at runtime and
146-
compile-time needs to behave the same (see also [this blog post][blog]). This means that you
161+
compile-time needs to behave the same (see also [this blog post][blog]).
162+
This means that you
147163
may not create a `const fn` that e.g. transmutes a memory address to an integer,
148164
because the addresses of things are nondeterministic and often unknown at
149165
compile-time.
@@ -159,7 +175,8 @@ Any crate that uses the `stable` or `unstable` attributes must include the
159175
## deprecated
160176

161177
Deprecations in the standard library are nearly identical to deprecations in
162-
user code. When `#[deprecated]` is used on an item, it must also have a `stable`
178+
user code.
179+
When `#[deprecated]` is used on an item, it must also have a `stable`
163180
or `unstable `attribute.
164181

165182
`deprecated` has the following form:
@@ -172,28 +189,35 @@ or `unstable `attribute.
172189
)]
173190
```
174191

175-
The `suggestion` field is optional. If given, it should be a string that can be
176-
used as a machine-applicable suggestion to correct the warning. This is
192+
The `suggestion` field is optional.
193+
If given, it should be a string that can be
194+
used as a machine-applicable suggestion to correct the warning.
195+
This is
177196
typically used when the identifier is renamed, but no other significant changes
178-
are necessary. When the `suggestion` field is used, you need to have
197+
are necessary.
198+
When the `suggestion` field is used, you need to have
179199
`#![feature(deprecated_suggestion)]` at the crate root.
180200

181201
Another difference from user code is that the `since` field is actually checked
182-
against the current version of `rustc`. If `since` is in a future version, then
202+
against the current version of `rustc`.
203+
If `since` is in a future version, then
183204
the `deprecated_in_future` lint is triggered which is default `allow`, but most
184205
of the standard library raises it to a warning with
185206
`#![warn(deprecated_in_future)]`.
186207

187208
## unstable_feature_bound
188-
The `#[unstable_feature_bound(foo)]` attribute can be used together with `#[unstable]` attribute to mark an `impl` of stable type and stable trait as unstable. In std/core, an item annotated with `#[unstable_feature_bound(foo)]` can only be used by another item that is also annotated with `#[unstable_feature_bound(foo)]`. Outside of std/core, using an item with `#[unstable_feature_bound(foo)]` requires the feature to be enabled with `#![feature(foo)]` attribute on the crate.
209+
The `#[unstable_feature_bound(foo)]` attribute can be used together with `#[unstable]` attribute to mark an `impl` of stable type and stable trait as unstable.
210+
In std/core, an item annotated with `#[unstable_feature_bound(foo)]` can only be used by another item that is also annotated with `#[unstable_feature_bound(foo)]`.
211+
Outside of std/core, using an item with `#[unstable_feature_bound(foo)]` requires the feature to be enabled with `#![feature(foo)]` attribute on the crate.
189212

190213
Currently, the items that can be annotated with `#[unstable_feature_bound]` are:
191214
- `impl`
192215
- free function
193216
- trait
194217

195218
## renamed and removed features
196-
Unstable features can get renamed and removed. If you rename a feature, you can add `old_name = "old_name"` to the `#[unstable]` attribute.
219+
Unstable features can get renamed and removed.
220+
If you rename a feature, you can add `old_name = "old_name"` to the `#[unstable]` attribute.
197221
If you remove a feature, the `#!unstable_removed(feature = "foo", reason = "brief description", link = "link", since = "1.90.0")`
198222
attribute should be used to produce a good error message for users of the removed feature.
199223

0 commit comments

Comments
 (0)