-
Notifications
You must be signed in to change notification settings - Fork 183
Implement GATs, step 1 #118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
e490665
23ec213
3a6169e
52c171e
0db2be9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,9 +72,26 @@ TraitDefn: TraitDefn = { | |
}; | ||
|
||
AssocTyDefn: AssocTyDefn = { | ||
"type" <name:Id> <p:Angle<ParameterKind>> ";" => AssocTyDefn { | ||
name: name, | ||
parameter_kinds: p | ||
"type" <name:Id> <p:Angle<ParameterKind>> <b:(":" <Id> <Angle<Parameter>>)?> | ||
<w:QuantifiedWhereClauses> ";" => | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok so currently we do not handle at all the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
let bound = match b { | ||
Some((t, a)) => { | ||
let mut args = vec![Parameter::Ty(Ty::Id{ name })]; | ||
args.extend(a); | ||
Some(TraitRef { | ||
trait_name: t, | ||
args: args, | ||
}) | ||
} | ||
None => None | ||
}; | ||
AssocTyDefn { | ||
name: name, | ||
parameter_kinds: p, | ||
where_clauses: w, | ||
bound, | ||
} | ||
} | ||
}; | ||
|
||
|
@@ -102,11 +119,10 @@ ParameterKind: ParameterKind = { | |
}; | ||
|
||
AssocTyValue: AssocTyValue = { | ||
"type" <n:Id> <a:Angle<ParameterKind>> <wc:WhereClauses> "=" <v:Ty> ";" => AssocTyValue { | ||
"type" <n:Id> <a:Angle<ParameterKind>> "=" <v:Ty> ";" => AssocTyValue { | ||
name: n, | ||
parameter_kinds: a, | ||
value: v, | ||
where_clauses: wc, | ||
}, | ||
}; | ||
|
||
|
@@ -201,11 +217,6 @@ InlineClause: Clause = { | |
} | ||
}; | ||
|
||
WhereClauses: Vec<WhereClause> = { | ||
"where" <Comma<WhereClause>>, | ||
() => vec![], | ||
}; | ||
|
||
QuantifiedWhereClauses: Vec<QuantifiedWhereClause> = { | ||
"where" <Comma<QuantifiedWhereClause>>, | ||
() => vec![], | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We would need multiple bounds there (see below), and using
TraitRef
is too rigid as we cannot parse things liketype Foo<T>: Iterator<Item = T>
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking this would maybe need some slight refactoring for how we handle where clauses in the grammar. Something which may work would be to split existing where clauses like
TraitRef
into two parts: a left part (which would beT
inT: Foo<K>
) and a right part (which would beFoo<K>
), separated by the:
symbol. This would prevent code duplication I think because in the case of associated types, you would only ask for the right part and then build the wholeTraitRef
by hand as you did. It would be especially useful when we add lifetime requirements on types as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, what do you think of something like
TraitBound
andProjectionEqBound
that I added to ast? (Currently they're only being used for GATs.)These can contain methods to convert them to
TraitRef
,WhereClause::ProjectionEq
, etc. if the proper information is obtained.