Update feature gating docs to fit reality (#455)

This commit is contained in:
Mazdak Farrokhzad 2019-10-01 13:40:58 +02:00 committed by Santiago Pastorino
parent 02d96fdcd8
commit 7f27d2150e
1 changed files with 14 additions and 5 deletions

View File

@ -35,7 +35,7 @@ of concept so that people can see what you are talking about.
That starts a "proposed final comment period" (pFCP), which requires That starts a "proposed final comment period" (pFCP), which requires
all members of the team to sign off the FCP. After they all do so, all members of the team to sign off the FCP. After they all do so,
there's a week long "final comment period" where everybody can comment, there's a 10 day long "final comment period" where everybody can comment,
and if no new concerns are raised, the PR/issue gets FCP approval. and if no new concerns are raised, the PR/issue gets FCP approval.
## The logistics of writing features ## The logistics of writing features
@ -119,10 +119,13 @@ a new unstable feature:
1. Open a [tracking issue] - 1. Open a [tracking issue] -
if you have an RFC, you can use the tracking issue for the RFC. if you have an RFC, you can use the tracking issue for the RFC.
The tracking issue should be labeled with at least `C-tracking-issue`.
For a language feature, a label `F-feature_name` should be added as well.
2. Pick a name for the feature gate (for RFCs, use the name 2. Pick a name for the feature gate (for RFCs, use the name
in the RFC). in the RFC).
3. Add a feature gate declaration to `libsyntax/feature_gate.rs` 3. Add a feature gate declaration to `libsyntax/active.rs`
in the active `declare_features` block: in the active `declare_features` block:
```rust,ignore ```rust,ignore
@ -140,8 +143,8 @@ For example:
( active, match_beginning_vert, "1.21.0", Some(44101), None), ( active, match_beginning_vert, "1.21.0", Some(44101), None),
``` ```
The current version is not actually important the important When added, the current version should be the one for the current nightly.
version is when you are stabilizing a feature. Once the feature is moved to `accepted.rs`, the version is changed to that nightly version.
4. Prevent usage of the new feature unless the feature gate is set. 4. Prevent usage of the new feature unless the feature gate is set.
You can check it in most places in the compiler using the You can check it in most places in the compiler using the
@ -153,10 +156,14 @@ version is when you are stabilizing a feature.
the pre-feature behavior or raise an error, depending on the pre-feature behavior or raise an error, depending on
what makes sense. what makes sense.
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 [`feature_gate::check::check_crate`].
5. Add a test to ensure the feature cannot be used without 5. Add a test to ensure the feature cannot be used without
a feature gate, by creating `feature-gate-$feature_name.rs` a feature gate, by creating `feature-gate-$feature_name.rs`
and `feature-gate-$feature_name.stderr` files under the and `feature-gate-$feature_name.stderr` files under the
`src/test/ui/feature-gates` directory. directory where the other tests for your feature reside.
6. Add a section to the unstable book, in 6. Add a section to the unstable book, in
`src/doc/unstable-book/src/language-features/$feature_name.md`. `src/doc/unstable-book/src/language-features/$feature_name.md`.
@ -167,6 +174,8 @@ version is when you are stabilizing a feature.
8. Get your PR reviewed and land it. You have now successfully 8. Get your PR reviewed and land it. You have now successfully
implemented a feature in Rust! implemented a feature in Rust!
[`GatedSpans`]: https://doc.rust-lang.org/nightly/nightly-rustc/syntax/parse/struct.GatedSpans.html
[`feature_gate::check::check_crate`]: https://doc.rust-lang.org/nightly/nightly-rustc/syntax/feature_gate/check/fn.check_crate.html
[value the stability of Rust]: https://github.com/rust-lang/rfcs/blob/master/text/1122-language-semver.md [value the stability of Rust]: https://github.com/rust-lang/rfcs/blob/master/text/1122-language-semver.md
[stability in code]: #stability-in-code [stability in code]: #stability-in-code
[here]: https://rust-lang.github.io/rustc-guide/stabilization_guide.html [here]: https://rust-lang.github.io/rustc-guide/stabilization_guide.html