From 3dbae343acc7b929fa045ed9153179b358bbc116 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 15 May 2018 09:29:34 -0700 Subject: [PATCH] Fix passing --edition to rustdoc during doctests. Fixes #5538 --- src/cargo/core/compiler/compilation.rs | 17 ++++++++++++++--- src/cargo/core/compiler/mod.rs | 14 +------------- tests/testsuite/doc.rs | 7 +++++++ tests/testsuite/package.rs | 24 ++++++++---------------- 4 files changed, 30 insertions(+), 32 deletions(-) diff --git a/src/cargo/core/compiler/compilation.rs b/src/cargo/core/compiler/compilation.rs index e6900e64c..1231de815 100644 --- a/src/cargo/core/compiler/compilation.rs +++ b/src/cargo/core/compiler/compilation.rs @@ -5,7 +5,7 @@ use std::path::PathBuf; use semver::Version; use lazycell::LazyCell; -use core::{Package, PackageId, Target, TargetKind}; +use core::{Feature, Package, PackageId, Target, TargetKind}; use util::{self, join_paths, process, CargoResult, Config, ProcessBuilder}; use super::BuildContext; @@ -93,12 +93,23 @@ impl<'cfg> Compilation<'cfg> { /// See `process`. pub fn rustc_process(&self, pkg: &Package) -> CargoResult { - self.fill_env(self.rustc_process.clone(), pkg, true) + let mut p = self.fill_env(self.rustc_process.clone(), pkg, true)?; + let manifest = pkg.manifest(); + if manifest.features().is_enabled(Feature::edition()) { + p.arg(format!("--edition={}", manifest.edition())); + } + Ok(p) } /// See `process`. pub fn rustdoc_process(&self, pkg: &Package) -> CargoResult { - self.fill_env(process(&*self.config.rustdoc()?), pkg, false) + let mut p = self.fill_env(process(&*self.config.rustdoc()?), pkg, false)?; + let manifest = pkg.manifest(); + if manifest.features().is_enabled(Feature::edition()) { + p.arg("-Zunstable-options"); + p.arg(format!("--edition={}", &manifest.edition())); + } + Ok(p) } /// See `process`. diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index 6d5241e0c..2dff328de 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -10,7 +10,7 @@ use serde_json; use core::profiles::{Lto, Profile}; use core::shell::ColorChoice; -use core::{Feature, PackageId, Target}; +use core::{PackageId, Target}; use util::errors::{CargoResult, CargoResultExt, Internal}; use util::paths; use util::{self, machine_message, Freshness, ProcessBuilder}; @@ -596,13 +596,6 @@ fn rustdoc<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoResult rustdoc.arg("--cfg").arg(&format!("feature=\"{}\"", feat)); } - let manifest = unit.pkg.manifest(); - - if manifest.features().is_enabled(Feature::edition()) { - rustdoc.arg("-Zunstable-options"); - rustdoc.arg(format!("--edition={}", &manifest.edition())); - } - if let Some(ref args) = bcx.extra_args_for(unit) { rustdoc.args(args); } @@ -739,11 +732,6 @@ fn build_base_args<'a, 'cfg>( cmd.arg("-C").arg(format!("panic={}", panic)); } } - let manifest = unit.pkg.manifest(); - - if manifest.features().is_enabled(Feature::edition()) { - cmd.arg(format!("--edition={}", manifest.edition())); - } // Disable LTO for host builds as prefer_dynamic and it are mutually // exclusive. diff --git a/tests/testsuite/doc.rs b/tests/testsuite/doc.rs index 94e0839d8..cba714de6 100644 --- a/tests/testsuite/doc.rs +++ b/tests/testsuite/doc.rs @@ -1508,6 +1508,13 @@ fn doc_edition() { .with_status(0) .with_stderr_contains("[RUNNING] `rustdoc [..]-Zunstable-options --edition=2018[..]"), ); + + assert_that( + p.cargo("test -v").masquerade_as_nightly_cargo(), + execs() + .with_status(0) + .with_stderr_contains("[RUNNING] `rustdoc [..]-Zunstable-options --edition=2018[..]") + ); } // Tests an issue where depending on different versions of the same crate depending on `cfg`s diff --git a/tests/testsuite/package.rs b/tests/testsuite/package.rs index 0dc91ce20..235a91f3d 100644 --- a/tests/testsuite/package.rs +++ b/tests/testsuite/package.rs @@ -1122,14 +1122,10 @@ fn test_edition() { // --edition is still in flux and we're not passing -Zunstable-options // from Cargo so it will probably error. Only partially match the output // until stuff stabilizes - .with_stderr_contains(format!("\ -[COMPILING] foo v0.0.1 ({url}) -[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib \ - --emit=dep-info,link --edition=2018 -C debuginfo=2 \ - -C metadata=[..] \ - --out-dir [..] \ - -L dependency={dir}[/]target[/]debug[/]deps` -", dir = p.root().display(), url = p.url())), + .with_stderr_contains("\ +[COMPILING] foo v0.0.1 ([..]) +[RUNNING] `rustc [..]--edition=2018 [..] +"), ); } @@ -1156,14 +1152,10 @@ fn test_edition_missing() { // --edition is still in flux and we're not passing -Zunstable-options // from Cargo so it will probably error. Only partially match the output // until stuff stabilizes - .with_stderr_contains(format!("\ -[COMPILING] foo v0.0.1 ({url}) -[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib \ - --emit=dep-info,link --edition=2015 -C debuginfo=2 \ - -C metadata=[..] \ - --out-dir [..] \ - -L dependency={dir}[/]target[/]debug[/]deps` -", dir = p.root().display(), url = p.url())), + .with_stderr_contains("\ +[COMPILING] foo v0.0.1 ([..]) +[RUNNING] `rustc [..]--edition=2015 [..] +"), ); } -- 2.30.2