@@ -5,6 +5,8 @@ nightly-only `#![feature(...)]` opt-in. This chapter documents the implementatio
55of feature gating: where gates are defined, how they are enabled, and how usage
66is verified.
77
8+ <!-- data-check: Feb 2026 -->
9+
810## Feature Definitions
911
1012All feature gate definitions are located in the ` rustc_feature ` crate:
@@ -30,7 +32,10 @@ Before AST validation or expansion, `rustc` collects crate-level
3032 ` removed ` tables:
3133 - ** Removed** features cause an immediate error.
3234 - ** Accepted** features are recorded but do not require nightly. On
33- stable/beta they trigger the "already stabilized" diagnostic.
35+ stable/beta, ` maybe_stage_features ` in
36+ [ ` rustc_ast_passes/src/feature_gate.rs ` ] emits the non-nightly
37+ diagnostic and lists stable features, which is where the "already
38+ stabilized" messaging comes from.
3439 - ** Unstable** features are recorded as enabled.
3540 - Unknown features are treated as ** library features** and validated later.
3641- With ` -Z allow-features=... ` , any ** unstable** or ** unknown** feature
@@ -62,18 +67,8 @@ in `check_crate` and its AST visitor.
6267 (declared in ` rustc_feature::INCOMPATIBLE_FEATURES ` ) are not used together.
6368- ` check_new_solver_banned_features ` : Bans features incompatible with
6469 compiler mode for the next trait solver.
65- - ** Parser-gated spans** : Processes the ` GatedSpans ` recorded during parsing.
66-
67- ### AST Visitor
68-
69- A ` PostExpansionVisitor ` walks the expanded AST to check constructs that are
70- easier to validate after expansion.
71-
72- - The visitor uses helper macros (` gate! ` , ` gate_alt! ` , ` gate_multi! ` ) to check:
73- 1 . Is the feature enabled?
74- 2 . Does ` span.allows_unstable ` permit it (for internal compiler macros)?
75- - Examples include ` trait_alias ` , ` decl_macro ` , ` extern types ` , and various
76- ` impl Trait ` forms.
70+ - ** Parser-gated spans** : Processes the ` GatedSpans ` recorded during parsing
71+ (see [ Checking ` GatedSpans ` ] ( #checking-gatedspans ) ).
7772
7873### Checking ` GatedSpans `
7974
@@ -86,6 +81,17 @@ easier to validate after expansion.
8681- Legacy gates (e.g., ` box_patterns ` , ` try_blocks ` ) may use a separate path that
8782 emits future-incompatibility warnings instead of hard errors.
8883
84+ ### AST Visitor
85+
86+ A ` PostExpansionVisitor ` walks the expanded AST to check constructs that are
87+ easier to validate after expansion.
88+
89+ - The visitor uses helper macros (` gate! ` , ` gate_alt! ` , ` gate_multi! ` ) to check:
90+ 1 . Is the feature enabled?
91+ 2 . Does ` span.allows_unstable ` permit it (for internal compiler macros)?
92+ - Examples include ` trait_alias ` , ` decl_macro ` , ` extern types ` , and various
93+ ` impl Trait ` forms.
94+
8995## Attributes and ` cfg `
9096
9197Beyond syntax, rustc also gates attributes and ` cfg ` options.
@@ -99,8 +105,8 @@ Beyond syntax, rustc also gates attributes and `cfg` options.
99105
100106### ` cfg ` options
101107
102- - [ ` rustc_attr_parsing/src/attributes/cfg.rs ` ] defines
103- ` find_gated_cfg ` / ` gate_cfg ` to reject gated ` cfg ` s.
108+ - [ ` rustc_attr_parsing/src/attributes/cfg.rs ` ] defines ` gate_cfg ` and uses
109+ [ ` rustc_feature:: find_gated_cfg` ] to reject gated ` cfg ` s.
104110- ` gate_cfg ` respects ` Span::allows_unstable ` , allowing internal compiler
105111 macros to bypass ` cfg ` gates when marked with ` #[allow_internal_unstable] ` .
106112- The gated cfg list is defined in [ ` rustc_feature/src/builtin_attrs.rs ` ] .
@@ -130,4 +136,5 @@ Diagnostic helpers are located in [`rustc_session/src/parse.rs`].
130136[ `rustc_parse/src/parser/*` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_parse/parser/index.html
131137[ `rustc_ast_passes::check_attribute` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast_passes/feature_gate/fn.check_attribute.html
132138[ `rustc_attr_parsing/src/attributes/cfg.rs` ] : https://github.com/rust-lang/rust/blob/HEAD/compiler/rustc_attr_parsing/src/attributes/cfg.rs
139+ [ `rustc_feature::find_gated_cfg` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_feature/fn.find_gated_cfg.html
133140[ `rustc_span/src/lib.rs` ] : https://github.com/rust-lang/rust/blob/HEAD/compiler/rustc_span/src/lib.rs
0 commit comments