Add mGCA array expression tests

This commit is contained in:
reddevilmidzy 2026-01-09 14:13:41 +09:00
parent 522be7f1c0
commit f2f45ffddd
11 changed files with 147 additions and 38 deletions

View file

@ -0,0 +1,16 @@
#![expect(incomplete_features)]
#![feature(min_generic_const_args, adt_const_params)]
fn takes_array<const A: [u32; 3]>() {}
fn generic_caller<const X: u32, const Y: usize>() {
// not supported yet
takes_array::<{ [1, 2, 1 + 2] }>();
//~^ ERROR: complex const arguments must be placed inside of a `const` block
takes_array::<{ [X; 3] }>();
//~^ ERROR: complex const arguments must be placed inside of a `const` block
takes_array::<{ [0; Y] }>();
//~^ ERROR: complex const arguments must be placed inside of a `const` block
}
fn main() {}

View file

@ -0,0 +1,20 @@
error: complex const arguments must be placed inside of a `const` block
--> $DIR/array-expr-complex.rs:8:28
|
LL | takes_array::<{ [1, 2, 1 + 2] }>();
| ^^^^^
error: complex const arguments must be placed inside of a `const` block
--> $DIR/array-expr-complex.rs:10:19
|
LL | takes_array::<{ [X; 3] }>();
| ^^^^^^^^^^
error: complex const arguments must be placed inside of a `const` block
--> $DIR/array-expr-complex.rs:12:19
|
LL | takes_array::<{ [0; Y] }>();
| ^^^^^^^^^^
error: aborting due to 3 previous errors

View file

@ -0,0 +1,9 @@
#![expect(incomplete_features)]
#![feature(min_generic_const_args)]
fn takes_empty_array<const A: []>() {}
//~^ ERROR: expected type, found `]`
fn main() {
takes_empty_array::<{ [] }>();
}

View file

@ -0,0 +1,8 @@
error: expected type, found `]`
--> $DIR/array-expr-empty.rs:4:32
|
LL | fn takes_empty_array<const A: []>() {}
| ^ expected type
error: aborting due to 1 previous error

View file

@ -0,0 +1,25 @@
//@ run-pass
#![expect(incomplete_features)]
#![feature(min_generic_const_args, adt_const_params)]
#![allow(dead_code)]
fn takes_array_u32<const A: [u32; 3]>() {}
fn takes_array_bool<const A: [bool; 2]>() {}
fn takes_nested_array<const A: [[u32; 2]; 2]>() {}
fn takes_empty_array<const A: [u32; 0]>() {}
fn generic_caller<const X: u32, const Y: u32>() {
takes_array_u32::<{ [X, Y, X] }>();
takes_array_u32::<{ [X, Y, const { 1 }] }>();
takes_array_u32::<{ [X, Y, const { 1 + 1 }] }>();
takes_array_u32::<{ [2_002, 2u32, 1_u32] }>();
takes_array_bool::<{ [true, false] }>();
takes_nested_array::<{ [[X, Y], [3, 4]] }>();
takes_nested_array::<{ [[1u32, 2_u32], [const { 3 }, 4]] }>();
takes_empty_array::<{ [] }>();
}
fn main() {}

View file

@ -0,0 +1,18 @@
//@ run-pass
#![expect(incomplete_features)]
#![feature(min_generic_const_args, adt_const_params)]
#![allow(dead_code)]
fn takes_array<const A: [u32; 3]>() {}
trait Trait {
#[type_const]
const ASSOC: u32;
}
fn generic_caller<T: Trait, const N: u32>() {
takes_array::<{ [T::ASSOC, N, T::ASSOC] }>();
takes_array::<{ [1_u32, T::ASSOC, 2] }>();
}
fn main() {}

View file

@ -0,0 +1,18 @@
//@ run-pass
#![expect(incomplete_features)]
#![feature(min_generic_const_args, adt_const_params)]
#![allow(dead_code)]
macro_rules! make_array {
($n:expr, $m:expr, $p:expr) => {
[N, $m, $p]
};
}
fn takes_array<const A: [u32; 3]>() {}
fn generic_caller<const N: u32>() {
takes_array::<{ make_array!(N, 2, 3) }>();
}
fn main() {}

View file

@ -0,0 +1,20 @@
//@ run-pass
#![feature(min_generic_const_args, adt_const_params)]
#![expect(incomplete_features)]
#![allow(dead_code)]
use std::marker::ConstParamTy;
#[derive(PartialEq, Eq, ConstParamTy)]
struct Container {
values: [u32; 3],
}
fn takes_container<const C: Container>() {}
fn generic_caller<const N: u32, const M: u32>() {
takes_container::<{ Container { values: [N, M, 1] } }>();
takes_container::<{ Container { values: [1, 2, 3] } }>();
}
fn main() {}

View file

@ -0,0 +1,13 @@
//@ run-pass
#![feature(min_generic_const_args, adt_const_params, unsized_const_params)]
#![expect(incomplete_features)]
#![allow(dead_code)]
fn takes_tuple<const T: ([u32; 2], u32, [u32; 2])>() {}
fn generic_caller<const N: u32, const M: u32>() {
takes_tuple::<{ ([N, M], 5, [M, N]) }>();
takes_tuple::<{ ([1, 2], 3, [4, 5]) }>();
}
fn main() {}

View file

@ -1,24 +0,0 @@
#![expect(incomplete_features)]
#![feature(min_generic_const_args, adt_const_params)]
fn takes_array<const A: [u32; 3]>() {}
fn generic_caller<const N: u32, const N2: u32>() {
takes_array::<{ [N, N2, N] }>(); // ok
takes_array::<{ [N, N2, const { 1 }] }>(); // ok
takes_array::<{ [N, N2, const { 1 + 1 }] }>(); // ok
takes_array::<{ [N, N2, 1] }>(); // ok
takes_array::<{ [1, 1u32, 1_u32] }>(); // ok
takes_array::<{ [N, N2, 1 + 1] }>(); // not implemented
//~^ ERROR complex const arguments must be placed inside of a `const` block
takes_array::<{ [N; 3] }>(); // not implemented
//~^ ERROR complex const arguments must be placed inside of a `const` block
}
fn main() {}

View file

@ -1,14 +0,0 @@
error: complex const arguments must be placed inside of a `const` block
--> $DIR/array-expr.rs:17:29
|
LL | takes_array::<{ [N, N2, 1 + 1] }>(); // not implemented
| ^^^^^
error: complex const arguments must be placed inside of a `const` block
--> $DIR/array-expr.rs:20:19
|
LL | takes_array::<{ [N; 3] }>(); // not implemented
| ^^^^^^^^^^
error: aborting due to 2 previous errors