Files
rust/tests/ui/consts/array-repeat-expr-not-const.rs

11 lines
363 B
Rust
Raw Normal View History

2025-06-30 00:05:58 +05:00
//! Arrays created with `[value; length]` syntax need the length to be known at
//! compile time. This test makes sure the compiler rejects runtime values like
//! function parameters in the length position.
fn main() {
2025-06-30 00:05:58 +05:00
fn create_array(n: usize) {
let _x = [0; n];
//~^ ERROR attempt to use a non-constant value in a constant [E0435]
}
}