You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/implementing_new_features.md
+48-18Lines changed: 48 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,53 +11,73 @@ See also [the Rust Language Design Team's procedures][lang-propose] for proposin
11
11
12
12
## The @rfcbot FCP process
13
13
14
-
When the change is small, uncontroversial, non-breaking, and does not affect the stable language in any user-observable ways or add any new unstable features, then it can be done with just writing a PR and getting an r+ from someone who knows that part of the code. However, if not, more must be done. Even for compiler-internal work, it would be a bad idea to push a controversial change without consensus from the rest of the team (both in the "distributed system" sense to make sure you don't break anything you don't know about, and in the social sense to avoid PR fights).
14
+
When the change is small, uncontroversial, non-breaking, and does not affect the stable language in any user-observable ways or add any new unstable features, then it can be done with just writing a PR and getting an r+ from someone who knows that part of the code.
15
+
However, if not, more must be done.
16
+
Even for compiler-internal work, it would be a bad idea to push a controversial change without consensus from the rest of the team (both in the "distributed system" sense to make sure you don't break anything you don't know about, and in the social sense to avoid PR fights).
15
17
16
-
For changes that need the consensus of a team, we us the process of proposing a final comment period (FCP). If you're not on the relevant team (and thus don't have @rfcbot permissions), ask someone who is to start one; unless they have a concern themselves, they should.
18
+
For changes that need the consensus of a team, we us the process of proposing a final comment period (FCP).
19
+
If you're not on the relevant team (and thus don't have @rfcbot permissions), ask someone who is to start one;
20
+
unless they have a concern themselves, they should.
17
21
18
-
The FCP process is only needed if you need consensus – if no processes require consensus for your change and you don't think anyone would have a problem with it, it's OK to rely on only an r+. For example, it is OK to add or modify unstable command-line flags or attributes in the reserved compiler-internal `rustc_` namespace without an FCP for compiler development or standard library use, as long as you don't expect them to be in wide use in the nightly ecosystem. Some teams have lighter weight processes that they use in scenarios like this; for example, the compiler team recommends filing a Major Change Proposal ([MCP][mcp]) as a lightweight way to garner support and feedback without requiring full consensus.
22
+
The FCP process is only needed if you need consensus – if no processes require consensus for your change and you don't think anyone would have a problem with it, it's OK to rely on only an r+.
23
+
For example, it is OK to add or modify unstable command-line flags or attributes in the reserved compiler-internal `rustc_` namespace without an FCP for compiler development or standard library use, as long as you don't expect them to be in wide use in the nightly ecosystem.
24
+
Some teams have lighter weight processes that they use in scenarios like this;
25
+
for example, the compiler team recommends filing a Major Change Proposal ([MCP][mcp]) as a lightweight way to garner support and feedback without requiring full consensus.
You don't need to have the implementation fully ready for r+ to propose an FCP, but it is generally a good idea to have at least a proof of concept so that people can see what you are talking about.
23
30
24
-
When an FCP is proposed, it requires all members of the team to sign off on the FCP. After they all do so, there's a 10-day-long "final comment period" (hence the name) where everybody can comment, and if no concerns are raised, the PR/issue gets FCP approval.
31
+
When an FCP is proposed, it requires all members of the team to sign off on the FCP.
32
+
After they all do so, there's a 10-day-long "final comment period" (hence the name) where everybody can comment, and if no concerns are raised, the PR/issue gets FCP approval.
25
33
26
34
## The logistics of writing features
27
35
28
36
There are a few "logistical" hoops you might need to go through in order to implement a feature in a working way.
29
37
30
38
### Warning Cycles
31
39
32
-
In some cases, a feature or bugfix might break some existing programs in some edge cases. In that case, you'll want to do a crater run to assess the impact and possibly add a future-compatibility lint, similar to those used for [edition-gated lints](diagnostics.md#edition-gated-lints).
40
+
In some cases, a feature or bugfix might break some existing programs in some edge cases.
41
+
In that case, you'll want to do a crater run to assess the impact and possibly add a future-compatibility lint, similar to those used for [edition-gated lints](diagnostics.md#edition-gated-lints).
33
42
34
43
### Stability
35
44
36
-
We [value the stability of Rust]. Code that works and runs on stable should (mostly) not break. Because of that, we don't want to release a feature to the world with only team consensus and code review - we want to gain real-world experience on using that feature on nightly, and we might want to change the feature based on that experience.
45
+
We [value the stability of Rust].
46
+
Code that works and runs on stable should (mostly) not break.
47
+
Because of that, we don't want to release a feature to the world with only team consensus and code review - we want to gain real-world experience on using that feature on nightly, and we might want to change the feature based on that experience.
37
48
38
49
To allow for that, we must make sure users don't accidentally depend on that new feature - otherwise, especially if experimentation takes time or is delayed and the feature takes the trains to stable, it would end up de facto stable and we'll not be able to make changes in it without breaking people's code.
39
50
40
-
The way we do that is that we make sure all new features are feature gated - they can't be used without enabling a feature gate (`#[feature(foo)]`), which can't be done in a stable/beta compiler. See the [stability in code] section for the technical details.
51
+
The way we do that is that we make sure all new features are feature gated - they can't be used without enabling a feature gate (`#[feature(foo)]`), which can't be done in a stable/beta compiler.
52
+
See the [stability in code] section for the technical details.
41
53
42
-
Eventually, after we gain enough experience using the feature, make the necessary changes, and are satisfied, we expose it to the world using the stabilization process described [here]. Until then, the feature is not set in stone: every part of the feature can be changed, or the feature might be completely rewritten or removed. Features do not gain tenure by being unstable and unchanged for long periods of time.
54
+
Eventually, after we gain enough experience using the feature, make the necessary changes, and are satisfied, we expose it to the world using the stabilization process described [here].
55
+
Until then, the feature is not set in stone: every part of the feature can be changed, or the feature might be completely rewritten or removed.
56
+
Features do not gain tenure by being unstable and unchanged for long periods of time.
43
57
44
58
### Tracking Issues
45
59
46
60
To keep track of the status of an unstable feature, the experience we get while using it on
47
61
nightly, and of the concerns that block its stabilization, every feature-gate needs a tracking
48
-
issue. When creating issues and PRs related to the feature, reference this tracking issue, and when there are updates about the feature's progress, post those to the tracking issue.
62
+
issue.
63
+
When creating issues and PRs related to the feature, reference this tracking issue, and when there are updates about the feature's progress, post those to the tracking issue.
49
64
50
65
For features that are part of an accept RFC or approved lang experiment, use the tracking issue for that.
51
66
52
-
For other features, create a tracking issue for that feature. The issue title should be "Tracking issue for YOUR FEATURE". Use the ["Tracking Issue" issue template][template].
67
+
For other features, create a tracking issue for that feature.
68
+
The issue title should be "Tracking issue for YOUR FEATURE".
69
+
Use the ["Tracking Issue" issue template][template].
To land in the compiler, features that have user-visible effects on the language (even unstable ones) must either be part of an accepted RFC or an approved [lang experiment].
59
76
60
-
To propose a new lang experiment, open an issue in `rust-lang/rust` that describes the motivation and the intended solution. If it's accepted, this issue will become the tracking issue for the experiment, so use the tracking issue [template] while also including these other details. Nominate the issue for the lang team and CC `@rust-lang/lang` and `@rust-lang/lang-advisors`. When the experiment is approved, the tracking issue will be marked as `B-experimental`.
77
+
To propose a new lang experiment, open an issue in `rust-lang/rust` that describes the motivation and the intended solution.
78
+
If it's accepted, this issue will become the tracking issue for the experiment, so use the tracking issue [template] while also including these other details.
79
+
Nominate the issue for the lang team and CC `@rust-lang/lang` and `@rust-lang/lang-advisors`.
80
+
When the experiment is approved, the tracking issue will be marked as `B-experimental`.
61
81
62
82
Feature flags related to a lang experiment must be marked as `incomplete` until an RFC is accepted for the feature.
63
83
@@ -110,11 +130,15 @@ The below steps needs to be followed in order to implement a new unstable featur
110
130
111
131
1. Prevent usage of the new feature unless the feature gate is set. You can check it in most places in the compiler using the expression `tcx.features().$feature_name()`.
112
132
113
-
If the feature gate is not set, you should either maintain the pre-feature behavior or raise an error, depending on what makes sense. Errors should generally use [`rustc_session::parse::feature_err`]. For an example of adding an error, see [#81015].
133
+
If the feature gate is not set, you should either maintain the pre-feature behavior or raise an error, depending on what makes sense.
134
+
Errors should generally use [`rustc_session::parse::feature_err`].
135
+
For an example of adding an error, see [#81015].
114
136
115
-
For features introducing new syntax, pre-expansion gating should be used instead. During parsing, when the new syntax is parsed, the symbol must be inserted to the current crate's [`GatedSpans`] via `self.sess.gated_span.gate(sym::my_feature, span)`.
137
+
For features introducing new syntax, pre-expansion gating should be used instead.
138
+
During parsing, when the new syntax is parsed, the symbol must be inserted to the current crate's [`GatedSpans`] via `self.sess.gated_span.gate(sym::my_feature, span)`.
116
139
117
-
After being inserted to the gated spans, the span must be checked in the [`rustc_ast_passes::feature_gate::check_crate`] function, which actually denies features. Exactly how it is gated depends on the exact type of feature, but most likely will use the `gate_all!()` macro.
140
+
After being inserted to the gated spans, the span must be checked in the [`rustc_ast_passes::feature_gate::check_crate`] function, which actually denies features.
141
+
Exactly how it is gated depends on the exact type of feature, but most likely will use the `gate_all!()` macro.
118
142
119
143
1. Add a test to ensure the feature cannot be used without a feature gate, by creating `tests/ui/feature-gates/feature-gate-$feature_name.rs`. You can generate the corresponding `.stderr` file by running `./x test tests/ui/feature-gates/ --bless`.
120
144
@@ -136,23 +160,27 @@ The below steps needs to be followed in order to implement a new unstable featur
136
160
137
161
## Call for testing
138
162
139
-
Once the implementation is complete, the feature will be available to nightly users but not yet part of stable Rust. This is a good time to write a blog post on [the main Rust blog][rust-blog] and issue a "call for testing".
163
+
Once the implementation is complete, the feature will be available to nightly users but not yet part of stable Rust.
164
+
This is a good time to write a blog post on [the main Rust blog][rust-blog] and issue a "call for testing".
140
165
141
166
Some earlier such blog posts include:
142
167
143
168
1.[The push for GATs stabilization](https://blog.rust-lang.org/2021/08/03/GATs-stabilization-push/)
144
169
2.[Changes to `impl Trait` in Rust 2024](https://blog.rust-lang.org/2024/09/05/impl-trait-capture-rules.html)
145
170
3.[Async Closures MVP: Call for Testing!](https://blog.rust-lang.org/inside-rust/2024/08/09/async-closures-call-for-testing/)
146
171
147
-
Alternatively, [*This Week in Rust*][twir] has a [section][twir-cft] for this. One example of this having been used is:
172
+
Alternatively, [*This Week in Rust*][twir] has a [section][twir-cft] for this.
173
+
One example of this having been used is:
148
174
149
175
-[Call for testing on boolean literals as cfg predicates](https://github.com/rust-lang/rust/issues/131204#issuecomment-2569314526)
150
176
151
177
Which option to choose might depend on how significant the language change is, though note that the [*This Week in Rust*][twir] section might be less visible than a dedicated post on the main Rust blog.
152
178
153
179
## Polishing
154
180
155
-
Giving users a polished experience means more than just implementing the feature in rustc. We need to think about all of the tools and resources that we ship. This work includes:
181
+
Giving users a polished experience means more than just implementing the feature in rustc.
182
+
We need to think about all of the tools and resources that we ship.
183
+
This work includes:
156
184
157
185
- Documenting the language feature in the [Rust Reference][reference].
158
186
- Extending [`rustfmt`] to format any new syntax (if applicable).
@@ -162,7 +190,9 @@ Giving users a polished experience means more than just implementing the feature
162
190
163
191
## Stabilization
164
192
165
-
The final step in the feature lifecycle is [stabilization][stab], which is when the feature becomes available to all Rust users. At this point, backward incompatible changes are generally no longer permitted (see the lang team's [defined semver policies](https://rust-lang.github.io/rfcs/1122-language-semver.html) for details). To learn more about stabilization, see the [stabilization guide][stab].
193
+
The final step in the feature lifecycle is [stabilization][stab], which is when the feature becomes available to all Rust users.
194
+
At this point, backward incompatible changes are generally no longer permitted (see the lang team's [defined semver policies](https://rust-lang.github.io/rfcs/1122-language-semver.html) for details).
195
+
To learn more about stabilization, see the [stabilization guide][stab].
0 commit comments