Skip to content

Commit 3a6169e

Browse files
committed
Add support for + on GAT bounds
1 parent 23ec213 commit 3a6169e

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

chalk-parse/src/ast.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub struct TraitFlags {
5454
pub struct AssocTyDefn {
5555
pub name: Identifier,
5656
pub parameter_kinds: Vec<ParameterKind>,
57-
pub bound: Option<TraitRef>,
57+
pub bounds: Vec<TraitBound>,
5858
pub where_clauses: Vec<QuantifiedWhereClause>,
5959
}
6060

@@ -177,6 +177,11 @@ impl PolarizedTraitRef {
177177
}
178178
}
179179

180+
pub struct TraitBound {
181+
pub trait_name: Identifier,
182+
pub args_no_self: Vec<Parameter>,
183+
}
184+
180185
#[derive(Copy, Clone, Debug)]
181186
pub struct Identifier {
182187
pub str: InternedString,

chalk-parse/src/parser.lalrpop

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,25 +72,23 @@ TraitDefn: TraitDefn = {
7272
};
7373

7474
AssocTyDefn: AssocTyDefn = {
75-
"type" <name:Id> <p:Angle<ParameterKind>> <b:(":" <Id> <Angle<Parameter>>)?>
75+
"type" <name:Id> <p:Angle<ParameterKind>> <b:(":" <Plus<TraitBound>>)?>
7676
<w:QuantifiedWhereClauses> ";" =>
7777
{
78-
let bound = match b {
79-
Some((t, a)) => {
80-
let mut args = vec![Parameter::Ty(Ty::Id{ name })];
81-
args.extend(a);
82-
Some(TraitRef {
83-
trait_name: t,
84-
args: args,
85-
})
86-
}
87-
None => None
88-
};
8978
AssocTyDefn {
9079
name: name,
9180
parameter_kinds: p,
9281
where_clauses: w,
93-
bound,
82+
bounds: b.unwrap_or(vec![]),
83+
}
84+
}
85+
};
86+
87+
TraitBound: TraitBound = {
88+
<t:Id> <a:Angle<Parameter>> => {
89+
TraitBound {
90+
trait_name: t,
91+
args_no_self: a,
9492
}
9593
}
9694
};
@@ -301,6 +299,11 @@ SemiColon<T>: Vec<T> = {
301299
<Separator<";", T>>
302300
};
303301

302+
#[inline]
303+
Plus<T>: Vec<T> = {
304+
<Separator<"+", T>>
305+
};
306+
304307
Angle<T>: Vec<T> = {
305308
"<" <Comma<T>> ">",
306309
() => vec![],

src/ir/lowering/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ fn gat_parse() {
311311
trait Sized {}
312312
313313
trait Foo {
314-
type Item<'a, T>: Clone where Self: Sized;
314+
type Item<'a, T>: Sized + Clone where Self: Sized;
315315
}
316316
317317
trait Bar {

0 commit comments

Comments
 (0)