Skip to content

Commit 22b26d5

Browse files
authored
Merge pull request #32 from rust-lang/stabilization-update
Update stabilization documentation
2 parents c9fe0ff + 31712ea commit 22b26d5

File tree

1 file changed

+98
-7
lines changed

1 file changed

+98
-7
lines changed
+98-7
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,45 @@
11
# Stabilizing features
22

3-
**Status:** Stub
3+
* **Status:** Current
4+
* **Last Updated:** 2022-05-27
45

56
Feature stabilization involves adding `#[stable]` attributes. They may be introduced alongside new trait impls or replace existing `#[unstable]` attributes.
67

7-
Stabilization goes through the Libs FCP process, which occurs on the [tracking issue](./tracking-issues.md) for the feature.
8+
Stabilization goes through the Libs FCP (Final Comment Period) process, which typically occurs on the [tracking issue](./tracking-issues.md) for the feature.
9+
10+
## When is an FCP appropriate?
11+
12+
Once an unstable feature's API design space (e.g. alternative APIs) has been fully explored with no outstanding concerns, anyone may push for its stabilization.
13+
14+
If you're unsure if a feature is ready for stabilization the first step should be to ask in the relevant tracking issue and get assistance from other participants in that discussion. In some cases the tracking issue may not have many other active participants, so if you're ever having trouble getting any feedback please ping one of the [libs team reviewers](https://github.com/rust-lang/highfive/blob/master/highfive/configs/rust-lang/rust.json) directly to request assistance.
15+
16+
## Stabilization Report
17+
18+
Once a feature is ready for stabilization the first step of the FCP process is writing a stabilization report. Stabilization reports are not mandatory but they are heavily encouraged, and may be mandated by library API team members if they feel it necessary. The purpose of stabilization reports is to help reviewers more quickly make decisions and to simplify the process of documenting stabilized APIs in release notes. Stabilization reports consist of three primary sections, a implementation history, an API summary, and an experience report.
19+
20+
The **Implementation History** section should summarize the initial discussion during the implementation PR, every change that has been made to the feature since the initial implementation, all issues that were raised during the lifetime of the feature, and how they were resolved.
21+
22+
The **API Summary** section should include a precise description of what APIs are being introduced to the standard libraries. This can often be a simple link back to the top level comment if it's up to date, but in some situations it may not be possible to edit the original tracking issue to fix outdated information, such as when the author of the stabilization report is not the author of the tracking issue itself.
23+
24+
The libs team maintains a tool for this called [`cargo unstable-api`](https://github.com/rust-lang/libs-team/tree/main/tools/unstable-api) that can be used to generate these API summaries in some cases. *Note* the current implementation of this tool is fragile and does not work in all cases. We hope to have a more permanent version of this tool in the future that is built ontop of either rustdoc or rustc's own APIs.
25+
26+
The **Experience Report** section should include concrete usecases of users who have wanted to use the feature and who have tested that it works for their needs. The experience report should include a brief summary of the experience of using that feature. Ideally this would include links to commits or branches where the feature was integrated with their project, but this is not a requirement. Alternatively, users can provide usage examples of crates that export an identical API to the one being stabilized.
27+
28+
You can see an example of a stabilization report in [#88581](https://github.com/rust-lang/rust/issues/88581#issuecomment-1054642118).
829

930
## Before writing a PR to stabilize a feature
1031

11-
Check to see if a FCP has completed first. If not, either ping `@rust-lang/libs` or leave a comment asking about the status of the feature.
32+
Check to see if a FCP has completed first. If not, either ping `@rust-lang/libs-api` or leave a comment asking about the status of the feature.
1233

1334
This will save you from opening a stabilization PR and having it need regular rebasing while the FCP process runs its course.
1435

15-
## Writing a stabilization PR
36+
## Partial Stabilizations
37+
38+
When you only wish to stabilize a subset of an existing feature you should skip creating a new tracking issue and instead create a partial stabilization PR for the subset of the feature being stabilized.
1639

17-
- Replace any `#[unstable]` attributes for the given feature with stable ones. The value of the `since` field is usually the current `nightly` version.
18-
- Remove any `#![feature()]` attributes that were previously required.
19-
- Submit a PR with a stabilization report.
40+
If you're unsure if a feature is ready for partial stabilization the first step should be to ask in the relevant tracking issue and get assistance from other participants in that discussion. In some cases the tracking issue may not have many other active participants, so if you're ever having trouble getting any feedback please ping one of the [libs team reviewers](https://github.com/rust-lang/highfive/blob/master/highfive/configs/rust-lang/rust.json) directly to request assistance.
41+
42+
You can see an example of partially stabilizing a feature with tracking issue [#71146](https://github.com/rust-lang/rust/issues/71146) and partial stabilization PR [#94640](https://github.com/rust-lang/rust/pull/94640).
2043

2144
## When there's `const` involved
2245

@@ -25,3 +48,71 @@ Const functions can be stabilized in a PR that replaces `#[rustc_const_unstable]
2548
Check whether the function internally depends on other unstable `const` functions through `#[allow_internal_unstable]` attributes and consider how the function could be implemented if its internally unstable calls were removed. See the _Stability attributes_ page for more details on `#[allow_internal_unstable]`.
2649

2750
Where `unsafe` and `const` is involved, e.g., for operations which are "unconst", that the const safety argument for the usage also be documented. That is, a `const fn` has additional determinism (e.g. run-time/compile-time results must correspond and the function's output only depends on its inputs...) restrictions that must be preserved, and those should be argued when `unsafe` is used.
51+
52+
## Stabilization PR for Library Features
53+
54+
Once we have decided to stabilize a feature, we need to have a PR that actually makes that stabilization happen. These kinds of PRs are a great way to get involved in Rust, as they're typically small -- just updating attributes.
55+
56+
Here is a general guide to how to stabilize a feature -- every feature is different, of course, so some features may require steps beyond what this guide talks about.
57+
58+
### Update the stability attributes on the items
59+
60+
Library items are marked unstable via the `#[unstable]` attribute, like this:
61+
62+
```rust,ignore
63+
#[unstable(feature = "total_cmp", issue = "72599")]
64+
pub fn total_cmp(&self, other: &Self) -> crate::cmp::Ordering { ... }
65+
```
66+
67+
You'll need to change that to a `#[stable]` attribute with a version:
68+
69+
```rust,ignore
70+
#[stable(feature = "total_cmp", since = "1.61.0")]
71+
```
72+
73+
Note that, the version number is updated to be the version number of the stable release where this feature will appear. This can be found by consulting [`src/version`](https://github.com/rust-lang/rust/blob/master/src/version) on the current master branch of `rust-lang/rust`.
74+
75+
### Remove feature gates from doctests
76+
77+
All the doctests on the items being stabilized will be enabling the unstable feature, so now that it's stable those attributes are no longer needed and should be removed.
78+
79+
`````diff
80+
/// # Examples
81+
///
82+
/// ```
83+
-/// #![feature(total_cmp)]
84+
-///
85+
/// assert_eq!(0.0_f32.total_cmp(&-0.0), std::cmp::Ordering::Greater);
86+
/// ```
87+
`````
88+
89+
The most obvious place to find these is on the item itself, but it's worth searching the whole library. Often you'll find other unstable methods that were also using it in their tests.
90+
91+
### Remove feature gates from the compiler
92+
93+
The compiler builds with nightly features allowed, so you may find uses of the feature there as well. These also need to be removed.
94+
95+
```diff
96+
#![feature(once_cell)]
97+
#![feature(never_type)]
98+
-#![feature(total_cmp)]
99+
#![feature(trusted_step)]
100+
#![feature(try_blocks)]
101+
```
102+
103+
## Stabilization PR Checklist
104+
105+
To stabilize a feature, follow these steps:
106+
107+
0. Create a stabiliation report in the tracking issue for the feature being stabilized.
108+
0. (Optional) For partial stabilizations, create a new partial stabilization PR for the subset of the issue being stabilized.
109+
0. Ask a **@rust-lang/libs-api** member to start an FCP on the tracking issue and wait for the FCP to complete (with `disposition-merge`).
110+
0. Change `#[unstable(...)]` to `#[stable(since = "version")]`. `version` should be the *current nightly*, i.e. stable+2. You can see which version is the current nightly in [`src/version`](https://github.com/rust-lang/rust/blob/master/src/version) on the master branch of `rust-lang/rust`.
111+
0. Remove `#![feature(...)]` from any test or doc-test for this API. If the feature is used in the compiler or tools, remove it from there as well.
112+
0. If applicable, change `#[rustc_const_unstable(...)]` to `#[rustc_const_stable(since = "version")]`.
113+
0. Open a PR against `rust-lang/rust`.
114+
- Add the appropriate labels: `@rustbot modify labels: +T-libs-api`.
115+
- Link to the tracking issue by adding "Closes #XXXXX".
116+
117+
You can see an example of stabilizing a feature with [tracking issue #81656 with FCP](https://github.com/rust-lang/rust/issues/81656) and the associated [implementation PR #84642](https://github.com/rust-lang/rust/pull/84642).
118+

0 commit comments

Comments
 (0)