Skip to content

Commit 52c171e

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

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

chalk-parse/src/ast.rs

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

71+
/// Represents a trait bound on e.g. a type or type parameter.
72+
/// Does not know anything about what it's binding.
73+
pub struct TraitBound {
74+
pub trait_name: Identifier,
75+
pub args_no_self: Vec<TraitBoundParameter>,
76+
}
77+
78+
pub enum TraitBoundParameter {
79+
Ty(Ty),
80+
Lifetime(Lifetime),
81+
ProjectionEq(ProjectionEqBound),
82+
}
83+
84+
pub struct ProjectionEqBound {
85+
pub name: Identifier,
86+
pub parameters: Vec<Parameter>,
87+
pub value: Ty,
88+
}
89+
7190
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
7291
pub enum Kind {
7392
Ty,
@@ -177,11 +196,6 @@ impl PolarizedTraitRef {
177196
}
178197
}
179198

180-
pub struct TraitBound {
181-
pub trait_name: Identifier,
182-
pub args_no_self: Vec<Parameter>,
183-
}
184-
185199
#[derive(Copy, Clone, Debug)]
186200
pub struct Identifier {
187201
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)