Parse ConstExpr::Other
diff --git a/Cargo.toml b/Cargo.toml
index 12be265..82be3c6 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "syn"
-version = "0.11.7" # don't forget to update version in readme for breaking changes
+version = "0.11.8" # don't forget to update version in readme for breaking changes
authors = ["David Tolnay <dtolnay@gmail.com>"]
license = "MIT/Apache-2.0"
description = "Nom parser for Rust source code"
diff --git a/src/constant.rs b/src/constant.rs
index c7d0e32..d0f11b5 100644
--- a/src/constant.rs
+++ b/src/constant.rs
@@ -43,6 +43,8 @@
use lit::parsing::lit;
use op::parsing::{binop, unop};
use ty::parsing::{path, ty};
+ #[cfg(feature = "full")] use expr::parsing::expr;
+ #[cfg(not(feature = "full"))] use synom::IResult;
named!(pub const_expr -> ConstExpr, do_parse!(
mut e: alt!(
@@ -53,6 +55,8 @@
expr_path
|
expr_paren
+ |
+ expr_other
) >>
many0!(alt!(
tap!(args: and_call => {
@@ -94,6 +98,14 @@
named!(expr_path -> ConstExpr, map!(path, ConstExpr::Path));
+ #[cfg(feature = "full")]
+ named!(expr_other -> ConstExpr, map!(expr, ConstExpr::Other));
+
+ #[cfg(not(feature = "full"))]
+ fn expr_other(_: &str) -> IResult<&str, ConstExpr> {
+ IResult::Error
+ }
+
named!(and_index -> ConstExpr, delimited!(punct!("["), const_expr, punct!("]")));
named!(expr_paren -> ConstExpr, do_parse!(
diff --git a/tests/test_macro_input.rs b/tests/test_macro_input.rs
index 2f4f2a3..6f6cb65 100644
--- a/tests/test_macro_input.rs
+++ b/tests/test_macro_input.rs
@@ -75,15 +75,19 @@
#[test]
fn test_enum() {
- let raw = "
+ let raw = r#"
/// See the std::result module documentation for details.
#[must_use]
pub enum Result<T, E> {
Ok(T),
Err(E),
Surprise = 0isize,
+
+ // Smuggling data into a proc_macro_derive,
+ // in the style of https://github.com/dtolnay/proc-macro-hack
+ ProcMacroHack = (0, "data").0,
}
- ";
+ "#;
let expected = MacroInput {
ident: "Result".into(),
@@ -157,6 +161,30 @@
data: VariantData::Unit,
discriminant: Some(ConstExpr::Lit(Lit::Int(0, IntTy::Isize))),
},
+ Variant {
+ ident: "ProcMacroHack".into(),
+ attrs: Vec::new(),
+ data: VariantData::Unit,
+ discriminant: Some(ConstExpr::Other(Expr {
+ node: ExprKind::TupField(
+ Box::new(Expr {
+ node: ExprKind::Tup(vec![
+ Expr {
+ node: ExprKind::Lit(Lit::Int(0, IntTy::Unsuffixed)),
+ attrs: Vec::new(),
+ },
+ Expr {
+ node: ExprKind::Lit(Lit::Str("data".into(), StrStyle::Cooked)),
+ attrs: Vec::new(),
+ },
+ ]),
+ attrs: Vec::new(),
+ }),
+ 0
+ ),
+ attrs: Vec::new(),
+ })),
+ },
]),
};