Skip to content

Commit dbbab42

Browse files
committed
Auto merge of #8509 - ehuss:stabilize-crate-version, r=Eh2406
Stabilize -Z crate-versions This stabilizes the `-Z crate-versions` flag which forwards the crate version to rustdoc so it can display the version in the sidebar. The flag in rustdoc was stabilized in 1.44. Closes #7907
2 parents eb7bc68 + 3ce3d34 commit dbbab42

File tree

6 files changed

+31
-49
lines changed

6 files changed

+31
-49
lines changed

src/bin/cargo/cli.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ Available unstable (nightly-only) flags:
3636
-Z unstable-options -- Allow the usage of unstable options
3737
-Z timings -- Display concurrency information
3838
-Z doctest-xcompile -- Compile and run doctests for non-host target using runner config
39-
-Z crate-versions -- Add crate versions to generated docs
4039
-Z terminal-width -- Provide a terminal width to rustc for error truncation
4140
4241
Run with 'cargo -Z [FLAG] [SUBCOMMAND]'"

src/cargo/core/compiler/mod.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,9 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
579579

580580
rustdoc.args(bcx.rustdocflags_args(unit));
581581

582-
add_crate_versions_if_requested(bcx, unit, &mut rustdoc);
582+
if !crate_version_flag_already_present(&rustdoc) {
583+
append_crate_version_flag(unit, &mut rustdoc);
584+
}
583585

584586
let name = unit.pkg.name().to_string();
585587
let build_script_outputs = Arc::clone(&cx.build_script_outputs);
@@ -617,16 +619,6 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
617619
}))
618620
}
619621

