-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Closed
Labels
A-inferenceArea: Type inferenceArea: Type inferenceC-bugCategory: This is a bug.Category: This is a bug.F-inline_constInline constants (aka: const blocks, const expressions, anonymous constants)Inline constants (aka: const blocks, const expressions, anonymous constants)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
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 ^^.
Metadata
Metadata
Assignees
Labels
A-inferenceArea: Type inferenceArea: Type inferenceC-bugCategory: This is a bug.Category: This is a bug.F-inline_constInline constants (aka: const blocks, const expressions, anonymous constants)Inline constants (aka: const blocks, const expressions, anonymous constants)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.