Pass edition to rustdoc.
authorEric Huss <eric@huss.org>
Thu, 5 Apr 2018 12:39:50 +0000 (05:39 -0700)
committerEric Huss <eric@huss.org>
Thu, 5 Apr 2018 12:39:50 +0000 (05:39 -0700)
Fixes #5279.

src/cargo/ops/cargo_rustc/mod.rs
tests/testsuite/doc.rs

index 5f75694824325a40b300a82497b8c0819fd7c3eb..f467cc6eeac8616d13788992f882c6b813384b80 100644 (file)
@@ -776,6 +776,13 @@ 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) = unit.profile.rustdoc_args {
         rustdoc.args(args);
     }
index 7b6ea41e356e01d67f3f4b0c3caf41bea6d83f7a..e3ca13e921cdb21bdee3eaeaedd20c52c923c495 100644 (file)
@@ -3,7 +3,7 @@ use std::str;
 use std::fs::{self, File};
 use std::io::Read;
 
-use cargotest::rustc_host;
+use cargotest::{rustc_host, ChannelChanger};
 use cargotest::support::{execs, project, path2url};
 use cargotest::support::registry::Package;
 use hamcrest::{assert_that, existing_dir, existing_file, is_not};
@@ -1464,3 +1464,33 @@ fn doc_workspace_open_help_message() {
             .with_stderr_contains("  bar"),
     );
 }
+
+#[test]
+fn doc_edition() {
+    if !cargotest::is_nightly() {
+        // Stable rustdoc won't have the edition option.  Remove this once it
+        // is stabilized.
+        return;
+    }
+    let p = project("foo")
+        .file(
+            "Cargo.toml",
+            r#"
+            cargo-features = ["edition"]
+            [package]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+            rust = "2018"
+        "#,
+        )
+        .file("src/lib.rs", "")
+        .build();
+
+    assert_that(
+        p.cargo("doc").arg("-v").masquerade_as_nightly_cargo(),
+        execs()
+            .with_status(0)
+            .with_stderr_contains("[RUNNING] `rustdoc [..]-Zunstable-options --edition=2018[..]"),
+    );
+}