Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some more details on feature gating #1891

Merged
merged 2 commits into from
Mar 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/implementing_new_features.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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`.
Expand Down