Skip to content

Commit b1b50e4

Browse files
authored
Merge pull request #1578 from ehuss/std-links
Rewrite the automatic std link translation, and switch to automatic links
2 parents 135bdee + b308070 commit b1b50e4

Some content is hidden

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

44 files changed

+331
-268
lines changed

Diff for: README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,15 @@ To build the Reference locally (in `build/`) and open it in a web
6161
browser, run:
6262

6363
```sh
64-
mdbook build --open
64+
SPEC_RELATIVE=0 mdbook build --open
6565
```
6666

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

69-
You can also open any current build of the reference by running:
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+
71+
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:
7072

7173
```sh
72-
mdbook serve --open
74+
SPEC_RELATIVE=0 mdbook serve --open
7375
```

Diff for: book.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ smart-punctuation = true
1818
edition = "2021"
1919

2020
[preprocessor.spec]
21-
command = "cargo run --manifest-path mdbook-spec/Cargo.toml"
21+
command = "cargo run --release --manifest-path mdbook-spec/Cargo.toml"
2222

2323
[build]
2424
extra-watch-dirs = ["mdbook-spec/src"]

Diff for: docs/authoring.md

+9
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@ Explicit namespace disambiguation is also supported:
109109
[`std::vec`](mod@std::vec)
110110
```
111111

112+
Beware there are some limitations, for example:
113+
114+
- Links to rexports from `std_arch` don't work due to <https://github.com/rust-lang/rust/issues/96506>.
115+
- Links to keywords aren't supported.
116+
- Links to trait impls where the trait is not in the prelude doesn't work. Traits must be in scope, and there currently isn't a way to add those.
117+
- If there are multiple generic implementations, it will link to one randomly (see <https://github.com/rust-lang/rust/issues/76895>).
118+
119+
When running into a rustdoc limitation, consider manually linking to the correct page using a relative link. For example, `../std/arch/macro.is_x86_feature_detected.html`.
120+
112121
[intra]: https://doc.rust-lang.org/rustdoc/write-documentation/linking-to-items-by-name.html
113122

114123
### Admonitions

Diff for: mdbook-spec/Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: mdbook-spec/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ anyhow = "1.0.79"
1313
mdbook = { version = "0.4.36", default-features = false }
1414
once_cell = "1.19.0"
1515
pathdiff = "0.2.1"
16+
# Try to keep in sync with mdbook.
17+
pulldown-cmark = { version = "0.10.3", default-features = false }
1618
regex = "1.9.4"
1719
semver = "1.0.21"
1820
serde_json = "1.0.113"

Diff for: mdbook-spec/src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ impl Preprocessor for Spec {
154154
}
155155
ch.content = self.rule_definitions(&ch, &mut found_rules);
156156
ch.content = self.admonitions(&ch);
157-
ch.content = std_links::std_links(&ch);
158157
});
159158
// This is a separate pass because it relies on the modifications of
160159
// the previous passes.
@@ -167,6 +166,10 @@ impl Preprocessor for Spec {
167166
}
168167
ch.content = self.auto_link_references(&ch, &found_rules);
169168
});
169+
// Final pass will resolve everything as a std link (or error if the
170+
// link is unknown).
171+
std_links::std_links(&mut book);
172+
170173
Ok(book)
171174
}
172175
}

0 commit comments

Comments
 (0)