Skip to content

Commit d346dbc

Browse files
committed
Auto merge of #38107 - keeperofdakeys:proc-macro-test, r=alexcrichton
Allow --test to be used on proc-macro crates Fixes #37480 This patch allows `--test` to work for proc-macro crates, removing the previous error.
2 parents 692d7cf + bfdd2d4 commit d346dbc

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/libsyntax_ext/proc_macro_registrar.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ pub fn modify(sess: &ParseSess,
7575
handler.err("cannot mix `proc-macro` crate type with others");
7676
}
7777

78+
if is_test_crate {
79+
return krate;
80+
}
81+
7882
krate.module.items.push(mk_registrar(&mut cx, &collect.derives));
7983

8084
if krate.exported_macros.len() > 0 {
@@ -141,8 +145,6 @@ impl<'a> Visitor for CollectCustomDerives<'a> {
141145
}
142146

143147
if self.is_test_crate {
144-
self.handler.span_err(attr.span(),
145-
"`--test` cannot be used with proc-macro crates");
146148
return;
147149
}
148150

src/test/compile-fail-fulldeps/proc-macro/error-on-test.rs src/test/run-pass-fulldeps/proc-macro/derive-test.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,23 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// no-prefer-dynamic
1112
// compile-flags: --test
1213

1314
#![crate_type = "proc-macro"]
15+
#![feature(proc_macro)]
1416
#![feature(proc_macro, proc_macro_lib)]
1517

1618
extern crate proc_macro;
1719

18-
#[proc_macro_derive(A)]
19-
//~^ ERROR: `--test` cannot be used with proc-macro crates
20-
pub fn foo1(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
20+
use proc_macro::TokenStream;
21+
22+
#[proc_macro_derive(Foo)]
23+
pub fn derive_foo(_input: TokenStream) -> TokenStream {
2124
"".parse().unwrap()
2225
}
26+
27+
#[test]
28+
pub fn test_derive() {
29+
assert!(true);
30+
}

0 commit comments

Comments
 (0)