about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>2017-04-03 22:23:32 +0000
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>2017-04-03 23:02:49 +0000
commit6a9448b523b95dbc850e856508342644fc17db45 (patch)
treed41dcac1c447725f16c00d46103b81657f68aab6 /src/libsyntax
parent5309a3e31d88def1f3ea966162ed4f81f161d500 (diff)
downloadrust-6a9448b523b95dbc850e856508342644fc17db45.tar.gz
rust-6a9448b523b95dbc850e856508342644fc17db45.zip
Fix bug parsing `#[derive]` macro invocations.
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ext/derive.rs3
-rw-r--r--src/libsyntax/parse/parser.rs20
2 files changed, 22 insertions, 1 deletions
diff --git a/src/libsyntax/ext/derive.rs b/src/libsyntax/ext/derive.rs
index c79040424f6..e7c5d8278d9 100644
--- a/src/libsyntax/ext/derive.rs
+++ b/src/libsyntax/ext/derive.rs
@@ -26,7 +26,8 @@ pub fn collect_derives(cx: &mut ExtCtxt, attrs: &mut Vec<ast::Attribute>) -> Vec
             return true;
         }
 
-        match attr.parse_list(cx.parse_sess, |parser| parser.parse_path(PathStyle::Mod)) {
+        match attr.parse_list(cx.parse_sess,
+                              |parser| parser.parse_path_allowing_meta(PathStyle::Mod)) {
             Ok(ref traits) if traits.is_empty() => {
                 cx.span_warn(attr.span, "empty trait list in `derive`");
                 false
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index c2c3e5a6855..a89811d8abb 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -1754,6 +1754,26 @@ impl<'a> Parser<'a> {
         })
     }
 
+    /// Like `parse_path`, but also supports parsing `Word` meta items into paths for back-compat.
+    /// This is used when parsing derive macro paths in `#[derive]` attributes.
+    pub fn parse_path_allowing_meta(&mut self, mode: PathStyle) -> PResult<'a, ast::Path> {
+        let meta_ident = match self.token {
+            token::Interpolated(ref nt) => match **nt {
+                token::NtMeta(ref meta) => match meta.node {
+                    ast::MetaItemKind::Word => Some(ast::Ident::with_empty_ctxt(meta.name)),
+                    _ => None,
+                },
+                _ => None,
+            },
+            _ => None,
+        };
+        if let Some(ident) = meta_ident {
+            self.bump();
+            return Ok(ast::Path::from_ident(self.prev_span, ident));
+        }
+        self.parse_path(mode)
+    }
+
     /// Examples:
     /// - `a::b<T,U>::c<V,W>`
     /// - `a::b<T,U>::c(V) -> W`