Skip to content

Commit 64f8f1b

Browse files
committed
Auto merge of #5541 - ehuss:fix-rustdoc-edition, r=alexcrichton
Fix passing --edition to rustdoc during doctests. Fixes #5538
2 parents f352115 + 3dbae34 commit 64f8f1b

File tree

4 files changed

+30
-32
lines changed

4 files changed

+30
-32
lines changed

src/cargo/core/compiler/compilation.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::path::PathBuf;
55
use semver::Version;
66
use lazycell::LazyCell;
77

8-
use core::{Package, PackageId, Target, TargetKind};
8+
use core::{Feature, Package, PackageId, Target, TargetKind};
99
use util::{self, join_paths, process, CargoResult, Config, ProcessBuilder};
1010
use super::BuildContext;
1111

@@ -93,12 +93,23 @@ impl<'cfg> Compilation<'cfg> {
9393

9494
/// See `process`.
9595
pub fn rustc_process(&self, pkg: &Package) -> CargoResult<ProcessBuilder> {
96-
self.fill_env(self.rustc_process.clone(), pkg, true)
96+
let mut p = self.fill_env(self.rustc_process.clone(), pkg, true)?;
97+
let manifest = pkg.manifest();
98+
if manifest.features().is_enabled(Feature::edition()) {
99+
p.arg(format!("--edition={}", manifest.edition()));
100+
}
101+
Ok(p)
97102
}
98103

99104
/// See `process`.
100105
pub fn rustdoc_process(&self, pkg: &Package) -> CargoResult<ProcessBuilder> {
101-
self.fill_env(process(&*self.config.rustdoc()?), pkg, false)
106+
let mut p = self.fill_env(process(&*self.config.rustdoc()?), pkg, false)?;
107+
let manifest = pkg.manifest();
108+
if manifest.features().is_enabled(Feature::edition()) {
109+
p.arg("-Zunstable-options");
110+
p.arg(format!("--edition={}", &manifest.edition()));
111+
}
112+
Ok(p)
102113
}
103114

104115
/// See `process`.

src/cargo/core/compiler/mod.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use serde_json;
1010

1111
use core::profiles::{Lto, Profile};
1212
use core::shell::ColorChoice;
13-
use core::{Feature, PackageId, Target};
13+
use core::{PackageId, Target};
1414
use util::errors::{CargoResult, CargoResultExt, Internal};
1515
use util::paths;
1616
use util::{self, machine_message, Freshness, ProcessBuilder};
@@ -596,13 +596,6 @@ fn rustdoc<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoResult
596596
rustdoc.arg("--cfg").arg(&format!("feature=\"{}\"", feat));
597597
}
598598

599-
let manifest = unit.pkg.manifest();
600-
601-
if manifest.features().is_enabled(Feature::edition()) {
602-
rustdoc.arg("-Zunstable-options");
603-
rustdoc.arg(format!("--edition={}", &manifest.edition()));
604-
}
605-
606599
if let Some(ref args) = bcx.extra_args_for(unit) {
607600
rustdoc.args(args);
608601
}
@@ -739,11 +732,6 @@ fn build_base_args<'a, 'cfg>(
739732
cmd.arg("-C").arg(format!("panic={}", panic));
740733
}
741734
}
742-
let manifest = unit.pkg.manifest();
743-
744-
if manifest.features().is_enabled(Feature::edition()) {
745-
cmd.arg(format!("--edition={}", manifest.edition()));
746-
}
747735

748736
// Disable LTO for host builds as prefer_dynamic and it are mutually
749737
// exclusive.

tests/testsuite/doc.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,6 +1508,13 @@ fn doc_edition() {
15081508
.with_status(0)
15091509
.with_stderr_contains("[RUNNING] `rustdoc [..]-Zunstable-options --edition=2018[..]"),
15101510
);
1511+
1512+
assert_that(
1513+
p.cargo("test -v").masquerade_as_nightly_cargo(),
1514+
execs()
1515+
.with_status(0)
1516+
.with_stderr_contains("[RUNNING] `rustdoc [..]-Zunstable-options --edition=2018[..]")
1517+
);
15111518
}
15121519

15131520
// Tests an issue where depending on different versions of the same crate depending on `cfg`s

tests/testsuite/package.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,14 +1122,10 @@ fn test_edition() {
11221122
// --edition is still in flux and we're not passing -Zunstable-options
11231123
// from Cargo so it will probably error. Only partially match the output
11241124
// until stuff stabilizes
1125-
.with_stderr_contains(format!("\
1126-
[COMPILING] foo v0.0.1 ({url})
1127-
[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib \
1128-
--emit=dep-info,link --edition=2018 -C debuginfo=2 \
1129-
-C metadata=[..] \
1130-
--out-dir [..] \
1131-
-L dependency={dir}[/]target[/]debug[/]deps`
1132-
", dir = p.root().display(), url = p.url())),
1125+
.with_stderr_contains("\
1126+
[COMPILING] foo v0.0.1 ([..])
1127+
[RUNNING] `rustc [..]--edition=2018 [..]
1128+
"),
11331129
);
11341130
}
11351131

@@ -1156,14 +1152,10 @@ fn test_edition_missing() {
11561152
// --edition is still in flux and we're not passing -Zunstable-options
11571153
// from Cargo so it will probably error. Only partially match the output
11581154
// until stuff stabilizes
1159-
.with_stderr_contains(format!("\
1160-
[COMPILING] foo v0.0.1 ({url})
1161-
[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib \
1162-
--emit=dep-info,link --edition=2015 -C debuginfo=2 \
1163-
-C metadata=[..] \
1164-
--out-dir [..] \
1165-
-L dependency={dir}[/]target[/]debug[/]deps`
1166-
", dir = p.root().display(), url = p.url())),
1155+
.with_stderr_contains("\
1156+
[COMPILING] foo v0.0.1 ([..])
1157+
[RUNNING] `rustc [..]--edition=2015 [..]
1158+
"),
11671159
);
11681160
}
11691161

0 commit comments

Comments
 (0)