about summary refs log tree commit diff
path: root/src/libsyntax/ext/base.rs
diff options
context:
space:
mode:
authorSeiichi Uchida <seuchida@gmail.com>2017-12-26 16:47:32 +0900
committerSeiichi Uchida <seuchida@gmail.com>2017-12-26 16:47:32 +0900
commit18da3c671b8147fb8d4e206d487f0ee4e4c3ba11 (patch)
tree44008e34c1ca92a795595088ecf7e3dd171bb335 /src/libsyntax/ext/base.rs
parent0cd67581e7d048810874903dc589e5b855f47e7d (diff)
downloadrust-18da3c671b8147fb8d4e206d487f0ee4e4c3ba11.tar.gz
rust-18da3c671b8147fb8d4e206d487f0ee4e4c3ba11.zip
Do not expand a derive invocation when derive is not allowed
1. Change the return type of `expand_invoc()` and its subroutines to
   `Option<Expansion>` from `Expansion`.
2. Return `None` when expanding a derive invocation if the item cannot
   have derive on it (in `expand_derive_invoc()`).
Diffstat (limited to 'src/libsyntax/ext/base.rs')
-rw-r--r--src/libsyntax/ext/base.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs
index d53335f5be7..be71d6e038c 100644
--- a/src/libsyntax/ext/base.rs
+++ b/src/libsyntax/ext/base.rs
@@ -96,6 +96,18 @@ impl Annotatable {
             _ => panic!("expected Item")
         }
     }
+
+    pub fn derive_allowed(&self) -> bool {
+        match *self {
+            Annotatable::Item(ref item) => match item.node {
+                ast::ItemKind::Struct(..) |
+                ast::ItemKind::Enum(..) |
+                ast::ItemKind::Union(..) => true,
+                _ => false,
+            },
+            _ => false,
+        }
+    }
 }
 
 // A more flexible ItemDecorator.