| commit | e0c96122040b9eb85590029fee04caefd7a72da2 | [log] [tgz] |
|---|---|---|
| author | Travis Cross <tc@traviscross.com> | Tue Oct 14 01:00:27 2025 +0000 |
| committer | Eric Huss <eric@huss.org> | Thu Dec 18 19:55:45 2025 -0800 |
| tree | cf0ceb3398ce93749b00c71dbcbb94871c6d6615 | |
| parent | a2877af7316dd2b3344ce3440349587731e0eba0 [diff] |
Revise `...discriminants.slice-patterns-*` rules The section here stated: > Matching against a slice pattern that needs to inspect the length of > the scrutinee performs a read of the pointer value in order to fetch > the length. The read will cause the closure to borrow the relevant > place by `ImmBorrow`. It then goes on to state exceptions for arrays matched against slice patterns and slice patterns containing only a rest pattern. In saying that the pointer value is read, this might suggest that the pointer is captured. Actually, though, it's the slice (the pointee) that is captured. Let's fix this. Beyond that, as we saw in an earlier commit, it's better to not lean on the reader to infer the "relevant place" or when the length needs to be inspected. Let's elaborate those details and state the full rule in one go, upfront, and then state a separate guarantee that matching an array against a slice pattern does not do a read. We'll also fix a typo, add rule identifiers, and tighten up the examples.
This document is the primary reference for the Rust programming language.
There are several pages for those working on the reference:
To build the Reference, first clone the project:
git clone https://github.com/rust-lang/reference.git cd reference
(Alternatively, if you don't want to use git, download a ZIP file of the project, extract it using your preferred tool, and rename the top-level directory to reference.)
The Reference is built using mdbook.
First, ensure that you have a recent copy of the nightly Rust compiler installed, as this is needed in order to run the tests:
rustup toolchain install nightly rustup override set nightly
Now, ensure you have mdbook installed, as this is needed in order to build the Reference:
cargo install --locked mdbook
mdbook provides a variety of different commands and options to help you work on the book:
mdbook build --open: Build the book and open it in a web browser.mdbook serve --open: Launches a web server on localhost. It also automatically rebuilds the book whenever any file changes and automatically reloads your web browser.The book contents are driven by a SUMMARY.md file, and every file must be linked there. See https://rust-lang.github.io/mdBook/ for its usage.
SPEC_RELATIVEThe SPEC_RELATIVE=0 environment variable makes links to the standard library go to https://doc.rust-lang.org/ instead of being relative, which is useful when viewing locally since you normally don't have a copy of the standard library.
SPEC_RELATIVE=0 mdbook serve --open
The published site at https://doc.rust-lang.org/reference/ (or local docs using rustup doc) does not set this, which means it will use relative links which supports offline viewing and links to the correct version (for example, links in https://doc.rust-lang.org/1.81.0/reference/ will stay within the 1.81.0 directory).
SPEC_DENY_WARNINGSThe SPEC_DENY_WARNINGS=1 environment variable will turn all warnings generated by mdbook-spec to errors. This is used in CI to ensure that there aren't any problems with the book content.
SPEC_RUST_ROOTThe SPEC_RUST_ROOT can be used to point to the directory of a checkout of https://github.com/rust-lang/rust. This is used by the test-linking feature so that it can find tests linked to reference rules. If this is not set, then the tests won't be linked.
There are several different kinds of tests you can run (these are enforced on CI):
mdbook test: This will run the inline Rust codeblocks (internally it uses rustdoc to do this).cargo xtask style-check: This will validate some style checks (see authoring guide).cargo xtask linkcheck: This will validate that markdown links aren't broken.cargo xtask test-all: Runs all tests.The process for getting the reference content into a Rust release and on the website is: