Skip to content

Commit cbf6c57

Browse files
committed
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
1 parent 3c5af1a commit cbf6c57

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

src/cargo/core/compiler/context/unit_dependencies.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ fn maybe_lib<'a>(
307307
bcx: &BuildContext,
308308
profile_for: ProfileFor,
309309
) -> Option<(Unit<'a>, ProfileFor)> {
310-
let mode = check_or_build_mode(&unit.mode, unit.target);
311310
unit.pkg.targets().iter().find(|t| t.linkable()).map(|t| {
311+
let mode = check_or_build_mode(&unit.mode, t);
312312
let unit = new_unit(bcx, unit.pkg, t, profile_for, unit.kind.for_target(t), mode);
313313
(unit, profile_for)
314314
})

tests/testsuite/check.rs

+46
Original file line numberDiff line numberDiff line change
@@ -897,3 +897,49 @@ fn check_artifacts() {
897897
0
898898
);
899899
}
900+
901+
#[test]
902+
fn proc_macro() {
903+
let p = project("foo")
904+
.file(
905+
"Cargo.toml",
906+
r#"
907+
[package]
908+
name = "demo"
909+
version = "0.0.1"
910+
911+
[lib]
912+
proc-macro = true
913+
"#,
914+
)
915+
.file(
916+
"src/lib.rs",
917+
r#"
918+
extern crate proc_macro;
919+
920+
use proc_macro::TokenStream;
921+
922+
#[proc_macro_derive(Foo)]
923+
pub fn demo(_input: TokenStream) -> TokenStream {
924+
"".parse().unwrap()
925+
}
926+
"#,
927+
)
928+
.file(
929+
"src/main.rs",
930+
r#"
931+
#[macro_use]
932+
extern crate demo;
933+
934+
#[derive(Foo)]
935+
struct A;
936+
937+
fn main() {}
938+
"#,
939+
)
940+
.build();
941+
assert_that(
942+
p.cargo("check").arg("-v").env("RUST_LOG", "cargo=trace"),
943+
execs().with_status(0),
944+
);
945+
}

0 commit comments

Comments
 (0)