diff --git a/lalrpop/src/grammar/parse_tree.rs b/lalrpop/src/grammar/parse_tree.rs index d526a5d..f63dc1b 100644 --- a/lalrpop/src/grammar/parse_tree.rs +++ b/lalrpop/src/grammar/parse_tree.rs @@ -231,7 +231,7 @@ pub enum WhereClause { }, // where for<'a> &'a T: Debug + Into Type { - forall: Option>, + forall: Vec, ty: T, bounds: Vec>, }, @@ -269,7 +269,7 @@ pub enum TypeBound { Lifetime(Atom), // `for<'a> FnMut(&'a usize)` Fn { - forall: Option>, + forall: Vec, path: Path, parameters: Vec, ret: Option, @@ -277,7 +277,7 @@ pub enum TypeBound { // `some::Trait` or `some::Trait` or `some::Trait` // or `for<'a> Trait<'a, T>` Trait { - forall: Option>, + forall: Vec, path: Path, parameters: Vec>, }, @@ -712,7 +712,7 @@ impl Display for WhereClause { ref ty, ref bounds, } => { - if let Some(ref forall) = *forall { + if !forall.is_empty() { write!(fmt, "for<")?; for (i, l) in forall.iter().enumerate() { if i != 0 { @@ -746,7 +746,7 @@ impl Display for TypeBound { ref parameters, ref ret, } => { - if let Some(ref forall) = *forall { + if !forall.is_empty() { write!(fmt, "for<")?; for (i, l) in forall.iter().enumerate() { if i != 0 { @@ -777,7 +777,7 @@ impl Display for TypeBound { ref path, ref parameters, } => { - if let Some(ref forall) = *forall { + if !forall.is_empty() { write!(fmt, "for<")?; for (i, l) in forall.iter().enumerate() { if i != 0 { diff --git a/lalrpop/src/parser/lrgrammar.lalrpop b/lalrpop/src/parser/lrgrammar.lalrpop index 29bbe5c..fefc951 100644 --- a/lalrpop/src/parser/lrgrammar.lalrpop +++ b/lalrpop/src/parser/lrgrammar.lalrpop @@ -52,12 +52,14 @@ GrammarWhereClauses: Vec> = GrammarWhereClause: WhereClause = { ":" > => WhereClause::Lifetime { lifetime: l, bounds: bounds }, - ":" => + ":" => WhereClause::Type { forall: f, ty: ty, bounds: bounds } }; -ForAll: Vec = - "for" "<" > ">"; +ForAll: Vec = { + "for" "<" > ">", + () => vec![], +}; TypeBounds: Vec> = >; @@ -65,9 +67,9 @@ TypeBounds: Vec> = TypeBound: TypeBound = { => TypeBound::Lifetime(l), - "(" > ")" " )?> => + "(" > ")" " )?> => TypeBound::Fn { forall: f, path: p, parameters: params, ret: ret }, - > ">")?> => + > ">")?> => TypeBound::Trait { forall: f, path: p, parameters: params.unwrap_or(vec![]) } };