Skip to content

Commit bbb2b92

Browse files
committed
Pass edition to rustdoc.
Fixes #5279.
1 parent 0729e06 commit bbb2b92

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/cargo/ops/cargo_rustc/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,13 @@ fn rustdoc<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoResult
776776
rustdoc.arg("--cfg").arg(&format!("feature=\"{}\"", feat));
777777
}
778778

779+
let manifest = unit.pkg.manifest();
780+
781+
if manifest.features().is_enabled(Feature::edition()) {
782+
rustdoc.arg("-Zunstable-options");
783+
rustdoc.arg(format!("--edition={}", &manifest.edition()));
784+
}
785+
779786
if let Some(ref args) = unit.profile.rustdoc_args {
780787
rustdoc.args(args);
781788
}

tests/testsuite/doc.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::str;
33
use std::fs::{self, File};
44
use std::io::Read;
55

6-
use cargotest::rustc_host;
6+
use cargotest::{rustc_host, ChannelChanger};
77
use cargotest::support::{execs, project, path2url};
88
use cargotest::support::registry::Package;
99
use hamcrest::{assert_that, existing_dir, existing_file, is_not};
@@ -1464,3 +1464,33 @@ fn doc_workspace_open_help_message() {
14641464
.with_stderr_contains(" bar"),
14651465
);
14661466
}
1467+
1468+
#[test]
1469+
fn doc_edition() {
1470+
if !cargotest::is_nightly() {
1471+
// Stable rustdoc won't have the edition option. Remove this once it
1472+
// is stabilized.
1473+
return;
1474+
}
1475+
let p = project("foo")
1476+
.file(
1477+
"Cargo.toml",
1478+
r#"
1479+
cargo-features = ["edition"]
1480+
[package]
1481+
name = "foo"
1482+
version = "0.0.1"
1483+
authors = []
1484+
rust = "2018"
1485+
"#,
1486+
)
1487+
.file("src/lib.rs", "")
1488+
.build();
1489+
1490+
assert_that(
1491+
p.cargo("doc").arg("-v").masquerade_as_nightly_cargo(),
1492+
execs()
1493+
.with_status(0)
1494+
.with_stderr_contains("[RUNNING] `rustdoc [..]-Zunstable-options --edition=2018[..]"),
1495+
);
1496+
}

0 commit comments

Comments
 (0)