Skip to content

Commit 4917f52

Browse files
authored
Rollup merge of rust-lang#37596 - est31:master, r=alexcrichton
Add error when proc_macro_derive is used not on functions Fixes rust-lang#37590
2 parents 72fa72d + ecd79a1 commit 4917f52

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/libsyntax_ext/proc_macro_registrar.rs

+11
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,17 @@ impl<'a> Visitor for CollectCustomDerives<'a> {
105105
match item.node {
106106
ast::ItemKind::Fn(..) => {}
107107
_ => {
108+
// Check for invalid use of proc_macro_derive
109+
let attr = item.attrs.iter()
110+
.filter(|a| a.check_name("proc_macro_derive"))
111+
.next();
112+
if let Some(attr) = attr {
113+
self.handler.span_err(attr.span(),
114+
"the `#[proc_macro_derive]` \
115+
attribute may only be used \
116+
on bare functions");
117+
return;
118+
}
108119
self.check_not_pub_in_root(&item.vis, item.span);
109120
return visit::walk_item(self, item)
110121
}

src/test/compile-fail-fulldeps/proc-macro/require-rustc-macro-crate-type.rs src/test/compile-fail-fulldeps/proc-macro/illegal-proc-macro-derive-use.rs

+6
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,10 @@ pub fn foo(a: proc_macro::TokenStream) -> proc_macro::TokenStream {
1818
a
1919
}
2020

21+
// Issue #37590
22+
#[proc_macro_derive(Foo)]
23+
//~^ ERROR: the `#[proc_macro_derive]` attribute may only be used on bare functions
24+
pub struct Foo {
25+
}
26+
2127
fn main() {}

0 commit comments

Comments
 (0)