Skip to content

Commit 25ac81e

Browse files
committed
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.
1 parent f912005 commit 25ac81e

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

src/libsyntax/ext/deriving/generic.rs

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ use std::cell::RefCell;
182182
use ast;
183183
use ast::{P, EnumDef, Expr, Ident, Generics, StructDef};
184184
use ast_util;
185+
use attr::AttrMetaMethods;
185186
use ext::base::ExtCtxt;
186187
use ext::build::AstBuilder;
187188
use codemap;
@@ -330,21 +331,34 @@ impl<'a> TraitDef<'a> {
330331
_mitem: @ast::MetaItem,
331332
item: @ast::Item,
332333
push: |@ast::Item|) {
333-
match item.node {
334+
let newitem = match item.node {
334335
ast::ItemStruct(struct_def, ref generics) => {
335-
push(self.expand_struct_def(cx,
336-
struct_def,
337-
item.ident,
338-
generics));
336+
self.expand_struct_def(cx,
337+
struct_def,
338+
item.ident,
339+
generics)
339340
}
340341
ast::ItemEnum(ref enum_def, ref generics) => {
341-
push(self.expand_enum_def(cx,
342-
enum_def,
343-
item.ident,
344-
generics));
342+
self.expand_enum_def(cx,
343+
enum_def,
344+
item.ident,
345+
generics)
345346
}
346-
_ => ()
347-
}
347+
_ => return
348+
};
349+
// Keep the lint attributes of the previous item to control how the
350+
// generated implementations are linted
351+
let mut attrs = newitem.attrs.clone();
352+
attrs.extend(item.attrs.iter().filter(|a| {
353+
match a.name().get() {
354+
"allow" | "warn" | "deny" | "forbid" => true,
355+
_ => false,
356+
}
357+
}).map(|a| a.clone()));
358+
push(@ast::Item {
359+
attrs: attrs,
360+
..(*newitem).clone()
361+
})
348362
}
349363

350364
/**

0 commit comments

Comments
 (0)