Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {}