Skip to content

Commit 0e042e8

Browse files
committed
Auto merge of #5520 - alexcrichton:check-with-full-proc-macro, r=matklad
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
2 parents 2f7cf4a + 5e76cbc commit 0e042e8

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
@@ -301,8 +301,8 @@ fn maybe_lib<'a>(
301301
bcx: &BuildContext,
302302
profile_for: ProfileFor,
303303
) -> Option<(Unit<'a>, ProfileFor)> {
304-
let mode = check_or_build_mode(&unit.mode, unit.target);
305304
unit.pkg.targets().iter().find(|t| t.linkable()).map(|t| {
305+
let mode = check_or_build_mode(&unit.mode, t);
306306
let unit = new_unit(bcx, unit.pkg, t, profile_for, unit.kind.for_target(t), mode);
307307
(unit, profile_for)
308308
})

tests/testsuite/check.rs

+46
Original file line numberDiff line numberDiff line change
@@ -912,3 +912,49 @@ fn check_artifacts() {
912912
0
913913
);
914914
}
915+
916+
#[test]
917+
fn proc_macro() {
918+
let p = project("foo")
919+
.file(
920+
"Cargo.toml",
921+
r#"
922+
[package]
923+
name = "demo"
924+
version = "0.0.1"
925+
926+
[lib]
927+
proc-macro = true
928+
"#,
929+
)
930+
.file(
931+
"src/lib.rs",
932+
r#"
933+
extern crate proc_macro;
934+
935+
use proc_macro::TokenStream;
936+
937+
#[proc_macro_derive(Foo)]
938+
pub fn demo(_input: TokenStream) -> TokenStream {
939+
"".parse().unwrap()
940+
}
941+
"#,
942+
)
943+
.file(
944+
"src/main.rs",
945+
r#"
946+
#[macro_use]
947+
extern crate demo;
948+
949+
#[derive(Foo)]
950+
struct A;
951+
952+
fn main() {}
953+
"#,
954+
)
955+
.build();
956+
assert_that(
957+
p.cargo("check").arg("-v").env("RUST_LOG", "cargo=trace"),
958+
execs().with_status(0),
959+
);
960+
}

0 commit comments

Comments
 (0)