Skip to content

Commit f2f45ff

Browse files
committed
Add mGCA array expression tests
1 parent 522be7f commit f2f45ff

11 files changed

Lines changed: 147 additions & 38 deletions
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![expect(incomplete_features)]
2+
#![feature(min_generic_const_args, adt_const_params)]
3+
4+
fn takes_array<const A: [u32; 3]>() {}
5+
6+
fn generic_caller<const X: u32, const Y: usize>() {
7+
// not supported yet
8+
takes_array::<{ [1, 2, 1 + 2] }>();
9+
//~^ ERROR: complex const arguments must be placed inside of a `const` block
10+
takes_array::<{ [X; 3] }>();
11+
//~^ ERROR: complex const arguments must be placed inside of a `const` block
12+
takes_array::<{ [0; Y] }>();
13+
//~^ ERROR: complex const arguments must be placed inside of a `const` block
14+
}
15+
16+
fn main() {}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: complex const arguments must be placed inside of a `const` block
2+
--> $DIR/array-expr-complex.rs:8:28
3+
|
4+
LL | takes_array::<{ [1, 2, 1 + 2] }>();
5+
| ^^^^^
6+
7+
error: complex const arguments must be placed inside of a `const` block
8+
--> $DIR/array-expr-complex.rs:10:19
9+
|
10+
LL | takes_array::<{ [X; 3] }>();
11+
| ^^^^^^^^^^
12+
13+
error: complex const arguments must be placed inside of a `const` block
14+
--> $DIR/array-expr-complex.rs:12:19
15+
|
16+
LL | takes_array::<{ [0; Y] }>();
17+
| ^^^^^^^^^^
18+
19+
error: aborting due to 3 previous errors
20+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![expect(incomplete_features)]
2+
#![feature(min_generic_const_args)]
3+
4+
fn takes_empty_array<const A: []>() {}
5+
//~^ ERROR: expected type, found `]`
6+
7+
fn main() {
8+
takes_empty_array::<{ [] }>();
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: expected type, found `]`
2+
--> $DIR/array-expr-empty.rs:4:32
3+
|
4+
LL | fn takes_empty_array<const A: []>() {}
5+
| ^ expected type
6+
7+
error: aborting due to 1 previous error
8+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//@ run-pass
2+
#![expect(incomplete_features)]
3+
#![feature(min_generic_const_args, adt_const_params)]
4+
#![allow(dead_code)]
5+
6+
fn takes_array_u32<const A: [u32; 3]>() {}
7+
fn takes_array_bool<const A: [bool; 2]>() {}
8+
fn takes_nested_array<const A: [[u32; 2]; 2]>() {}
9+
fn takes_empty_array<const A: [u32; 0]>() {}
10+
11+
fn generic_caller<const X: u32, const Y: u32>() {
12+
takes_array_u32::<{ [X, Y, X] }>();
13+
takes_array_u32::<{ [X, Y, const { 1 }] }>();
14+
takes_array_u32::<{ [X, Y, const { 1 + 1 }] }>();
15+
takes_array_u32::<{ [2_002, 2u32, 1_u32] }>();
16+
17+
takes_array_bool::<{ [true, false] }>();
18+
19+
takes_nested_array::<{ [[X, Y], [3, 4]] }>();
20+
takes_nested_array::<{ [[1u32, 2_u32], [const { 3 }, 4]] }>();
21+
22+
takes_empty_array::<{ [] }>();
23+
}
24+
25+
fn main() {}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//@ run-pass
2+
#![expect(incomplete_features)]
3+
#![feature(min_generic_const_args, adt_const_params)]
4+
#![allow(dead_code)]
5+
6+
fn takes_array<const A: [u32; 3]>() {}
7+
8+
trait Trait {
9+
#[type_const]
10+
const ASSOC: u32;
11+
}
12+
13+
fn generic_caller<T: Trait, const N: u32>() {
14+
takes_array::<{ [T::ASSOC, N, T::ASSOC] }>();
15+
takes_array::<{ [1_u32, T::ASSOC, 2] }>();
16+
}
17+
18+
fn main() {}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//@ run-pass
2+
#![expect(incomplete_features)]
3+
#![feature(min_generic_const_args, adt_const_params)]
4+
#![allow(dead_code)]
5+
6+
macro_rules! make_array {
7+
($n:expr, $m:expr, $p:expr) => {
8+
[N, $m, $p]
9+
};
10+
}
11+
12+
fn takes_array<const A: [u32; 3]>() {}
13+
14+
fn generic_caller<const N: u32>() {
15+
takes_array::<{ make_array!(N, 2, 3) }>();
16+
}
17+
18+
fn main() {}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//@ run-pass
2+
#![feature(min_generic_const_args, adt_const_params)]
3+
#![expect(incomplete_features)]
4+
#![allow(dead_code)]
5+
6+
use std::marker::ConstParamTy;
7+
8+
#[derive(PartialEq, Eq, ConstParamTy)]
9+
struct Container {
10+
values: [u32; 3],
11+
}
12+
13+
fn takes_container<const C: Container>() {}
14+
15+
fn generic_caller<const N: u32, const M: u32>() {
16+
takes_container::<{ Container { values: [N, M, 1] } }>();
17+
takes_container::<{ Container { values: [1, 2, 3] } }>();
18+
}
19+
20+
fn main() {}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@ run-pass
2+
#![feature(min_generic_const_args, adt_const_params, unsized_const_params)]
3+
#![expect(incomplete_features)]
4+
#![allow(dead_code)]
5+
6+
fn takes_tuple<const T: ([u32; 2], u32, [u32; 2])>() {}
7+
8+
fn generic_caller<const N: u32, const M: u32>() {
9+
takes_tuple::<{ ([N, M], 5, [M, N]) }>();
10+
takes_tuple::<{ ([1, 2], 3, [4, 5]) }>();
11+
}
12+
13+
fn main() {}

tests/ui/const-generics/mgca/array-expr.rs

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)