mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 09:14:20 +00:00
31 lines
639 B
Rust
31 lines
639 B
Rust
// run-pass
|
|
#![feature(generic_const_exprs)]
|
|
#![allow(incomplete_features)]
|
|
|
|
const fn test_me<T>(a: usize, b: usize) -> usize {
|
|
if a < b {
|
|
std::mem::size_of::<T>()
|
|
} else {
|
|
usize::MAX
|
|
}
|
|
}
|
|
|
|
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>());
|
|
}
|