2020-09-11 03:35:28 -05:00
|
|
|
// run-pass
|
2021-08-27 11:04:57 -05:00
|
|
|
#![feature(generic_const_exprs)]
|
2020-09-11 03:35:28 -05:00
|
|
|
#![allow(incomplete_features)]
|
|
|
|
|
|
|
|
const fn test_me<T>(a: usize, b: usize) -> usize {
|
|
|
|
if a < b {
|
|
|
|
std::mem::size_of::<T>()
|
|
|
|
} else {
|
2020-10-24 18:21:40 -05:00
|
|
|
usize::MAX
|
2020-09-11 03:35:28 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_simple<T>() -> [u8; std::mem::size_of::<T>()]
|
|
|
|
where
|
|
|
|
[u8; std::mem::size_of::<T>()]: Sized,
|
|
|
|
{
|
|
|
|
[0; std::mem::size_of::<T>()]
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_with_args<T, const N: usize>() -> [u8; test_me::<T>(N, N + 1) + N]
|
|
|
|
where
|
|
|
|
[u8; test_me::<T>(N, N + 1) + N]: Sized,
|
|
|
|
{
|
|
|
|
[0; test_me::<T>(N, N + 1) + N]
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
assert_eq!([0; 8], test_simple::<u64>());
|
|
|
|
assert_eq!([0; 12], test_with_args::<u64, 4>());
|
|
|
|
}
|