Skip to content

Commit 1f831ec

Browse files
authored
Merge branch 'master' into spec-inline-assembly-tests
2 parents b41a30f + d6d24b9 commit 1f831ec

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+4092
-624
lines changed

.github/workflows/main.yml

+46-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
merge_group:
55

66
env:
7-
MDBOOK_VERSION: 0.4.40
7+
MDBOOK_VERSION: 0.4.43
88

99
jobs:
1010
code-tests:
@@ -35,6 +35,11 @@ jobs:
3535
runs-on: ubuntu-latest
3636
steps:
3737
- uses: actions/checkout@master
38+
- name: Checkout rust-lang/rust
39+
uses: actions/checkout@master
40+
with:
41+
repository: rust-lang/rust
42+
path: rust
3843
- name: Update rustup
3944
run: rustup self update
4045
- name: Install Rust
@@ -52,16 +57,17 @@ jobs:
5257
rustup --version
5358
rustc -Vv
5459
mdbook --version
55-
- name: Verify the book builds
56-
env:
57-
SPEC_DENY_WARNINGS: 1
58-
run: mdbook build
5960
- name: Style checks
6061
working-directory: style-check
6162
run: cargo run --locked -- ../src
6263
- name: Style fmt
6364
working-directory: style-check
6465
run: cargo fmt --check
66+
- name: Verify the book builds
67+
env:
68+
SPEC_DENY_WARNINGS: 1
69+
SPEC_RUST_ROOT: ${{ github.workspace }}/rust
70+
run: mdbook build
6571
- name: Check for broken links
6672
run: |
6773
curl -sSLo linkcheck.sh \
@@ -98,6 +104,40 @@ jobs:
98104
working-directory: ./mdbook-spec
99105
run: cargo fmt --check
100106

107+
preview:
108+
if: github.event_name == 'pull_request'
109+
runs-on: ubuntu-latest
110+
steps:
111+
- uses: actions/checkout@master
112+
- name: Checkout rust-lang/rust
113+
uses: actions/checkout@master
114+
with:
115+
repository: rust-lang/rust
116+
path: rust
117+
- name: Update rustup
118+
run: rustup self update
119+
- name: Install Rust
120+
run: |
121+
rustup set profile minimal
122+
rustup toolchain install nightly
123+
rustup default nightly
124+
- name: Install mdbook
125+
run: |
126+
mkdir bin
127+
curl -sSL https://github.com/rust-lang/mdBook/releases/download/v${MDBOOK_VERSION}/mdbook-v${MDBOOK_VERSION}-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=bin
128+
echo "$(pwd)/bin" >> $GITHUB_PATH
129+
- name: Build the book
130+
env:
131+
SPEC_RELATIVE: 0
132+
SPEC_RUST_ROOT: ${{ github.workspace }}/rust
133+
run: mdbook build --dest-dir dist/preview-${{ github.event.pull_request.number }}
134+
- name: Upload artifact
135+
uses: actions/upload-artifact@v4
136+
with:
137+
name: preview-${{ github.event.pull_request.number }}
138+
overwrite: true
139+
path: dist
140+
101141
# The success job is here to consolidate the total success/failure state of
102142
# all other jobs. This job is then included in the GitHub branch protection
103143
# rule which prevents merges unless all other jobs are passing. This makes
@@ -110,6 +150,7 @@ jobs:
110150
- code-tests
111151
- style-tests
112152
- mdbook-spec
153+
# preview is explicitly excluded here since it doesn't run on merge
113154
runs-on: ubuntu-latest
114155
steps:
115156
- run: jq --exit-status 'all(.result == "success")' <<< '${{ toJson(needs) }}'

README.md

+14-2
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,22 @@ SPEC_RELATIVE=0 mdbook build --open
6666

6767
This will open a browser with a websocket live-link to automatically reload whenever the source is updated.
6868

69-
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.
70-
7169
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:
7270

7371
```sh
7472
SPEC_RELATIVE=0 mdbook serve --open
7573
```
74+
75+
### `SPEC_RELATIVE`
76+
77+
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.
78+
79+
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).
80+
81+
### `SPEC_DENY_WARNINGS`
82+
83+
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.
84+
85+
### `SPEC_RUST_ROOT`
86+
87+
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.

book.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ author = "The Rust Project Developers"
55

66
[output.html]
77
additional-css = ["theme/reference.css"]
8+
additional-js = ["theme/reference.js"]
89
git-repository-url = "https://github.com/rust-lang/reference/"
910
edit-url-template = "https://github.com/rust-lang/reference/edit/master/{path}"
1011
smart-punctuation = true
@@ -15,7 +16,7 @@ smart-punctuation = true
1516
"/unsafe-functions.html" = "unsafe-keyword.html"
1617

1718
[rust]
18-
edition = "2021"
19+
edition = "2024"
1920

2021
[preprocessor.spec]
2122
command = "cargo run --release --manifest-path mdbook-spec/Cargo.toml"

docs/authoring.md

