Fix passing --edition to rustdoc during doctests.
authorEric Huss <eric@huss.org>
Tue, 15 May 2018 16:29:34 +0000 (09:29 -0700)
committerEric Huss <eric@huss.org>
Tue, 15 May 2018 16:29:34 +0000 (09:29 -0700)
Fixes #5538

src/cargo/core/compiler/compilation.rs
src/cargo/core/compiler/mod.rs
tests/testsuite/doc.rs
tests/testsuite/package.rs

index e6900e64cf53f527219f23e5fb1266c0b12d0392..1231de815efb7c13f95f6dedfff1909e1fb70d5c 100644 (file)
@@ -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<ProcessBuilder> {
-        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<ProcessBuilder> {
-        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`.
index 6d5241e0c9c29d5816a17211896b9c399db1d806..2dff328de0b86f4f650a74db8cc99265a7524f1f 100644 (file)
@@ -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.
index 94e0839d8befa087d303f4e1c4db096f9dc9ac34..cba714de6e71281f1a7bf6eeaf7daa3022d00078 100644 (file)
@@ -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
index 0dc91ce207acbc50b90892ff150de003316fe941..235a91f3d3dff93e1dc823f618f1b3645d61c317 100644 (file)
@@ -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 [..]
+"),
     );
 }