From a0ee63ef6e50a8b92e29d54d2c02be3feaef3d5e Mon Sep 17 00:00:00 2001 From: Ross Smyth Date: Fri, 16 Feb 2024 17:46:30 -0500 Subject: [PATCH 1/2] Add some more details on feature gating --- src/implementing_new_features.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/implementing_new_features.md b/src/implementing_new_features.md index 0140c09bb..11a94fcbf 100644 --- a/src/implementing_new_features.md +++ b/src/implementing_new_features.md @@ -123,6 +123,8 @@ a new unstable feature: 1. Add the feature name to `rustc_span/src/symbol.rs` in the `Symbols {...}` block. +Note that this block must be in alphbetical order. + 1. Add a feature gate declaration to `rustc_feature/src/unstable.rs` in the unstable `declare_features` block. @@ -171,9 +173,13 @@ a new unstable feature: For an example of adding an error, see [#81015]. For features introducing new syntax, pre-expansion gating should be used instead. - To do so, extend the [`GatedSpans`] struct, add spans to it during parsing, - and then finally feature-gate all the spans in - [`rustc_ast_passes::feature_gate::check_crate`]. + 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)`. + + 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. 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`. From ab12c592e758403022047ebd744bb3b4cb57f493 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Fri, 1 Mar 2024 23:19:21 +0100 Subject: [PATCH 2/2] Apply suggestions from code review --- src/implementing_new_features.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/implementing_new_features.md b/src/implementing_new_features.md index 11a94fcbf..1b9170e49 100644 --- a/src/implementing_new_features.md +++ b/src/implementing_new_features.md @@ -123,7 +123,7 @@ a new unstable feature: 1. Add the feature name to `rustc_span/src/symbol.rs` in the `Symbols {...}` block. -Note that this block must be in alphbetical order. + Note that this block must be in alphbetical order. 1. Add a feature gate declaration to `rustc_feature/src/unstable.rs` in the unstable `declare_features` block. @@ -174,7 +174,7 @@ Note that this block must be in alphbetical order. 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)`. + current crate's [`GatedSpans`] via `self.sess.gated_span.gate(sym::my_feature, span)`. 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