From cfeb768693a6e8a90de3f7bbdd8e2fbb9e61efba Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 11 May 2018 08:04:10 -0700 Subject: [PATCH] Fix mode generated in `maybe_lib` 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 --- .../compiler/context/unit_dependencies.rs | 2 +- tests/testsuite/check.rs | 46 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/cargo/core/compiler/context/unit_dependencies.rs b/src/cargo/core/compiler/context/unit_dependencies.rs index 49a8e860aa2..eedcd3c7764 100644 --- a/src/cargo/core/compiler/context/unit_dependencies.rs +++ b/src/cargo/core/compiler/context/unit_dependencies.rs @@ -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) }) diff --git a/tests/testsuite/check.rs b/tests/testsuite/check.rs index f4e49e711d4..efeb518a998 100644 --- a/tests/testsuite/check.rs +++ b/tests/testsuite/check.rs @@ -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), + ); +}