@@ -128,14 +128,48 @@ a new unstable feature:
128
128
The tracking issue should be labeled with at least ` C-tracking-issue ` .
129
129
For a language feature, a label ` F-feature_name ` should be added as well.
130
130
131
- 2 . Pick a name for the feature gate (for RFCs, use the name
131
+ 1 . Pick a name for the feature gate (for RFCs, use the name
132
132
in the RFC).
133
133
134
- 3 . Add a feature gate declaration to ` rustc_feature/src/active.rs ` in the active
135
- ` declare_features ` block, and add the feature gate keyword to
136
- ` rustc_span/src/symbol.rs ` . See [ here] [ add-feature-gate ] for detailed instructions.
134
+ 1 . Add the feature name to ` rustc_span/src/symbol.rs ` in the ` Symbols {...} ` block.
137
135
138
- 4 . Prevent usage of the new feature unless the feature gate is set.
136
+ 1 . Add a feature gate declaration to ` rustc_feature/src/active.rs ` in the active
137
+ ` declare_features ` block.
138
+
139
+ ``` rust ignore
140
+ /// description of feature
141
+ (active , $ feature_name , " CURRENT_RUSTC_VERSION" , Some ($ tracking_issue_number ), $ edition )
142
+ ```
143
+
144
+ where ` $edition ` has the type ` Option<Edition> ` , and is typically just ` None ` . If you haven't yet
145
+ opened a tracking issue (e.g. because you want initial feedback on whether the feature is likely
146
+ to be accepted), you can temporarily use ` None ` - but make sure to update it before the PR is
147
+ merged!
148
+
149
+ For example:
150
+
151
+ ``` rust ignore
152
+ /// Allows defining identifiers beyond ASCII.
153
+ (active , non_ascii_idents , " CURRENT_RUSTC_VERSION" , Some (55467 ), None ),
154
+ ```
155
+
156
+ Features can be marked as incomplete, and trigger the warn-by-default [ ` incomplete_features `
157
+ lint]
158
+ by setting their type to ` incomplete ` :
159
+
160
+ [ `incomplete_features` lint ] : https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#incomplete-features
161
+
162
+ ``` rust ignore
163
+ /// Allows unsized rvalues at arguments and parameters.
164
+ (incomplete , unsized_locals , " CURRENT_RUSTC_VERSION" , Some (48055 ), None ),
165
+ ```
166
+
167
+ To avoid [ semantic merge conflicts] , please use ` CURRENT_RUSTC_VERSION ` instead of ` 1.70 ` or
168
+ another explicit version number.
169
+
170
+ [ semantic merge conflicts ] : https://bors.tech/essay/2017/02/02/pitch/
171
+
172
+ 1 . Prevent usage of the new feature unless the feature gate is set.
139
173
You can check it in most places in the compiler using the
140
174
expression ` tcx.features().$feature_name ` (or
141
175
` sess.features_untracked().$feature_name ` if the
@@ -151,18 +185,18 @@ a new unstable feature:
151
185
and then finally feature-gate all the spans in
152
186
[ ` rustc_ast_passes::feature_gate::check_crate ` ] .
153
187
154
- 5 . Add a test to ensure the feature cannot be used without
155
- a feature gate, by creating ` feature-gate-$feature_name.rs `
156
- and ` feature-gate-$feature_name .stderr` files under the
157
- directory where the other tests for your feature reside .
188
+ 1 . Add a test to ensure the feature cannot be used without
189
+ a feature gate, by creating ` tests/ui/ feature-gates/feature- gate-$feature_name.rs` .
190
+ You can generate the corresponding ` .stderr ` file by running `./x.py test tests/ui/feature-gates/
191
+ --bless` .
158
192
159
- 6 . Add a section to the unstable book, in
193
+ 1 . Add a section to the unstable book, in
160
194
` src/doc/unstable-book/src/language-features/$feature_name.md ` .
161
195
162
- 7 . Write a lot of tests for the new feature.
196
+ 1 . Write a lot of tests for the new feature, preferably in ` tests/ui/$feature_name/ ` .
163
197
PRs without tests will not be accepted!
164
198
165
- 8 . Get your PR reviewed and land it. You have now successfully
199
+ 1 . Get your PR reviewed and land it. You have now successfully
166
200
implemented a feature in Rust!
167
201
168
202
[ `GatedSpans` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_session/parse/struct.GatedSpans.html
0 commit comments