+41-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ This document serves as a guide for editors and reviewers. Some conventions and
1515
* Code blocks should have an explicit language tag.
1616
* Do not wrap long lines. This helps with reviewing diffs of the source.
1717
* Use [smart punctuation] instead of Unicode characters. For example, use `---` for em-dash instead of the Unicode character. Characters like em-dash can be difficult to see in a fixed-width editor, and some editors may not have easy methods to enter such characters.
18-
* Links should be relative with the `.md` extension. Links to other rust-lang books that are published with the reference or the standard library API should also be relative so that the linkchecker can validate them.
18+
* Links should be relative with the `.md` extension. Links to other rust-lang books that are published with the reference should also be relative so that the linkchecker can validate them.
19+
* Links to the standard library should use rustdoc-style links described in [Standard library links](#standard-library-links).
1920
* The use of reference links is preferred, with shortcuts if appropriate. Place the sorted link reference definitions at the bottom of the file, or at the bottom of a section if there are an unusually large number of links that are specific to the section.
2021

2122
```markdown
@@ -75,6 +76,45 @@ Rules can be linked to by their ID using markdown such as `[foo.bar]`. There are
7576

7677
In the HTML, the rules are clickable just like headers.
7778

79+
When assigning rules to new paragraphs, or when modifying rule names, use the following guidelines:
80+
81+
1. A rule applies to one core idea, which should be easily determined when reading the paragraph it is applied to.
82+
2. Other than the "intro" paragraph, purely explanatory, expository, or exemplary content does not need a rule. If the expository paragraph isn't directly related to the previous, separate it with a hard (rendered) line break.
83+
* This content will be moved to `[!NOTE]` or more specific admonitions in the future.
84+
3. Rust code examples and tests do not need their own rules.
85+
4. Use the following guidelines for admonitions:
86+
* Notes: Do not include a rule.
87+
* Warning: Omit the rule if the warning follows from the previous paragraph or if the warning is explanatory and doesn't introduce any new rules.
88+
* Target specific behavior: Always include the rule.
89+
* Edition differences: Always include the rule.
90+
5. The following keywords should be used to identify paragraphs when unambiguous:
91+
* `intro`: The beginning paragraph of each section - should explain the construct being defined overall.
92+
* `syntax`: Syntax definitions or explanations when BNF syntax definitions are not used.
93+
* `namespace`: For items only, specifies the namespace(s) the item introduces a name in. May also be used elsewhere when defining a namespace (e.g. `r[attribute.diagnostic.namespace]`).
94+
6. When a rule doesn't fall under the above keywords, or for section rule ids, name the subrule as follows:
95+
* If the rule is naming a specific Rust language construct (e.g. an attribute, standard library type/function, or keyword-introduced concept), use the construct as named in the language, appropriately case-adjusted (but do not replace `_`s with `-`s).
96+
* Other than Rust language concepts with `_`s in the name, use `-` characters to separate words within a "subrule".
97+
* Whenever possible, do not repeat previous components of the rule.
98+
* Edition differences admonitions should typically be named by the edition referenced directly by the rule. If multiple editions are named, use the one for which the behavior is defined by the admonition, and not by a previous paragraph.
99+
* Target specific admonitions should typically be named by the least specific target property to which they apply (e.g. if a rule affects all x86 CPUs, the rule name should include `x86` rather than separately listing `i586`, `i686` and `x86_64`, and if a rule applies to all ELF platforms, it should be named `elf` rather than listing every ELF OS).
100+
* Use an appropriately descriptive, but short, name if the language does not provide one.
101+
102+
#### Test rule annotations
103+
104+
Tests in <https://github.com/rust-lang/rust> can be linked to rules in the reference. The rule will include a link to the tests, and there is also an [appendix] which tracks how the rules are currently linked.
105+
106+
Tests in the `tests` directory can be annotated with the `//@ reference: x.y.z` header to link it to a rule. The header can be specified multiple times if a single file covers multiple rules.
107+
108+
Compiler developers are not expected to add `reference` annotations to tests. However, if they do want to help, their cooperation is very welcome. Reference authors and editors are responsible for making sure every rule has a test associated with it.
109+
110+
The tests are beneficial for reviewers to see the behavior of a rule. It is also a benefit to readers who may want to see examples of particular behaviors. When adding new rules, you should wait until the reference side is approved before submitting a PR to `rust-lang/rust` (to avoid churn if we decide on different names).
111+
112+
Prefixed rule names should not be used in tests. That is, do not use something like `asm.rules` when there are specific rules like `asm.rules.reg-not-input`.
113+
114+
We are not expecting 100% coverage at any time. Although it would be nice, it is unrealistic due to the sequence things are developed, and resources available.
115+
116+
[appendix]: https://doc.rust-lang.org/nightly/reference/test-summary.html
117+
78118
### Standard library links
79119

80120
You should link to the standard library without specifying a URL in a fashion similar to [rustdoc intra-doc links][intra]. Some examples:

0 commit comments

Comments
 (0)