Skip to content

Commit cf9fb88

Browse files
RossSmythrsmyth-ecmiNoratrieb
authored
Add some more details on feature gating (#1891)
* Add some more details on feature gating * Apply suggestions from code review --------- Co-authored-by: Ross Smyth <[email protected]> Co-authored-by: Nilstrieb <[email protected]>
1 parent 9ef55c5 commit cf9fb88

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/implementing_new_features.md

+9-3
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ a new unstable feature:
123123

124124
1. Add the feature name to `rustc_span/src/symbol.rs` in the `Symbols {...}` block.
125125

126+
Note that this block must be in alphbetical order.
127+
126128
1. Add a feature gate declaration to `rustc_feature/src/unstable.rs` in the unstable
127129
`declare_features` block.
128130

@@ -171,9 +173,13 @@ a new unstable feature:
171173
For an example of adding an error, see [#81015].
172174

173175
For features introducing new syntax, pre-expansion gating should be used instead.
174-
To do so, extend the [`GatedSpans`] struct, add spans to it during parsing,
175-
and then finally feature-gate all the spans in
176-
[`rustc_ast_passes::feature_gate::check_crate`].
176+
During parsing, when the new syntax is parsed, the symbol must be inserted to the
177+
current crate's [`GatedSpans`] via `self.sess.gated_span.gate(sym::my_feature, span)`.
178+
179+
After being inserted to the gated spans, the span must be checked in the
180+
[`rustc_ast_passes::feature_gate::check_crate`] function, which actually denies
181+
features. Exactly how it is gated depends on the exact type of feature, but most
182+
likely will use the `gate_all!()` macro.
177183

178184
1. Add a test to ensure the feature cannot be used without
179185
a feature gate, by creating `tests/ui/feature-gates/feature-gate-$feature_name.rs`.

0 commit comments

Comments
 (0)