Skip to content

Commit ee100cc

Browse files
committed
Auto merge of #12339 - ehuss:heading-attributes, r=weihanglo
docs: Use heading attributes to control the fragment. mdBook recently gained the ability to use [heading attributes](https://rust-lang.github.io/mdBook/format/markdown.html#heading-attributes) which allows you to define the HTML id (and thus URL fragment) for a section. This is an improvement over using manual `id` tags since mdBook can now know which ID matches the section, and will automatically set up links and such. Some of these pages were using `id` tags to handle backwards-compat for old URLs. For those, I switched them to use redirects instead. One downside is that the links won't work in GitHub render previews. Overall I think the benefits are worth it, though.
2 parents a94d1d0 + a181267 commit ee100cc

File tree

5 files changed

+79
-118
lines changed

5 files changed

+79
-118
lines changed

Diff for: .github/workflows/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ jobs:
232232
- name: Install mdbook
233233
run: |
234234
mkdir mdbook
235-
curl -Lf https://github.com/rust-lang/mdBook/releases/download/v0.4.27/mdbook-v0.4.27-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=./mdbook
235+
curl -Lf https://github.com/rust-lang/mdBook/releases/download/v0.4.31/mdbook-v0.4.31-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=./mdbook
236236
echo `pwd`/mdbook >> $GITHUB_PATH
237237
- run: cd src/doc && mdbook build --dest-dir ../../target/doc
238238
- name: Run linkchecker.sh

Diff for: src/doc/src/reference/build-scripts.md

+16-31
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ The sections below describe how build scripts work, and the [examples
3434
chapter](build-script-examples.md) shows a variety of examples on how to write
3535
scripts.
3636

37-
> Note: The [`package.build` manifest key](manifest.md#package-build) can be
37+
> Note: The [`package.build` manifest key](manifest.md#the-build-field) can be
3838
> used to change the name of the build script, or disable it entirely.
3939
4040
### Life Cycle of a Build Script
@@ -132,8 +132,7 @@ one detailed below.
132132
scripts.
133133

134134

135-
<a id="rustc-link-arg"></a>
136-
#### `cargo:rustc-link-arg=FLAG`
135+
#### `cargo:rustc-link-arg=FLAG` {#rustc-link-arg}
137136

138137
The `rustc-link-arg` instruction tells Cargo to pass the [`-C link-arg=FLAG`
139138
option][link-arg] to the compiler, but only when building supported targets
@@ -143,26 +142,23 @@ linker script.
143142

144143
[link-arg]: ../../rustc/codegen-options/index.md#link-arg
145144

146-
<a id="rustc-link-arg-bin"></a>
147-
#### `cargo:rustc-link-arg-bin=BIN=FLAG`
145+
#### `cargo:rustc-link-arg-bin=BIN=FLAG` {#rustc-link-arg-bin}
148146

149147
The `rustc-link-arg-bin` instruction tells Cargo to pass the [`-C
150148
link-arg=FLAG` option][link-arg] to the compiler, but only when building
151149
the binary target with name `BIN`. Its usage is highly platform specific. It is useful
152150
to set a linker script or other linker options.
153151

154152

155-
<a id="rustc-link-arg-bins"></a>
156-
#### `cargo:rustc-link-arg-bins=FLAG`
153+
#### `cargo:rustc-link-arg-bins=FLAG` {#rustc-link-arg-bins}
157154

158155
The `rustc-link-arg-bins` instruction tells Cargo to pass the [`-C
159156
link-arg=FLAG` option][link-arg] to the compiler, but only when building a
160157
binary target. Its usage is highly platform specific. It is useful
161158
to set a linker script or other linker options.
162159

163160

164-
<a id="rustc-link-lib"></a>
165-
#### `cargo:rustc-link-lib=LIB`
161+
#### `cargo:rustc-link-lib=LIB` {#rustc-link-lib}
166162

167163
The `rustc-link-lib` instruction tells Cargo to link the given library using
168164
the compiler's [`-l` flag][option-link]. This is typically used to link a
@@ -187,30 +183,26 @@ The optional `KIND` may be one of `dylib`, `static`, or `framework`. See the
187183
[FFI]: ../../nomicon/ffi.md
188184

189185

190-
<a id="rustc-link-arg-tests"></a>
191-
#### `cargo:rustc-link-arg-tests=FLAG`
186+
#### `cargo:rustc-link-arg-tests=FLAG` {#rustc-link-arg-tests}
192187

193188
The `rustc-link-arg-tests` instruction tells Cargo to pass the [`-C
194189
link-arg=FLAG` option][link-arg] to the compiler, but only when building a
195190
tests target.
196191

197192

198-
<a id="rustc-link-arg-examples"></a>
199-
#### `cargo:rustc-link-arg-examples=FLAG`
193+
#### `cargo:rustc-link-arg-examples=FLAG` {#rustc-link-arg-examples}
200194

201195
The `rustc-link-arg-examples` instruction tells Cargo to pass the [`-C
202196
link-arg=FLAG` option][link-arg] to the compiler, but only when building an examples
203197
target.
204198

205-
<a id="rustc-link-arg-benches"></a>
206-
#### `cargo:rustc-link-arg-benches=FLAG`
199+
#### `cargo:rustc-link-arg-benches=FLAG` {#rustc-link-arg-benches}
207200

208201
The `rustc-link-arg-benches` instruction tells Cargo to pass the [`-C
209202
link-arg=FLAG` option][link-arg] to the compiler, but only when building a benchmark
210203
target.
211204

212-
<a id="rustc-link-search"></a>
213-
#### `cargo:rustc-link-search=[KIND=]PATH`
205+
#### `cargo:rustc-link-search=[KIND=]PATH` {#rustc-link-search}
214206

215207
The `rustc-link-search` instruction tells Cargo to pass the [`-L`
216208
flag][option-search] to the compiler to add a directory to the library search
@@ -228,16 +220,14 @@ is fine).
228220

229221
[option-search]: ../../rustc/command-line-arguments.md#option-l-search-path
230222

231-
<a id="rustc-flags"></a>
232-
#### `cargo:rustc-flags=FLAGS`
223+
#### `cargo:rustc-flags=FLAGS` {#rustc-flags}
233224

234225
The `rustc-flags` instruction tells Cargo to pass the given space-separated
235226
flags to the compiler. This only allows the `-l` and `-L` flags, and is
236227
equivalent to using [`rustc-link-lib`](#rustc-link-lib) and
237228
[`rustc-link-search`](#rustc-link-search).
238229

239-
<a id="rustc-cfg"></a>
240-
#### `cargo:rustc-cfg=KEY[="VALUE"]`
230+
#### `cargo:rustc-cfg=KEY[="VALUE"]` {#rustc-cfg}
241231

242232
The `rustc-cfg` instruction tells Cargo to pass the given value to the
243233
[`--cfg` flag][option-cfg] to the compiler. This may be used for compile-time
@@ -258,8 +248,7 @@ identifier, the value should be a string.
258248
[conditional compilation]: ../../reference/conditional-compilation.md
259249
[option-cfg]: ../../rustc/command-line-arguments.md#option-cfg
260250

261-
<a id="rustc-env"></a>
262-
#### `cargo:rustc-env=VAR=VALUE`
251+
#### `cargo:rustc-env=VAR=VALUE` {#rustc-env}
263252

264253
The `rustc-env` instruction tells Cargo to set the given environment variable
265254
when compiling the package. The value can be then retrieved by the [`env!`
@@ -279,17 +268,15 @@ Cargo][env-cargo].
279268
[env-macro]: ../../std/macro.env.html
280269
[env-cargo]: environment-variables.md#environment-variables-cargo-sets-for-crates
281270

282-
<a id="rustc-cdylib-link-arg"></a>
283-
#### `cargo:rustc-cdylib-link-arg=FLAG`
271+
#### `cargo:rustc-cdylib-link-arg=FLAG` {#rustc-cdylib-link-arg}
284272

285273
The `rustc-cdylib-link-arg` instruction tells Cargo to pass the [`-C
286274
link-arg=FLAG` option][link-arg] to the compiler, but only when building a
287275
`cdylib` library target. Its usage is highly platform specific. It is useful
288276
to set the shared library version or the runtime-path.
289277

290278

291-
<a id="cargo-warning"></a>
292-
#### `cargo:warning=MESSAGE`
279+
#### `cargo:warning=MESSAGE` {#cargo-warning}
293280

294281
The `warning` instruction tells Cargo to display a warning after the build
295282
script has finished running. Warnings are only shown for `path` dependencies
@@ -334,8 +321,7 @@ FAQ](../faq.md#why-is-cargo-rebuilding-my-code).
334321

335322
[`exclude` and `include` fields]: manifest.md#the-exclude-and-include-fields
336323

337-
<a id="rerun-if-changed"></a>
338-
#### `cargo:rerun-if-changed=PATH`
324+
#### `cargo:rerun-if-changed=PATH` {#rerun-if-changed}
339325

340326
The `rerun-if-changed` instruction tells Cargo to re-run the build script if
341327
the file at the given path has changed. Currently, Cargo only uses the
@@ -354,8 +340,7 @@ automatically handles whether or not the script itself needs to be recompiled,
354340
and of course the script will be re-run after it has been recompiled.
355341
Otherwise, specifying `build.rs` is redundant and unnecessary.
356342

357-
<a id="rerun-if-env-changed"></a>
358-
#### `cargo:rerun-if-env-changed=NAME`
343+
#### `cargo:rerun-if-env-changed=NAME` {#rerun-if-env-changed}
359344

360345
The `rerun-if-env-changed` instruction tells Cargo to re-run the build script
361346
if the value of an environment variable of the given name has changed.

Diff for: src/doc/src/reference/manifest.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ Every manifest file consists of the following sections:
5353
* [`[profile]`](profiles.md) --- Compiler settings and optimizations.
5454
* [`[workspace]`](workspaces.md) --- The workspace definition.
5555

56-
<a id="package-metadata"></a>
5756
### The `[package]` section
5857

5958
The first section in a `Cargo.toml` is `[package]`.
@@ -112,7 +111,6 @@ breaking change.
112111
[Resolver]: resolver.md
113112
[SemVer compatibility]: semver.md
114113

115-
<a id="the-authors-field-optional"></a>
116114
#### The `authors` field
117115

118116
The optional `authors` field lists in an array the people or organizations that are considered
@@ -135,7 +133,6 @@ user interface.
135133
> field cannot be changed or removed in already-published versions of a
136134
> package.
137135
138-
<a id="the-edition-field-optional"></a>
139136
#### The `edition` field
140137

141138
The `edition` key is an optional key that affects which [Rust Edition] your package
@@ -198,7 +195,6 @@ description = "A short description of my package"
198195

199196
> **Note**: [crates.io] requires the `description` to be set.
200197
201-
<a id="the-documentation-field-optional"></a>
202198
#### The `documentation` field
203199

204200
The `documentation` field specifies a URL to a website hosting the crate's
@@ -326,7 +322,6 @@ categories = ["command-line-utilities", "development-tools::cargo-plugins"]
326322
> match one of the strings available at <https://crates.io/category_slugs>, and
327323
> must match exactly.
328324
329-
<a id="the-workspace--field-optional"></a>
330325
#### The `workspace` field
331326

332327
The `workspace` field can be used to configure the workspace that this package
@@ -347,8 +342,6 @@ table defined. That is, a crate cannot both be a root crate in a workspace
347342

348343
For more information, see the [workspaces chapter](workspaces.md).
349344

350-
<a id="package-build"></a>
351-
<a id="the-build-field-optional"></a>
352345
#### The `build` field
353346

354347
The `build` field specifies a file in the package root which is a [build
@@ -368,7 +361,6 @@ The default is `"build.rs"`, which loads the script from a file named
368361
specify a path to a different file or `build = false` to disable automatic
369362
detection of the build script.
370363

371-
<a id="the-links-field-optional"></a>
372364
#### The `links` field
373365

374366
The `links` field specifies the name of a native library that is being linked
@@ -386,7 +378,6 @@ on Linux) may specify:
386378
links = "git2"
387379
```
388380

389-
<a id="the-exclude-and-include-fields-optional"></a>
390381
#### The `exclude` and `include` fields
391382

392383
The `exclude` and `include` fields can be used to explicitly specify which
@@ -476,7 +467,6 @@ if any of those files change.
476467

477468
[gitignore]: https://git-scm.com/docs/gitignore
478469

479-
<a id="the-publish--field-optional"></a>
480470
#### The `publish` field
481471

482472
The `publish` field can be used to prevent a package from being published to a
@@ -501,7 +491,6 @@ publish = ["some-registry-name"]
501491
If publish array contains a single registry, `cargo publish` command will use
502492
it when `--registry` flag is not specified.
503493

504-
<a id="the-metadata-table-optional"></a>
505494
#### The `metadata` table
506495

507496
Cargo by default will warn about unused keys in `Cargo.toml` to assist in
@@ -624,6 +613,17 @@ more detail.
624613
"#the-patch-section": "overriding-dependencies.html#the-patch-section",
625614
"#using-patch-with-multiple-versions": "overriding-dependencies.html#using-patch-with-multiple-versions",
626615
"#the-replace-section": "overriding-dependencies.html#the-replace-section",
616+
"#package-metadata": "manifest.html#the-package-section",
617+
"#the-authors-field-optional": "manifest.html#the-authors-field",
618+
"#the-edition-field-optional": "manifest.html#the-edition-field",
619+
"#the-documentation-field-optional": "manifest.html#the-documentation-field",
620+
"#the-workspace--field-optional": "manifest.html#the-workspace-field",
621+
"#package-build": "manifest.html#the-build-field",
622+
"#the-build-field-optional": "manifest.html#the-build-field",
623+
"#the-links-field-optional": "manifest.html#the-links-field",
624+
"#the-exclude-and-include-fields-optional": "manifest.html#the-exclude-and-include-fields",
625+
"#the-publish--field-optional": "manifest.html#the-publish-field",
626+
"#the-metadata-table-optional": "manifest.html#the-metadata-table",
627627
};
628628
var target = fragments[window.location.hash];
629629
if (target) {

0 commit comments

Comments
 (0)