|
| 1 | + |
| 2 | +# Request for stabilization |
| 3 | + |
| 4 | + Once an unstable feature has been well-tested with no outstanding |
| 5 | + concern, anyone may push for its stabilization. It involves the |
| 6 | + following steps. |
| 7 | + |
| 8 | + - Documentation PRs |
| 9 | + - Write a stabilization report |
| 10 | + - FCP |
| 11 | + - Stabilization PR |
| 12 | + |
| 13 | +## Documentation PRs |
| 14 | + |
| 15 | + Prepare PRs to update documentations involing this new feature. |
| 16 | + You need to submit PRs for repositories The Reference, The Book |
| 17 | + and Rust by Example. |
| 18 | + Maintainers of these repositories will keep these PRs open until |
| 19 | + the whole stabilization process has completed. Meanwhile, we can |
| 20 | + proceed to the next step. |
| 21 | + |
| 22 | +## Write a stabilization report |
| 23 | + |
| 24 | + Find the tracking issue of the feature, and create a short |
| 25 | + stabilization report. Essentially this would be a brief summary |
| 26 | + of the feature plus some links to test cases showing it works |
| 27 | + as expected, along with a list of edge cases that came up and |
| 28 | + and were considered. This is a minimal "due diligence" that |
| 29 | + we do before stabilizing. |
| 30 | + |
| 31 | + The report should contain: |
| 32 | + |
| 33 | + - A summary, showing examples (e.g. code snippets) what is |
| 34 | + enabled by this feature. |
| 35 | + - Links to test cases in our test suite regarding this feature |
| 36 | + and describe the feature's behavior on encountering edge cases. |
| 37 | + - Links to the documentations (the PRs we have made in the |
| 38 | + previous steps). |
| 39 | + - Any other relevant information(Examples of such reports can |
| 40 | + be found in rust-lang/rust#44494 and rust-lang/rust#28237). |
| 41 | + |
| 42 | +## FCP |
| 43 | + |
| 44 | +If any member of the team responsible for tracking this |
| 45 | +feature agrees with stabilizing this feature, they will |
| 46 | +start the FCP (final-comment-period) process by |
| 47 | +commenting |
| 48 | + |
| 49 | + ```bash |
| 50 | + @rfcbot fcp merge |
| 51 | + ``` |
| 52 | + |
| 53 | +The rest of the team members will review the proposal. If the final |
| 54 | +decision is to stabilize, we proceed to do the actual code modification. |
| 55 | + |
| 56 | +## Stabilization PR |
| 57 | + |
| 58 | +Once we have decided to stabilize a feature, we need to have a PR that |
| 59 | +actually makes that stabilization happen. These kinds of PRs are a |
| 60 | +great way to get involved in Rust, as they take you on a little tour |
| 61 | +through the source code. |
| 62 | + |
| 63 | +Here is a general guide to how to stabilize a feature -- every feature |
| 64 | +is different, of course, so some features may require steps beyond |
| 65 | +what this guide talks about. |
| 66 | + |
| 67 | +Note: Before we stabilize any feature, it is rule that it should appear |
| 68 | +in the documentation. |
| 69 | + |
| 70 | +### Updating the feature-gate listing |
| 71 | + |
| 72 | +There is a central listing of feature-gates in |
| 73 | +`src/libsyntax/feature_gate.rs`. Search for the `declare_features!` |
| 74 | +macro. There should be an entry for the feature you are aiming to |
| 75 | +stabilize, something like (this example is taken from |
| 76 | +[rust-lang/rust#32409]: |
| 77 | + |
| 78 | + ``` |
| 79 | + // pub(restricted) visibilities (RFC 1422) |
| 80 | + (active, pub_restricted, "1.9.0", Some(32409)), |
| 81 | + ``` |
| 82 | +The above line should be moved down to the area for "accepted" |
| 83 | +features, declared below in a separate call to `declare_features!`. |
| 84 | +When it is done, it should look like: |
| 85 | + |
| 86 | + ``` |
| 87 | + // pub(restricted) visibilities (RFC 1422) |
| 88 | + (accepted, pub_restricted, "1.31.0", Some(32409)), |
| 89 | + // ^^^^^^ note that we changed this |
| 90 | + ``` |
| 91 | + |
| 92 | +Note that, the version number is updated to be the version number |
| 93 | +of the stable release where this feature will appear. This can be |
| 94 | +found by consulting https://forge.rust-lang.org/, which will guide |
| 95 | +you the next stable release number. You want to add 1 to that, |
| 96 | +because the code that lands today will become go into beta on that |
| 97 | +date, and then become stable after that. So, at the time of this |
| 98 | +writing, the next stable release (what is currently beta, iow) was |
| 99 | +1.30.0, hence I wrote 1.31.0 above. |
| 100 | + |
| 101 | +### Removing existing uses of the feature-gate |
| 102 | + |
| 103 | +Next search for the feature string (in this case, pub_restricted) |
| 104 | +in the codebase to find where it appears. Change uses of |
| 105 | +`#![feature(XXX)]` from the stdlib and rustc crates to be |
| 106 | +`#![cfg_attr(stage0, feature(XXX))]`. This includes the feature-gate |
| 107 | +only for stage0, which is built using the current beta (this is |
| 108 | +needed because the feature is still unstable in the current beta). |
| 109 | + |
| 110 | +Also, remove those strings from any tests. If there are tests |
| 111 | +specifically targeting the feature-gate (i.e., testing that the |
| 112 | +feature-gate is required to use the feature, but nothing else), |
| 113 | +simply remove the test. |
| 114 | + |
| 115 | +### Do not require the feature-gate to use the feature |
| 116 | + |
| 117 | +Most importantly, remove the code which flags an error if the |
| 118 | +feature-gate is not present (since the feature is now considered |
| 119 | +stable). If the feature can be detected because it employs some |
| 120 | +new syntax, then a common place for that code to be is in the |
| 121 | +same `feature_gate.rs`. For example, you might see code like this: |
| 122 | + |
| 123 | + ``` |
| 124 | + gate_feature_post!(&self, pub_restricted, span, |
| 125 | + "`pub(restricted)` syntax is experimental"); |
| 126 | + ``` |
| 127 | + |
| 128 | +This `gate_feature_post!` macro prints an error if the |
| 129 | +`pub_restricted` feature is not enabled. It is not needed |
| 130 | +now that `#[pub_restricted]` is stable. |
| 131 | + |
| 132 | +For more subtle features, you may find code like this: |
| 133 | + |
| 134 | + ``` |
| 135 | + if self.tcx.sess.features.borrow().pub_restricted { /* XXX */ } |
| 136 | + ``` |
| 137 | + |
| 138 | +This `pub_restricted` field (obviously named after the feature) |
| 139 | +would ordinarily be false if the feature flag is not present |
| 140 | +and true if it is. So transform the code to assume that the field |
| 141 | +is true. In this case, that would mean removing the `if` and |
| 142 | +leaving just the `/* XXX */`. |
| 143 | + |
| 144 | + ``` |
| 145 | + if self.tcx.sess.features.borrow().pub_restricted { /* XXX */ } |
| 146 | + = becomes ==> |
| 147 | + /* XXX */ |
| 148 | + |
| 149 | + if self.tcx.sess.features.borrow().pub_restricted && something { /* XXX */ } |
| 150 | + = becomes ==> |
| 151 | + if something { /* XXX */ } |
| 152 | + ``` |
| 153 | + |
| 154 | +## Updating documentation |
| 155 | + |
| 156 | +If any documentation for this feature exists, it should be |
| 157 | +in the `Unstable Book`, located at `src/doc/unstable-book`. |
| 158 | +Regardless of its existence, the page for the feature gate |
| 159 | +should be removed. |
| 160 | + |
| 161 | +If there was documentation there, integrating it into the |
| 162 | +existing documentation is needed. |
| 163 | + |
| 164 | +If there wasn't documentation there, it needs to be added. |
| 165 | + |
| 166 | +Places that may need updated documentation: |
| 167 | + |
| 168 | + [The Reference]: this must be updated, in full detail. |
| 169 | + [The Book]: this may or may not need updating, depending. |
| 170 | + If you're not sure, please open an issue on this repository |
| 171 | + and it can be discussed. |
| 172 | + standard library documentation: as needed. Language features |
| 173 | + often don't need this, but if it's a feature that changes |
| 174 | + how good examples are written, such as when `?` was added |
| 175 | + to the language, updating examples is important. |
| 176 | + [Rust by Example]: as needed. |
| 177 | + |
| 178 | +[rust-lang/rust#32409]:https://github.com/rust-lang/rust/issues/32409 |
| 179 | +[The Reference]: https://github.com/rust-lang-nursery/reference |
| 180 | +[The Book]: https://github.com/rust-lang/book |
| 181 | +[Rust by Example]: https://github.com/rust-lang/rust-by-example |
0 commit comments