Parse other types of array length expressions
diff --git a/src/constant.rs b/src/constant.rs
index 1688dbf..b2420c0 100644
--- a/src/constant.rs
+++ b/src/constant.rs
@@ -22,8 +22,20 @@
Index(Box<ConstExpr>, Box<ConstExpr>),
/// No-op: used solely so we can pretty-print faithfully
Paren(Box<ConstExpr>),
+ /// If compiling with full support for expression syntax, any expression is
+ /// allowed
+ Other(Other),
}
+#[cfg(not(feature = "full"))]
+#[derive(Debug, Clone, Eq, PartialEq)]
+pub struct Other {
+ _private: (),
+}
+
+#[cfg(feature = "full")]
+pub type Other = Expr;
+
#[cfg(feature = "parsing")]
pub mod parsing {
use super::*;
@@ -139,7 +151,17 @@
expr.to_tokens(tokens);
tokens.append(")");
}
+ ConstExpr::Other(ref other) => {
+ other.to_tokens(tokens);
+ }
}
}
}
+
+ #[cfg(not(feature = "full"))]
+ impl ToTokens for Other {
+ fn to_tokens(&self, _tokens: &mut Tokens) {
+ unreachable!()
+ }
+ }
}
diff --git a/src/ty.rs b/src/ty.rs
index b33206a..f9e3a2d 100644
--- a/src/ty.rs
+++ b/src/ty.rs
@@ -211,7 +211,11 @@
pub mod parsing {
use super::*;
use {TraitBoundModifier, TyParamBound};
+ #[cfg(feature = "full")]
+ use ConstExpr;
use constant::parsing::const_expr;
+ #[cfg(feature = "full")]
+ use expr::parsing::expr;
use generics::parsing::{lifetime, lifetime_def, ty_param_bound, bound_lifetimes};
use ident::parsing::ident;
use lit::parsing::quoted_string;
@@ -248,6 +252,7 @@
(Ty::Slice(Box::new(elem)))
));
+ #[cfg(not(feature = "full"))]
named!(ty_array -> Ty, do_parse!(
punct!("[") >>
elem: ty >>
@@ -257,6 +262,19 @@
(Ty::Array(Box::new(elem), len))
));
+ #[cfg(feature = "full")]
+ named!(ty_array -> Ty, do_parse!(
+ punct!("[") >>
+ elem: ty >>
+ punct!(";") >>
+ len: alt!(
+ terminated!(const_expr, punct!("]"))
+ |
+ terminated!(expr, punct!("]")) => { ConstExpr::Other }
+ ) >>
+ (Ty::Array(Box::new(elem), len))
+ ));
+
named!(ty_ptr -> Ty, do_parse!(
punct!("*") >>
mutability: alt!(