refactor how forall is represented in the AST

This commit is contained in:
Niko Matsakis 2018-07-13 19:54:11 +03:00 committed by Markus Westerlind
parent 60751e68c3
commit a9d8937fa9
2 changed files with 13 additions and 11 deletions

View File

@ -231,7 +231,7 @@ pub enum WhereClause<T> {
},
// where for<'a> &'a T: Debug + Into<usize>
Type {
forall: Option<Vec<Atom>>,
forall: Vec<TypeParameter>,
ty: T,
bounds: Vec<TypeBound<T>>,
},
@ -269,7 +269,7 @@ pub enum TypeBound<T> {
Lifetime(Atom),
// `for<'a> FnMut(&'a usize)`
Fn {
forall: Option<Vec<Atom>>,
forall: Vec<TypeParameter>,
path: Path,
parameters: Vec<T>,
ret: Option<T>,
@ -277,7 +277,7 @@ pub enum TypeBound<T> {
// `some::Trait` or `some::Trait<Param, ...>` or `some::Trait<Item = Assoc>`
// or `for<'a> Trait<'a, T>`
Trait {
forall: Option<Vec<Atom>>,
forall: Vec<TypeParameter>,
path: Path,
parameters: Vec<TypeBoundParameter<T>>,
},
@ -712,7 +712,7 @@ impl<T: Display> Display for WhereClause<T> {
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<T: Display> Display for TypeBound<T> {
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<T: Display> Display for TypeBound<T> {
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 {

View File

@ -52,12 +52,14 @@ GrammarWhereClauses: Vec<WhereClause<TypeRef>> =
GrammarWhereClause: WhereClause<TypeRef> = {
<l:Lifetime> ":" <bounds:Plus<Lifetime>> =>
WhereClause::Lifetime { lifetime: l, bounds: bounds },
<f:ForAll?> <ty:TypeRef> ":" <bounds:TypeBounds> =>
<f:ForAll> <ty:TypeRef> ":" <bounds:TypeBounds> =>
WhereClause::Type { forall: f, ty: ty, bounds: bounds }
};
ForAll: Vec<Atom> =
"for" "<" <Comma<Lifetime>> ">";
ForAll: Vec<TypeParameter> = {
"for" "<" <Comma<TypeParameter>> ">",
() => vec![],
};
TypeBounds: Vec<TypeBound<TypeRef>> =
<Plus<TypeBound>>;
@ -65,9 +67,9 @@ TypeBounds: Vec<TypeBound<TypeRef>> =
TypeBound: TypeBound<TypeRef> = {
<l:Lifetime> =>
TypeBound::Lifetime(l),
<f:ForAll?> <p:Path> "(" <params:Comma<TypeRef>> ")" <ret:("->" <TypeRef>)?> =>
<f:ForAll> <p:Path> "(" <params:Comma<TypeRef>> ")" <ret:("->" <TypeRef>)?> =>
TypeBound::Fn { forall: f, path: p, parameters: params, ret: ret },
<f:ForAll?> <p:Path> <params:("<" <Comma<TypeBoundParameter>> ">")?> =>
<f:ForAll> <p:Path> <params:("<" <Comma<TypeBoundParameter>> ">")?> =>
TypeBound::Trait { forall: f, path: p, parameters: params.unwrap_or(vec![]) }
};