7

Add support for `cfg(overflow_checks)` by AngelicosPhosphoros · Pull Request #11...

 1 year ago
source link: https://github.com/rust-lang/rust/pull/111096
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Conversation

Contributor

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.

pub fn cast(val: usize)->u16 {
    if cfg!(overflow_checks) {
        val.try_into().unwrap()
    }
    else{
        vas as _
    }
}

Resolves #91130.

jyn514, Dushistov, aznhe21, matthiasbeyer, and Aloso reacted with thumbs up emojileonardo-m reacted with heart emoji

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK