Skip to content

Commit b9ed51c

Browse files
Show a better error when using --test with #[proc_macro_derive]
1 parent 43006fc commit b9ed51c

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/librustc_driver/driver.rs

+2
Original file line numberDiff line numberDiff line change
@@ -709,10 +709,12 @@ pub fn phase_2_configure_and_expand<'a, F>(sess: &Session,
709709
let crate_types = sess.crate_types.borrow();
710710
let num_crate_types = crate_types.len();
711711
let is_proc_macro_crate = crate_types.contains(&config::CrateTypeProcMacro);
712+
let is_test_crate = sess.opts.test;
712713
syntax_ext::proc_macro_registrar::modify(&sess.parse_sess,
713714
&mut resolver,
714715
krate,
715716
is_proc_macro_crate,
717+
is_test_crate,
716718
num_crate_types,
717719
sess.diagnostic(),
718720
&sess.features.borrow())

src/libsyntax_ext/proc_macro_registrar.rs

+9
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ struct CollectCustomDerives<'a> {
3838
in_root: bool,
3939
handler: &'a errors::Handler,
4040
is_proc_macro_crate: bool,
41+
is_test_crate: bool,
4142
}
4243

4344
pub fn modify(sess: &ParseSess,
4445
resolver: &mut ::syntax::ext::base::Resolver,
4546
mut krate: ast::Crate,
4647
is_proc_macro_crate: bool,
48+
is_test_crate: bool,
4749
num_crate_types: usize,
4850
handler: &errors::Handler,
4951
features: &Features) -> ast::Crate {
@@ -55,6 +57,7 @@ pub fn modify(sess: &ParseSess,
5557
in_root: true,
5658
handler: handler,
5759
is_proc_macro_crate: is_proc_macro_crate,
60+
is_test_crate: is_test_crate,
5861
};
5962
visit::walk_crate(&mut collect, &krate);
6063

@@ -137,6 +140,12 @@ impl<'a> Visitor for CollectCustomDerives<'a> {
137140
attributes found");
138141
}
139142

143+
if self.is_test_crate {
144+
self.handler.span_err(attr.span(),
145+
"`--test` cannot be used with proc-macro crates");
146+
return;
147+
}
148+
140149
if !self.is_proc_macro_crate {
141150
self.handler.span_err(attr.span(),
142151
"the `#[proc_macro_derive]` attribute is \

0 commit comments

Comments
 (0)