Skip to content

Commit ced1b24

Browse files
committed
Add parse rules for ProjectionEq bounds on GATs
1 parent 3a6169e commit ced1b24

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

chalk-parse/src/ast.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,23 @@ pub enum Parameter {
6868
Lifetime(Lifetime),
6969
}
7070

71+
pub struct TraitBound {
72+
pub trait_name: Identifier,
73+
pub args_no_self: Vec<TraitBoundParameter>,
74+
}
75+
76+
pub enum TraitBoundParameter {
77+
Ty(Ty),
78+
Lifetime(Lifetime),
79+
ProjectionEq(ProjectionEqBound),
80+
}
81+
82+
pub struct ProjectionEqBound {
83+
pub name: Identifier,
84+
pub parameters: Vec<Parameter>,
85+
pub value: Ty,
86+
}
87+
7188
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
7289
pub enum Kind {
7390
Ty,
@@ -177,11 +194,6 @@ impl PolarizedTraitRef {
177194
}
178195
}
179196

180-
pub struct TraitBound {
181-
pub trait_name: Identifier,
182-
pub args_no_self: Vec<Parameter>,
183-
}
184-
185197
#[derive(Copy, Clone, Debug)]
186198
pub struct Identifier {
187199
pub str: InternedString,

chalk-parse/src/parser.lalrpop

+13-1
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,26 @@ AssocTyDefn: AssocTyDefn = {
8585
};
8686

8787
TraitBound: TraitBound = {
88-
<t:Id> <a:Angle<Parameter>> => {
88+
<t:Id> <a:Angle<TraitBoundParameter>> => {
8989
TraitBound {
9090
trait_name: t,
9191
args_no_self: a,
9292
}
9393
}
9494
};
9595

96+
TraitBoundParameter: TraitBoundParameter = {
97+
Ty => TraitBoundParameter::Ty(<>),
98+
Lifetime => TraitBoundParameter::Lifetime(<>),
99+
ProjectionEqBound => TraitBoundParameter::ProjectionEq(<>),
100+
};
101+
102+
ProjectionEqBound: ProjectionEqBound = {
103+
<name:Id> <parameters:Angle<Parameter>> "=" <value:Ty> => ProjectionEqBound {
104+
name, parameters, value
105+
},
106+
};
107+
96108
Impl: Impl = {
97109
"impl" <p:Angle<ParameterKind>> <mark:"!"?> <t:Id> <a:Angle<Parameter>> "for" <s:Ty>
98110
<w:QuantifiedWhereClauses> "{" <assoc:AssocTyValue*> "}" =>

src/ir/lowering/test.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,12 @@ fn gat_parse() {
318318
type Item<'a, T> where Self: Sized;
319319
}
320320
321+
struct Container<T> {
322+
value: T
323+
}
324+
321325
trait Baz {
322-
type Item<'a, T>: Clone;
326+
type Item<'a, 'b, T>: Foo<Item<'b, T> = Containter<T>> + Clone;
323327
}
324328
325329
trait Quux {

0 commit comments

Comments
 (0)