Fix mode generated in `maybe_lib`
authorAlex Crichton <alex@alexcrichton.com>
Fri, 11 May 2018 15:04:10 +0000 (08:04 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Sat, 12 May 2018 19:19:01 +0000 (12:19 -0700)
The new `mode` for the library dependency is dependent on the library target
rather than the target which is the reason for the dependency on the library!

Closes rust-lang/rust#50640

src/cargo/core/compiler/context/unit_dependencies.rs
tests/testsuite/check.rs

index 61b03ff8e670e19a735b868574565eca3fb19690..882c6ddad336c1d578dfb3ff3c7570c0584cd729 100644 (file)
@@ -307,8 +307,8 @@ fn maybe_lib<'a>(
     bcx: &BuildContext,
     profile_for: ProfileFor,
 ) -> Option<(Unit<'a>, ProfileFor)> {
-    let mode = check_or_build_mode(&unit.mode, unit.target);
     unit.pkg.targets().iter().find(|t| t.linkable()).map(|t| {
+        let mode = check_or_build_mode(&unit.mode, t);
         let unit = new_unit(bcx, unit.pkg, t, profile_for, unit.kind.for_target(t), mode);
         (unit, profile_for)
     })
index f4e49e711d4c81777e47e4e5c8ed5390212ebd95..efeb518a9984b6c5fe4894bcc5ddd7d0ed66a47b 100644 (file)
@@ -897,3 +897,49 @@ fn check_artifacts() {
         0
     );
 }
+
+#[test]
+fn proc_macro() {
+    let p = project("foo")
+        .file(
+            "Cargo.toml",
+            r#"
+                [package]
+                name = "demo"
+                version = "0.0.1"
+
+                [lib]
+                proc-macro = true
+            "#,
+        )
+        .file(
+            "src/lib.rs",
+            r#"
+                extern crate proc_macro;
+
+                use proc_macro::TokenStream;
+
+                #[proc_macro_derive(Foo)]
+                pub fn demo(_input: TokenStream) -> TokenStream {
+                    "".parse().unwrap()
+                }
+            "#,
+        )
+        .file(
+            "src/main.rs",
+            r#"
+                #[macro_use]
+                extern crate demo;
+
+                #[derive(Foo)]
+                struct A;
+
+                fn main() {}
+            "#,
+        )
+        .build();
+    assert_that(
+        p.cargo("check").arg("-v").env("RUST_LOG", "cargo=trace"),
+        execs().with_status(0),
+    );
+}