Closed
Description
Inline const blocks default to the i32
type on integer literals, see the following:
#![feature(inline_const)]
fn main() {
let _: usize = const { 0 };
}
fails compilation with:
error[E0308]: mismatched types
--> src/main.rs:4:20
|
4 | let _: usize = const { 0 };
| ----- ^^^^^ expected `usize`, found `i32`
| |
| expected due to this
|
help: you can convert an `i32` to `usize` and panic if the converted value wouldn't fit
|
4 | let _: usize = const.try_into().unwrap() { 0 };
Regular integer literals, and in unsafe blocks just get the type right: let _: usize = 0
and let _: usize = unsafe { 0 };
Another minor thing is the error message, const.try_into().unwrap() { 0 };
is an invalid suggestion ^^.