commit | 1fc4b67256ef0691d67057231a3f3630be0ef6e6 | [log] [tgz] |
---|---|---|
author | Travis Cross <tc@traviscross.com> | Wed May 14 12:39:49 2025 +0000 |
committer | Eric Huss <eric@huss.org> | Thu May 15 05:56:33 2025 -0700 |
tree | f44bd01acf2404de88a1c7f2d0656f8e39a22f84 | |
parent | 048d75aa5f881235c88256b6d3fdaaaeadb5aa32 [diff] |
Fix grammar for `LiteralPattern` regarding `-` We had documented that only numeric literals in patterns can be prefixed by `-` (minus), but the Rust parser happily accepts a minus ahead of all literals in patterns. E.g.: ```rust match () { -true | -false => (), -'x' => (), -b'x' => (), -"x" => (), -r"x" => (), -br"x" => (), -c"x" => (), -cr"x" => (), -1 => (), -1.1 => (), } ``` In the compiler, this happens in `Parser::parse_literal_maybe_minus` and `Token::can_begin_literal_maybe_minus`. Let's fix this by defining `LiteralPattern` as a `LiteralExpression` optionally prefixed by the minus sign. This better matches how the `rustc` AST models this.
This document is the primary reference for the Rust programming language.
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
Now, ensure you have mdbook
installed, as this is needed in order to build the Reference:
cargo install --locked mdbook
To build the Reference, first clone the project:
git clone https://github.com/rust-lang/reference.git
(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
.)
Now change your current directory to the working directory:
cd reference
To test all of the code examples in the Reference, run:
mdbook test
For authors, consider using the server functionality which supports automatic reload.
To build the Reference locally (in build/
) and open it in a web browser, run:
SPEC_RELATIVE=0 mdbook build --open
This will open a browser with a websocket live-link to automatically reload whenever the source is updated.
You can also use mdbook's live webserver option, which will automatically rebuild the book and reload your web browser whenever a source file is modified:
SPEC_RELATIVE=0 mdbook serve --open
SPEC_RELATIVE
The 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.
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_WARNINGS
The 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_ROOT
The 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.