overflow_checks in core::intrinsics - Rust
Description: Returns whether we should perform some overflow-checking at runtime. This eventually evaluates to `cfg!(overflow_checks)`, but behaves different from `cfg!` when mixing crates built with different flags: if the crate has overflow checks enabled or carries the `#[rustc_inherit_overflow_checks]` attribute, evaluation is delayed until monomorphization (or until the call gets inlined into a crate that does not delay evaluation further); otherwise it can happen any time.

## overflow_checks

# Function overflow_checks

Source

    pub const fn overflow_checks() -> bool

🔬This is a nightly-only experimental API. (`core_intrinsics`)
Expand description

Returns whether we should perform some overflow-checking at runtime. This eventually evaluates to `cfg!(overflow_checks)`, but behaves different from `cfg!` when mixing crates built with different flags: if the crate has overflow checks enabled or carries the `#[rustc_inherit_overflow_checks]` attribute, evaluation is delayed until monomorphization (or until the call gets inlined into a crate that does not delay evaluation further); otherwise it can happen any time.

The common case here is a user program built with overflow_checks linked against the distributed sysroot which is built without overflow_checks but with `#[rustc_inherit_overflow_checks]`. For code that gets monomorphized in the user crate (i.e., generic functions and functions with `#[inline]`), gating assertions on `overflow_checks()` rather than `cfg!(overflow_checks)` means that assertions are enabled whenever the user crate has overflow checks enabled. However if the user has overflow checks disabled, the checks will still get optimized out.