let expansion = self.expand_invoc(invoc, ext);
self.collect_invocations(expansion, &[])
} else if let InvocationKind::Attr { attr: None, traits, item } = invoc.kind {
+ let derive_allowed = match item {
+ Annotatable::Item(ref item) => match item.node {
+ ast::ItemKind::Struct(..) |
+ ast::ItemKind::Enum(..) |
+ ast::ItemKind::Union(..) => true,
+ _ => false,
+ },
+ _ => false,
+ };
+ if !derive_allowed {
+ let span = item.attrs().iter()
+ .find(|attr| attr.check_name("derive"))
+ .expect("`derive` attribute should exist").span;
+ self.cx.span_err(span,
+ "`derive` may only be applied to structs, enums \
+ and unions");
+ }
+
let item = item
.map_attrs(|mut attrs| { attrs.retain(|a| a.path != "derive"); attrs });
let item_with_markers =