diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-05-11 01:11:33 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-05-13 17:24:08 -0700 |
| commit | 25ac81eb8998e08add3eba703c701a0b9a65173f (patch) | |
| tree | 94f9c8b673f614d4c7764eb2ea8da577cbd02850 | |
| parent | f912005ef34c8adfc2b0827f2d1e353e1508d3d0 (diff) | |
| download | rust-25ac81eb8998e08add3eba703c701a0b9a65173f.tar.gz rust-25ac81eb8998e08add3eba703c701a0b9a65173f.zip | |
syntax: Preserve attributes in #[deriving]
Now that the #[deriving] attribute is removed, the raw_pointers_deriving lint was broken. This commit restores the lint by preserving lint attributes across #[deriving] to the implementations and using #[automatically_derived] as the trigger for activating the lint.
| -rw-r--r-- | src/libsyntax/ext/deriving/generic.rs | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/src/libsyntax/ext/deriving/generic.rs b/src/libsyntax/ext/deriving/generic.rs index 9c967cfb4ee..6df4da89402 100644 --- a/src/libsyntax/ext/deriving/generic.rs +++ b/src/libsyntax/ext/deriving/generic.rs @@ -182,6 +182,7 @@ use std::cell::RefCell; use ast; use ast::{P, EnumDef, Expr, Ident, Generics, StructDef}; use ast_util; +use attr::AttrMetaMethods; use ext::base::ExtCtxt; use ext::build::AstBuilder; use codemap; @@ -330,21 +331,34 @@ impl<'a> TraitDef<'a> { _mitem: @ast::MetaItem, item: @ast::Item, push: |@ast::Item|) { - match item.node { + let newitem = match item.node { ast::ItemStruct(struct_def, ref generics) => { - push(self.expand_struct_def(cx, - struct_def, - item.ident, - generics)); + self.expand_struct_def(cx, + struct_def, + item.ident, + generics) } ast::ItemEnum(ref enum_def, ref generics) => { - push(self.expand_enum_def(cx, - enum_def, - item.ident, - generics)); + self.expand_enum_def(cx, + enum_def, + item.ident, + generics) } - _ => () - } + _ => return + }; + // Keep the lint attributes of the previous item to control how the + // generated implementations are linted + let mut attrs = newitem.attrs.clone(); + attrs.extend(item.attrs.iter().filter(|a| { + match a.name().get() { + "allow" | "warn" | "deny" | "forbid" => true, + _ => false, + } + }).map(|a| a.clone())); + push(@ast::Item { + attrs: attrs, + ..(*newitem).clone() + }) } /** |
