about summary refs log tree commit diff
path: root/src/libsyntax/ext/deriving
diff options
context:
space:
mode:
authorAdolfo OchagavĂ­a <aochagavia92@gmail.com>2015-01-20 20:28:36 +0100
committerAdolfo OchagavĂ­a <aochagavia92@gmail.com>2015-01-31 11:38:49 +0100
commitaa3fe205223936e37c0accd91473fa3d666451ce (patch)
tree481c91362307cde7e4c3d39e1c8b0514e12dad84 /src/libsyntax/ext/deriving
parent01172eedfab32b24e38aa86ba0cba24453e842fb (diff)
Replace uses of Decorator and Modifier
Diffstat (limited to 'src/libsyntax/ext/deriving')
-rw-r--r--src/libsyntax/ext/deriving/mod.rs25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/libsyntax/ext/deriving/mod.rs b/src/libsyntax/ext/deriving/mod.rs
index d3d7fee3a18..a06ed638fe1 100644
--- a/src/libsyntax/ext/deriving/mod.rs
+++ b/src/libsyntax/ext/deriving/mod.rs
@@ -13,10 +13,9 @@
 //! FIXME (#2810): hygiene. Search for "__" strings (in other files too). We also assume "extra" is
 //! the standard library, and "std" is the core library.
 
-use ast::{Item, MetaItem, MetaList, MetaNameValue, MetaWord};
-use ext::base::ExtCtxt;
+use ast::{MetaItem, MetaList, MetaNameValue, MetaWord};
+use ext::base::{Annotatable, ExtCtxt};
 use codemap::Span;
-use ptr::P;
 
 pub mod bounds;
 pub mod clone;
@@ -49,10 +48,20 @@ pub fn expand_deprecated_deriving(cx: &mut ExtCtxt,
 }
 
 pub fn expand_meta_derive(cx: &mut ExtCtxt,
-                          _span: Span,
+                          span: Span,
                           mitem: &MetaItem,
-                          item: &Item,
-                          mut push: Box<FnMut(P<Item>)>) {
+                          annotatable: &Annotatable,
+                          mut push: Box<FnMut(Annotatable)>)
+{
+    // Derive can only be applied to items
+    let item = match annotatable {
+        &Annotatable::Item(ref it) => it.clone(),
+        _ => {
+            cx.span_err(span, "`derive` can only be applied to items");
+            return;
+        }
+    };
+
     match mitem.node {
         MetaNameValue(_, ref l) => {
             cx.span_err(l.span, "unexpected value in `derive`");
@@ -70,8 +79,8 @@ pub fn expand_meta_derive(cx: &mut ExtCtxt,
                     MetaList(ref tname, _) |
                     MetaWord(ref tname) => {
                         macro_rules! expand {
-                            ($func:path) => ($func(cx, titem.span, &**titem, item,
-                                                   |i| push(i)))
+                            ($func:path) => ($func(cx, titem.span, &**titem,
+                                                   &*item, |i| push(Annotatable::Item(i))))
                         }
 
                         match tname.get() {