]> git.proxmox.com Git - rustc.git/blame - src/doc/rustc-guide/src/stabilization_guide.md
New upstream version 1.36.0+dfsg1
[rustc.git] / src / doc / rustc-guide / src / stabilization_guide.md
CommitLineData
532ac7d7
XL
1# Request for stabilization
2
3Once an unstable feature has been well-tested with no outstanding
4concern, anyone may push for its stabilization. It involves the
5following steps.
6
7- Documentation PRs
8- Write a stabilization report
9- FCP
10- Stabilization PR
11
12## Documentation PRs
13
14<a name="updating-documentation"></a>
15
16If any documentation for this feature exists, it should be
17in the [`Unstable Book`], located at [`src/doc/unstable-book`].
18If it exists, the page for the feature gate should be removed.
19
20If there was documentation there, integrating it into the
21existing documentation is needed.
22
23If there wasn't documentation there, it needs to be added.
24
25Places that may need updated documentation:
26
27- [The Reference]: This must be updated, in full detail.
28- [The Book]: This may or may not need updating, depends.
29 If you're not sure, please open an issue on this repository
30 and it can be discussed.
31- standard library documentation: As needed. Language features
32 often don't need this, but if it's a feature that changes
33 how good examples are written, such as when `?` was added
34 to the language, updating examples is important.
35- [Rust by Example]: As needed.
36
37Prepare PRs to update documentations invovling this new feature
38for repositories mentioned above. Maintainers of these repositories
39will keep these PRs open until the whole stabilization process
40has completed. Meanwhile, we can proceed to the next step.
41
42## Write a stabilization report
43
44Find the tracking issue of the feature, and create a short
45stabilization report. Essentially this would be a brief summary
46of the feature plus some links to test cases showing it works
47as expected, along with a list of edge cases that came up and
48and were considered. This is a minimal "due diligence" that
49we do before stabilizing.
50
51The report should contain:
52
53- A summary, showing examples (e.g. code snippets) what is
54 enabled by this feature.
55- Links to test cases in our test suite regarding this feature
56 and describe the feature's behavior on encountering edge cases.
57- Links to the documentations (the PRs we have made in the
58 previous steps).
59- Any other relevant information(Examples of such reports can
60 be found in rust-lang/rust#44494 and rust-lang/rust#28237).
61- The resolutions of any unresolved questions if the stabilization
62 is for an RFC.
63
64## FCP
65
66If any member of the team responsible for tracking this
67feature agrees with stabilizing this feature, they will
68start the FCP (final-comment-period) process by commenting
69
70```bash
71@rfcbot fcp merge
72```
73
74The rest of the team members will review the proposal. If the final
75decision is to stabilize, we proceed to do the actual code modification.
76
77## Stabilization PR
78
79Once we have decided to stabilize a feature, we need to have
80a PR that actually makes that stabilization happen. These kinds
81of PRs are a great way to get involved in Rust, as they take
82you on a little tour through the source code.
83
84Here is a general guide to how to stabilize a feature --
85every feature is different, of course, so some features may
86require steps beyond what this guide talks about.
87
88Note: Before we stabilize any feature, it's the rule that it
89should appear in the documentation.
90
91### Updating the feature-gate listing
92
93There is a central listing of feature-gates in
94[`src/libsyntax/feature_gate.rs`]. Search for the `declare_features!`
95macro. There should be an entry for the feature you are aiming
96to stabilize, something like (this example is taken from
97[rust-lang/rust#32409]:
98
99```rust,ignore
100// pub(restricted) visibilities (RFC 1422)
101(active, pub_restricted, "1.9.0", Some(32409)),
102```
103
104The above line should be moved down to the area for "accepted"
105features, declared below in a separate call to `declare_features!`.
106When it is done, it should look like:
107
108```rust,ignore
109// pub(restricted) visibilities (RFC 1422)
110(accepted, pub_restricted, "1.31.0", Some(32409)),
111// note that we changed this
112```
113
114Note that, the version number is updated to be the version number
115of the stable release where this feature will appear. This can be
116found by consulting [the forge](https://forge.rust-lang.org/), which will guide
117you the next stable release number. You want to add 1 to that,
118because the code that lands today will become go into beta on that
119date, and then become stable after that. So, at the time of this
120writing, the next stable release (i.e. what is currently beta) was
1211.30.0, hence I wrote 1.31.0 above.
122
123### Removing existing uses of the feature-gate
124
125Next search for the feature string (in this case, `pub_restricted`)
126in the codebase to find where it appears. Change uses of
127`#![feature(XXX)]` from the `libstd` and any rustc crates to be
128`#![cfg_attr(stage0, feature(XXX))]`. This includes the feature-gate
129only for stage0, which is built using the current beta (this is
130needed because the feature is still unstable in the current beta).
131
132Also, remove those strings from any tests. If there are tests
133specifically targeting the feature-gate (i.e., testing that the
134feature-gate is required to use the feature, but nothing else),
135simply remove the test.
136
137### Do not require the feature-gate to use the feature
138
139Most importantly, remove the code which flags an error if the
140feature-gate is not present (since the feature is now considered
141stable). If the feature can be detected because it employs some
142new syntax, then a common place for that code to be is in the
143same `feature_gate.rs`. For example, you might see code like this:
144
145```rust,ignore
146gate_feature_post!(&self, pub_restricted, span,
147 "`pub(restricted)` syntax is experimental");
148```
149
150This `gate_feature_post!` macro prints an error if the
151`pub_restricted` feature is not enabled. It is not needed
152now that `#[pub_restricted]` is stable.
153
154For more subtle features, you may find code like this:
155
156```rust,ignore
157if self.tcx.sess.features.borrow().pub_restricted { /* XXX */ }
158```
159
160This `pub_restricted` field (obviously named after the feature)
161would ordinarily be false if the feature flag is not present
162and true if it is. So transform the code to assume that the field
163is true. In this case, that would mean removing the `if` and
164leaving just the `/* XXX */`.
165
166```rust,ignore
167if self.tcx.sess.features.borrow().pub_restricted { /* XXX */ }
168becomes
169/* XXX */
170
171if self.tcx.sess.features.borrow().pub_restricted && something { /* XXX */ }
172 becomes
173if something { /* XXX */ }
174```
175
176[rust-lang/rust#32409]:https://github.com/rust-lang/rust/issues/32409
177[`src/libsyntax/feature_gate.rs`]:https://doc.rust-lang.org/nightly/nightly-rustc/syntax/feature_gate/index.html
178[The Reference]: https://github.com/rust-lang-nursery/reference
179[The Book]: https://github.com/rust-lang/book
180[Rust by Example]: https://github.com/rust-lang/rust-by-example
181[`Unstable Book`]: https://doc.rust-lang.org/unstable-book/index.html
182[`src/doc/unstable-book`]: https://github.com/rust-lang/rust/tree/master/src/doc/unstable-book