Files
rust/tests/ui/consts/const-array-oob-arith.rs
T
Esteban Küber 87d8f5885b Provide more context on type errors in const context
- On `const` and `static` point at the type (like we do for let bindings)
- On fn calls, point at const parameter in fn definition
- On type, point at const parameter in type definition
- On array type lengths, explain that array length is always `usize`
- On enum variant discriminant, mention `repr`
2026-03-14 20:13:43 +00:00

17 lines
451 B
Rust

const ARR: [i32; 6] = [42, 43, 44, 45, 46, 47];
const IDX: usize = 3;
const VAL: i32 = ARR[IDX];
const BONG: [i32; (ARR[0] - 41) as usize] = [5];
const BLUB: [i32; (ARR[0] - 40) as usize] = [5];
//~^ ERROR: mismatched types
//~| NOTE: expected an array
//~| NOTE: expected because
const BOO: [i32; (ARR[0] - 41) as usize] = [5, 99];
//~^ ERROR: mismatched types
//~| NOTE: expected an array
//~| NOTE: expected because
fn main() {
let _ = VAL;
}