620-
fn add_crate_versions_if_requested(
621-
bcx: &BuildContext<'_, '_>,
622-
unit: &Unit,
623-
rustdoc: &mut ProcessBuilder,
624-
) {
625-
if bcx.config.cli_unstable().crate_versions && !crate_version_flag_already_present(rustdoc) {
626-
append_crate_version_flag(unit, rustdoc);
627-
}
628-
}
629-
630622
// The --crate-version flag could have already been passed in RUSTDOCFLAGS
631623
// or as an extra compiler argument for rustdoc
632624
fn crate_version_flag_already_present(rustdoc: &ProcessBuilder) -> bool {

src/cargo/core/features.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,6 @@ pub struct CliUnstable {
356356
pub panic_abort_tests: bool,
357357
pub jobserver_per_rustc: bool,
358358
pub features: Option<Vec<String>>,
359-
pub crate_versions: bool,
360359
pub separate_nightlies: bool,
361360
pub multitarget: bool,
362361
pub rustdoc_map: bool,
@@ -462,7 +461,6 @@ impl CliUnstable {
462461
"panic-abort-tests" => self.panic_abort_tests = parse_empty(k, v)?,
463462
"jobserver-per-rustc" => self.jobserver_per_rustc = parse_empty(k, v)?,
464463
"features" => self.features = Some(parse_features(v)),
465-
"crate-versions" => self.crate_versions = parse_empty(k, v)?,
466464
"separate-nightlies" => self.separate_nightlies = parse_empty(k, v)?,
467465
"multitarget" => self.multitarget = parse_empty(k, v)?,
468466
"rustdoc-map" => self.rustdoc_map = parse_empty(k, v)?,

src/doc/src/reference/unstable.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -646,13 +646,6 @@ resolver = "2"
646646
The `resolver` field is ignored in dependencies, only the top-level project or
647647
workspace can control the new behavior.
648648

649-
### crate-versions
650-
* Tracking Issue: [#7907](https://github.com/rust-lang/cargo/issues/7907)
651-
652-
The `-Z crate-versions` flag will make `cargo doc` include appropriate crate versions for the current crate and all of its dependencies (unless `--no-deps` was provided) in the compiled documentation.
653-
654-
You can find an example screenshot for the cargo itself in the tracking issue.
655-
656649
### unit-graph
657650
* Tracking Issue: [#8002](https://github.com/rust-lang/cargo/issues/8002)
658651

tests/testsuite/doc.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,10 +1479,6 @@ fn bin_private_items_deps() {
14791479

14801480
#[cargo_test]
14811481
fn crate_versions() {
1482-
// Testing flag that will reach stable on 1.44
1483-
if !is_nightly() {
1484-
return;
1485-
}
14861482
let p = project()
14871483
.file(
14881484
"Cargo.toml",
@@ -1496,8 +1492,14 @@ fn crate_versions() {
14961492
.file("src/lib.rs", "")
14971493
.build();
14981494

1499-
p.cargo("-Z crate-versions doc")
1500-
.masquerade_as_nightly_cargo()
1495+
p.cargo("doc -v")
1496+
.with_stderr(
1497+
"\
1498+
[DOCUMENTING] foo v1.2.4 [..]
1499+
[RUNNING] `rustdoc --crate-type lib --crate-name foo src/lib.rs [..]--crate-version 1.2.4`
1500+
[FINISHED] [..]
1501+
",
1502+
)
15011503
.run();
15021504

15031505
let output_path = p.root().join("target/doc/foo/index.html");
@@ -1508,10 +1510,6 @@ fn crate_versions() {
15081510

15091511
#[cargo_test]
15101512
fn crate_versions_flag_is_overridden() {
1511-
// Testing flag that will reach stable on 1.44
1512-
if !is_nightly() {
1513-
return;
1514-
}
15151513
let p = project()
15161514
.file(
15171515
"Cargo.toml",
@@ -1534,16 +1532,13 @@ fn crate_versions_flag_is_overridden() {
15341532
assert!(html.contains("Version 2.0.3"));
15351533
};
15361534

1537-
p.cargo("-Z crate-versions doc")
1538-
.masquerade_as_nightly_cargo()
1535+
p.cargo("doc")
15391536
.env("RUSTDOCFLAGS", "--crate-version 2.0.3")
15401537
.run();
15411538
asserts(output_documentation());
15421539

15431540
p.build_dir().rm_rf();
15441541

1545-
p.cargo("-Z crate-versions rustdoc -- --crate-version 2.0.3")
1546-
.masquerade_as_nightly_cargo()
1547-
.run();
1542+
p.cargo("rustdoc -- --crate-version 2.0.3").run();
15481543
asserts(output_documentation());
15491544
}

tests/testsuite/rustdoc.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Tests for the `cargo rustdoc` command.
22
3-
use cargo_test_support::{basic_manifest, project};
3+
use cargo_test_support::{basic_manifest, cross_compile, project};
44

55
#[cargo_test]
66
fn rustdoc_simple() {
@@ -13,7 +13,7 @@ fn rustdoc_simple() {
1313
[RUNNING] `rustdoc [..]--crate-name foo src/lib.rs [..]\
1414
-o [CWD]/target/doc \
1515
[..] \
16-
-L dependency=[CWD]/target/debug/deps`
16+
-L dependency=[CWD]/target/debug/deps [..]`
1717
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
1818
",
1919
)
@@ -32,7 +32,7 @@ fn rustdoc_args() {
3232
-o [CWD]/target/doc \
3333
[..] \
3434
--cfg=foo \
35-
-L dependency=[CWD]/target/debug/deps`
35+
-L dependency=[CWD]/target/debug/deps [..]`
3636
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
3737
",
3838
)
@@ -122,7 +122,7 @@ fn rustdoc_only_bar_dependency() {
122122
-o [CWD]/target/doc \
123123
[..] \
124124
--cfg=foo \
125-
-L dependency=[CWD]/target/debug/deps`
125+
-L dependency=[CWD]/target/debug/deps [..]`
126126
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
127127
",
128128
)
@@ -144,7 +144,7 @@ fn rustdoc_same_name_documents_lib() {
144144
-o [CWD]/target/doc \
145145
[..] \
146146
--cfg=foo \
147-
-L dependency=[CWD]/target/debug/deps`
147+
-L dependency=[CWD]/target/debug/deps [..]`
148148
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
149149
",
150150
)
@@ -203,21 +203,26 @@ fn proc_macro_crate_type() {
203203
}
204204

205205
#[cargo_test]
206-
#[cfg(all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"))]
207206
fn rustdoc_target() {
207+
if cross_compile::disabled() {
208+
return;
209+
}
210+
208211
let p = project().file("src/lib.rs", "").build();
209212

210-
p.cargo("rustdoc --verbose --target x86_64-unknown-linux-gnu")
211-
.with_stderr(
213+
p.cargo("rustdoc --verbose --target")
214+
.arg(cross_compile::alternate())
215+
.with_stderr(format!(
212216
"\
213217
[DOCUMENTING] foo v0.0.1 ([..])
214218
[RUNNING] `rustdoc [..]--crate-name foo src/lib.rs [..]\
215-
--target x86_64-unknown-linux-gnu \
216-
-o [CWD]/target/x86_64-unknown-linux-gnu/doc \
219+
--target {target} \
220+
-o [CWD]/target/{target}/doc \
217221
[..] \
218-
-L dependency=[CWD]/target/x86_64-unknown-linux-gnu/debug/deps \
219-
-L dependency=[CWD]/target/debug/deps`
222+
-L dependency=[CWD]/target/{target}/debug/deps \
223+
-L dependency=[CWD]/target/debug/deps[..]`
220224
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]",
221-
)
225+
target = cross_compile::alternate()
226+
))
222227
.run();
223228
}

0 commit comments

Comments
 (0)