Add support for cfg(overflow_checks)
This PR adds support for detecting if overflow checks are enabled in similar fashion as debug_assertions are detected. Possible use-case of this, for example, if we want to use checked integer casts in builds with overflow checks, e.g. ```rust pub fn cast(val: usize)->u16 { if cfg!(overflow_checks) { val.try_into().unwrap() } else{ vas as _ } } ``` Resolves #91130. Tracking issue: #111466.
This commit is contained in:
parent
f8d8ffa2eb
commit
7c263adb2a
8 changed files with 65 additions and 0 deletions
|
@ -24,6 +24,7 @@ pub type GatedCfg = (Symbol, Symbol, GateFn);
|
|||
/// `cfg(...)`'s that are feature gated.
|
||||
const GATED_CFGS: &[GatedCfg] = &[
|
||||
// (name in cfg, feature, function to check if the feature is enabled)
|
||||
(sym::overflow_checks, sym::cfg_overflow_checks, cfg_fn!(cfg_overflow_checks)),
|
||||
(sym::target_abi, sym::cfg_target_abi, cfg_fn!(cfg_target_abi)),
|
||||
(sym::target_thread_local, sym::cfg_target_thread_local, cfg_fn!(cfg_target_thread_local)),
|
||||
(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue