Skip to content

Commit bc193d5

Browse files
committed
Parse and lower array types
1 parent 55a63e9 commit bc193d5

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

chalk-integration/src/lowering.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,6 +1395,18 @@ impl LowerTy for Ty {
13951395
})
13961396
.intern(interner)),
13971397

1398+
Ty::Array { ty, len } => Ok(chalk_ir::TyData::Apply(chalk_ir::ApplicationTy {
1399+
name: chalk_ir::TypeName::Array,
1400+
substitution: chalk_ir::Substitution::from(
1401+
interner,
1402+
&[
1403+
ty.lower(env)?.cast(interner),
1404+
len.lower(env)?.cast(interner),
1405+
],
1406+
),
1407+
})
1408+
.intern(interner)),
1409+
13981410
Ty::Slice { ty } => Ok(chalk_ir::TyData::Apply(chalk_ir::ApplicationTy {
13991411
name: chalk_ir::TypeName::Slice,
14001412
substitution: chalk_ir::Substitution::from_fallible(

chalk-parse/src/ast.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ pub enum Ty {
212212
Slice {
213213
ty: Box<Ty>,
214214
},
215+
Array {
216+
ty: Box<Ty>,
217+
len: Box<GenericArg>,
218+
},
215219
Raw {
216220
mutability: Mutability,
217221
ty: Box<Ty>,

chalk-parse/src/parser.lalrpop

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ TyWithoutId: Ty = {
239239
"&" <l: Lifetime> "mut" <t:Ty> => Ty::Ref{ mutability: Mutability::Mut, lifetime: l, ty: Box::new(t) },
240240
"&" <l: Lifetime> <t:Ty> => Ty::Ref{ mutability: Mutability::Not, lifetime: l, ty: Box::new(t) },
241241
"[" <t:Ty> "]" => Ty::Slice { ty: Box::new(t) },
242+
"[" <t:Ty> ";" <len:GenericArg> "]" => Ty::Array { ty: Box::new(t), len: Box::new(len) },
242243
};
243244

244245
ScalarType: ScalarType = {

tests/lowering/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,3 +584,15 @@ fn fn_defs() {
584584
}
585585
}
586586
}
587+
588+
#[test]
589+
fn arrays() {
590+
lowering_success! {
591+
program {
592+
struct Baz { }
593+
fn foo(bar: [Baz; 3]);
594+
595+
fn bar<const N>(baz: [Baz; N]);
596+
}
597+
}
598+
}

0 commit comments

Comments
 (0)