Skip to content

Commit

Permalink
Add error when proc_macro_derive is used not on functions
Browse files Browse the repository at this point in the history
Fixes #37590
  • Loading branch information
est31 committed Nov 4, 2016
1 parent ccfc38f commit ecd79a1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/libsyntax_ext/proc_macro_registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ impl<'a> Visitor for CollectCustomDerives<'a> {
match item.node {
ast::ItemKind::Fn(..) => {}
_ => {
// Check for invalid use of proc_macro_derive
let attr = item.attrs.iter()
.filter(|a| a.check_name("proc_macro_derive"))
.next();
if let Some(attr) = attr {
self.handler.span_err(attr.span(),
"the `#[proc_macro_derive]` \
attribute may only be used \
on bare functions");
return;
}
self.check_not_pub_in_root(&item.vis, item.span);
return visit::walk_item(self, item)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ pub fn foo(a: proc_macro::TokenStream) -> proc_macro::TokenStream {
a
}

// Issue #37590
#[proc_macro_derive(Foo)]
//~^ ERROR: the `#[proc_macro_derive]` attribute may only be used on bare functions
pub struct Foo {
}

fn main() {}

0 comments on commit ecd79a1

Please sign in to comment.