-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-mir-optArea: MIR optimizationsArea: MIR optimizationsA-monomorphizationArea: MonomorphizationArea: MonomorphizationC-bugCategory: This is a bug.Category: This is a bug.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
#![feature(inline_const)]
#![crate_type = "lib"]
pub fn f<T>() -> usize {
g::<()>()
}
pub fn g<T>() -> usize {
const { 0 / std::mem::size_of::<T>() }
}
This compiles fine in debug builds, but fails in release builds:
$ rustc b.rs
$ rustc b.rs -O
error[E0080]: evaluation of `g::<()>::{constant#0}` failed
--> b.rs:7:13
|
7 | const { 0 / std::mem::size_of::<T>() }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to divide `0_usize` by zero
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0080`.
Based on #107503 (comment) cc @RalfJung.
But also see this example based on type sizes.
Metadata
Metadata
Assignees
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-mir-optArea: MIR optimizationsArea: MIR optimizationsA-monomorphizationArea: MonomorphizationArea: MonomorphizationC-bugCategory: This is a bug.Category: This is a bug.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.