Skip to content

Commit 6025184

Browse files
committed
Parse and lower array types
1 parent 2cb6f79 commit 6025184

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
@@ -1384,6 +1384,18 @@ impl LowerTy for Ty {
13841384
})
13851385
.intern(interner)),
13861386

1387+
Ty::Array { ty, len } => Ok(chalk_ir::TyData::Apply(chalk_ir::ApplicationTy {
1388+
name: chalk_ir::TypeName::Array,
1389+
substitution: chalk_ir::Substitution::from(
1390+
interner,
1391+
&[
1392+
ty.lower(env)?.cast(interner),
1393+
len.lower(env)?.cast(interner),
1394+
],
1395+
),
1396+
})
1397+
.intern(interner)),
1398+
13871399
Ty::Slice { ty } => Ok(chalk_ir::TyData::Apply(chalk_ir::ApplicationTy {
13881400
name: chalk_ir::TypeName::Slice,
13891401
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
@@ -238,6 +238,7 @@ TyWithoutId: Ty = {
238238
"&" <l: Lifetime> "mut" <t:Ty> => Ty::Ref{ mutability: Mutability::Mut, lifetime: l, ty: Box::new(t) },
239239
"&" <l: Lifetime> <t:Ty> => Ty::Ref{ mutability: Mutability::Not, lifetime: l, ty: Box::new(t) },
240240
"[" <t:Ty> "]" => Ty::Slice { ty: Box::new(t) },
241+
"[" <t:Ty> ";" <len:GenericArg> "]" => Ty::Array { ty: Box::new(t), len: Box::new(len) },
241242
};
242243

243244
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)