2020-08-10 13:50:58 -05:00
|
|
|
// Tests that array sizes that depend on const-params are checked using `ConstEvaluatable`.
|
2020-08-09 01:19:57 -05:00
|
|
|
// revisions: full min
|
|
|
|
|
2021-08-30 03:59:53 -05:00
|
|
|
#![cfg_attr(full, feature(generic_const_exprs, adt_const_params))]
|
2020-08-09 01:19:57 -05:00
|
|
|
#![cfg_attr(full, allow(incomplete_features))]
|
2020-01-05 17:00:47 -06:00
|
|
|
|
|
|
|
#[allow(dead_code)]
|
2020-01-20 09:22:12 -06:00
|
|
|
struct ArithArrayLen<const N: usize>([u32; 0 + N]);
|
2021-08-27 11:04:57 -05:00
|
|
|
//[full]~^ ERROR unconstrained generic constant
|
2020-10-12 16:27:59 -05:00
|
|
|
//[min]~^^ ERROR generic parameters may not be used in const operations
|
2020-01-05 17:00:47 -06:00
|
|
|
|
2023-05-16 23:05:46 -05:00
|
|
|
#[cfg(full)]
|
|
|
|
use std::marker::ConstParamTy;
|
|
|
|
|
2020-01-05 17:00:47 -06:00
|
|
|
#[derive(PartialEq, Eq)]
|
2023-05-16 23:05:46 -05:00
|
|
|
#[cfg_attr(full, derive(ConstParamTy))]
|
2020-01-05 17:00:47 -06:00
|
|
|
struct Config {
|
|
|
|
arr_size: usize,
|
|
|
|
}
|
|
|
|
|
|
|
|
struct B<const CFG: Config> {
|
2020-08-18 15:44:06 -05:00
|
|
|
//[min]~^ ERROR `Config` is forbidden
|
2020-08-09 01:19:57 -05:00
|
|
|
arr: [u8; CFG.arr_size],
|
2021-08-27 11:04:57 -05:00
|
|
|
//[full]~^ ERROR overly complex generic constant
|
2020-10-12 16:27:59 -05:00
|
|
|
//[min]~^^ ERROR generic parameters may not be used in const operations
|
2020-01-05 17:00:47 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
const C: Config = Config { arr_size: 5 };
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let b = B::<C> { arr: [1, 2, 3, 4, 5] };
|
|
|
|
assert_eq!(b.arr.len(), 5);
|
|
|
|
}
|