ConstExpr type for discriminant and array len
diff --git a/src/ty.rs b/src/ty.rs
index b8aee5a..fb34280 100644
--- a/src/ty.rs
+++ b/src/ty.rs
@@ -6,7 +6,7 @@
/// A variable-length array (`[T]`)
Slice(Box<Ty>),
/// A fixed length array (`[T; n]`)
- Array(Box<Ty>, ArrayLen),
+ Array(Box<Ty>, ConstExpr),
/// A raw pointer (`*const T` or `*mut T`)
Ptr(Box<MutTy>),
/// A reference (`&'a T` or `&'a mut T`)
@@ -36,15 +36,6 @@
}
#[derive(Debug, Clone, Eq, PartialEq)]
-pub enum ArrayLen {
- /// As in `[T; 0]`.
- Usize(usize),
- /// As in `[T; LEN]` or `[T; helper::LEN as usize]`. The boolean indicates
- /// whether the path is followed by `as usize`.
- Path(Path, bool),
-}
-
-#[derive(Debug, Clone, Eq, PartialEq)]
pub struct MutTy {
pub ty: Ty,
pub mutability: Mutability,
@@ -204,9 +195,9 @@
#[cfg(feature = "parsing")]
pub mod parsing {
use super::*;
+ use constant::parsing::const_expr;
use generics::parsing::{lifetime, lifetime_def, ty_param_bound, bound_lifetimes};
use ident::parsing::ident;
- use lit::parsing::int;
use std::str;
named!(pub ty -> Ty, alt!(
@@ -242,21 +233,11 @@
punct!("[") >>
elem: ty >>
punct!(";") >>
- len: array_len >>
+ len: const_expr >>
punct!("]") >>
(Ty::Array(Box::new(elem), len))
));
- named!(array_len -> ArrayLen, alt!(
- map!(int, |(i, _)| ArrayLen::Usize(i as usize))
- |
- do_parse!(
- path: path >>
- as_usize: option!(tuple!(keyword!("as"), keyword!("usize"))) >>
- (ArrayLen::Path(path, as_usize.is_some()))
- )
- ));
-
named!(ty_ptr -> Ty, do_parse!(
punct!("*") >>
mutability: alt!(
@@ -527,21 +508,6 @@
}
}
- impl ToTokens for ArrayLen {
- fn to_tokens(&self, tokens: &mut Tokens) {
- match *self {
- ArrayLen::Usize(len) => tokens.append(&len.to_string()),
- ArrayLen::Path(ref path, as_usize) => {
- path.to_tokens(tokens);
- if as_usize {
- tokens.append("as");
- tokens.append("usize");
- }
- }
- }
- }
- }
-
impl ToTokens for Mutability {
fn to_tokens(&self, tokens: &mut Tokens) {
if let Mutability::Mutable = *self {