Skip to content

Commit

Permalink
publish: Merge pull request #32 from rust-lang/stabilization-update
Browse files Browse the repository at this point in the history
generated from commit 22b26d5
  • Loading branch information
GH Actions Runner authored and GH Actions Runner committed May 27, 2022
1 parent 48836d0 commit 195dcc3
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 20 deletions.
77 changes: 68 additions & 9 deletions feature-lifecycle/stabilization.html
Original file line number Diff line number Diff line change
Expand Up @@ -168,22 +168,81 @@ <h1 class="menu-title">Standard library developers Guide</h1>
<div id="content" class="content">
<main>
<h1><a class="header" href="#stabilizing-features" id="stabilizing-features">Stabilizing features</a></h1>
<p><strong>Status:</strong> Stub</p>
<ul>
<li><strong>Status:</strong> Current</li>
<li><strong>Last Updated:</strong> 2022-05-27</li>
</ul>
<p>Feature stabilization involves adding <code>#[stable]</code> attributes. They may be introduced alongside new trait impls or replace existing <code>#[unstable]</code> attributes.</p>
<p>Stabilization goes through the Libs FCP process, which occurs on the <a href="./tracking-issues.html">tracking issue</a> for the feature.</p>
<p>Stabilization goes through the Libs FCP (Final Comment Period) process, which typically occurs on the <a href="./tracking-issues.html">tracking issue</a> for the feature.</p>
<h2><a class="header" href="#when-is-an-fcp-appropriate" id="when-is-an-fcp-appropriate">When is an FCP appropriate?</a></h2>
<p>Once an unstable feature's API design space (e.g. alternative APIs) has been fully explored with no outstanding concerns, anyone may push for its stabilization.</p>
<p>If you're unsure if a feature is ready for stabilization the first step should be to ask in the relevant tracking issue and get assistance from other participants in that discussion. In some cases the tracking issue may not have many other active participants, so if you're ever having trouble getting any feedback please ping one of the <a href="https://github.com/rust-lang/highfive/blob/master/highfive/configs/rust-lang/rust.json">libs team reviewers</a> directly to request assistance.</p>
<h2><a class="header" href="#stabilization-report" id="stabilization-report">Stabilization Report</a></h2>
<p>Once a feature is ready for stabilization the first step of the FCP process is writing a stabilization report. Stabilization reports are not mandatory but they are heavily encouraged, and may be mandated by library API team members if they feel it necessary. The purpose of stabilization reports is to help reviewers more quickly make decisions and to simplify the process of documenting stabilized APIs in release notes. Stabilization reports consist of three primary sections, a implementation history, an API summary, and an experience report.</p>
<p>The <strong>Implementation History</strong> section should summarize the initial discussion during the implementation PR, every change that has been made to the feature since the initial implementation, all issues that were raised during the lifetime of the feature, and how they were resolved.</p>
<p>The <strong>API Summary</strong> section should include a precise description of what APIs are being introduced to the standard libraries. This can often be a simple link back to the top level comment if it's up to date, but in some situations it may not be possible to edit the original tracking issue to fix outdated information, such as when the author of the stabilization report is not the author of the tracking issue itself.</p>
<p>The libs team maintains a tool for this called <a href="https://github.com/rust-lang/libs-team/tree/main/tools/unstable-api"><code>cargo unstable-api</code></a> that can be used to generate these API summaries in some cases. <em>Note</em> the current implementation of this tool is fragile and does not work in all cases. We hope to have a more permanent version of this tool in the future that is built ontop of either rustdoc or rustc's own APIs.</p>
<p>The <strong>Experience Report</strong> section should include concrete usecases of users who have wanted to use the feature and who have tested that it works for their needs. The experience report should include a brief summary of the experience of using that feature. Ideally this would include links to commits or branches where the feature was integrated with their project, but this is not a requirement. Alternatively, users can provide usage examples of crates that export an identical API to the one being stabilized.</p>
<p>You can see an example of a stabilization report in <a href="https://github.com/rust-lang/rust/issues/88581#issuecomment-1054642118">#88581</a>.</p>
<h2><a class="header" href="#before-writing-a-pr-to-stabilize-a-feature" id="before-writing-a-pr-to-stabilize-a-feature">Before writing a PR to stabilize a feature</a></h2>
<p>Check to see if a FCP has completed first. If not, either ping <code>@rust-lang/libs</code> or leave a comment asking about the status of the feature.</p>
<p>Check to see if a FCP has completed first. If not, either ping <code>@rust-lang/libs-api</code> or leave a comment asking about the status of the feature.</p>
<p>This will save you from opening a stabilization PR and having it need regular rebasing while the FCP process runs its course.</p>
<h2><a class="header" href="#writing-a-stabilization-pr" id="writing-a-stabilization-pr">Writing a stabilization PR</a></h2>
<ul>
<li>Replace any <code>#[unstable]</code> attributes for the given feature with stable ones. The value of the <code>since</code> field is usually the current <code>nightly</code> version.</li>
<li>Remove any <code>#![feature()]</code> attributes that were previously required.</li>
<li>Submit a PR with a stabilization report.</li>
</ul>
<h2><a class="header" href="#partial-stabilizations" id="partial-stabilizations">Partial Stabilizations</a></h2>
<p>When you only wish to stabilize a subset of an existing feature you should skip creating a new tracking issue and instead create a partial stabilization PR for the subset of the feature being stabilized.</p>
<p>If you're unsure if a feature is ready for partial stabilization the first step should be to ask in the relevant tracking issue and get assistance from other participants in that discussion. In some cases the tracking issue may not have many other active participants, so if you're ever having trouble getting any feedback please ping one of the <a href="https://github.com/rust-lang/highfive/blob/master/highfive/configs/rust-lang/rust.json">libs team reviewers</a> directly to request assistance.</p>
<p>You can see an example of partially stabilizing a feature with tracking issue <a href="https://github.com/rust-lang/rust/issues/71146">#71146</a> and partial stabilization PR <a href="https://github.com/rust-lang/rust/pull/94640">#94640</a>.</p>
<h2><a class="header" href="#when-theres-const-involved" id="when-theres-const-involved">When there's <code>const</code> involved</a></h2>
<p>Const functions can be stabilized in a PR that replaces <code>#[rustc_const_unstable]</code> attributes with <code>#[rustc_const_stable]</code> ones. The <a href="https://github.com/rust-lang/const-eval">Constant Evaluation WG</a> should be pinged for input on whether or not the <code>const</code>-ness is something we want to commit to. If it is an intrinsic being exposed that is const-stabilized then <code>@rust-lang/lang</code> should also be included in the FCP.</p>
<p>Check whether the function internally depends on other unstable <code>const</code> functions through <code>#[allow_internal_unstable]</code> attributes and consider how the function could be implemented if its internally unstable calls were removed. See the <em>Stability attributes</em> page for more details on <code>#[allow_internal_unstable]</code>.</p>
<p>Where <code>unsafe</code> and <code>const</code> is involved, e.g., for operations which are &quot;unconst&quot;, that the const safety argument for the usage also be documented. That is, a <code>const fn</code> has additional determinism (e.g. run-time/compile-time results must correspond and the function's output only depends on its inputs...) restrictions that must be preserved, and those should be argued when <code>unsafe</code> is used.</p>
<h2><a class="header" href="#stabilization-pr-for-library-features" id="stabilization-pr-for-library-features">Stabilization PR for Library Features</a></h2>
<p>Once we have decided to stabilize a feature, we need to have a PR that actually makes that stabilization happen. These kinds of PRs are a great way to get involved in Rust, as they're typically small -- just updating attributes.</p>
<p>Here is a general guide to how to stabilize a feature -- every feature is different, of course, so some features may require steps beyond what this guide talks about.</p>
<h3><a class="header" href="#update-the-stability-attributes-on-the-items" id="update-the-stability-attributes-on-the-items">Update the stability attributes on the items</a></h3>
<p>Library items are marked unstable via the <code>#[unstable]</code> attribute, like this:</p>
<pre><code class="language-rust ignore">#[unstable(feature = &quot;total_cmp&quot;, issue = &quot;72599&quot;)]
pub fn total_cmp(&amp;self, other: &amp;Self) -&gt; crate::cmp::Ordering { ... }
</code></pre>
<p>You'll need to change that to a <code>#[stable]</code> attribute with a version:</p>
<pre><code class="language-rust ignore">#[stable(feature = &quot;total_cmp&quot;, since = &quot;1.61.0&quot;)]
</code></pre>
<p>Note that, the version number is updated to be the version number of the stable release where this feature will appear. This can be found by consulting <a href="https://github.com/rust-lang/rust/blob/master/src/version"><code>src/version</code></a> on the current master branch of <code>rust-lang/rust</code>.</p>
<h3><a class="header" href="#remove-feature-gates-from-doctests" id="remove-feature-gates-from-doctests">Remove feature gates from doctests</a></h3>
<p>All the doctests on the items being stabilized will be enabling the unstable feature, so now that it's stable those attributes are no longer needed and should be removed.</p>
<pre><code class="language-diff"> /// # Examples
///
/// ```
-/// #![feature(total_cmp)]
-///
/// assert_eq!(0.0_f32.total_cmp(&amp;-0.0), std::cmp::Ordering::Greater);
/// ```
</code></pre>
<p>The most obvious place to find these is on the item itself, but it's worth searching the whole library. Often you'll find other unstable methods that were also using it in their tests.</p>
<h3><a class="header" href="#remove-feature-gates-from-the-compiler" id="remove-feature-gates-from-the-compiler">Remove feature gates from the compiler</a></h3>
<p>The compiler builds with nightly features allowed, so you may find uses of the feature there as well. These also need to be removed.</p>
<pre><code class="language-diff"> #![feature(once_cell)]
#![feature(never_type)]
-#![feature(total_cmp)]
#![feature(trusted_step)]
#![feature(try_blocks)]
</code></pre>
<h2><a class="header" href="#stabilization-pr-checklist" id="stabilization-pr-checklist">Stabilization PR Checklist</a></h2>
<p>To stabilize a feature, follow these steps:</p>
<ol start="0">
<li>Create a stabiliation report in the tracking issue for the feature being stabilized.</li>
<li>(Optional) For partial stabilizations, create a new partial stabilization PR for the subset of the issue being stabilized.</li>
<li>Ask a <strong>@rust-lang/libs-api</strong> member to start an FCP on the tracking issue and wait for the FCP to complete (with <code>disposition-merge</code>).</li>
<li>Change <code>#[unstable(...)]</code> to <code>#[stable(since = &quot;version&quot;)]</code>. <code>version</code> should be the <em>current nightly</em>, i.e. stable+2. You can see which version is the current nightly in <a href="https://github.com/rust-lang/rust/blob/master/src/version"><code>src/version</code></a> on the master branch of <code>rust-lang/rust</code>.</li>
<li>Remove <code>#![feature(...)]</code> from any test or doc-test for this API. If the feature is used in the compiler or tools, remove it from there as well.</li>
<li>If applicable, change <code>#[rustc_const_unstable(...)]</code> to <code>#[rustc_const_stable(since = &quot;version&quot;)]</code>.</li>
<li>Open a PR against <code>rust-lang/rust</code>.
<ul>
<li>Add the appropriate labels: <code>@rustbot modify labels: +T-libs-api</code>.</li>
<li>Link to the tracking issue by adding &quot;Closes #XXXXX&quot;.</li>
</ul>
</li>
</ol>
<p>You can see an example of stabilizing a feature with <a href="https://github.com/rust-lang/rust/issues/81656">tracking issue #81656 with FCP</a> and the associated <a href="https://github.com/rust-lang/rust/pull/84642">implementation PR #84642</a>.</p>

</main>

Expand Down
Loading

0 comments on commit 195dcc3

Please sign in to comment.