Closed
Description
pub fn test_saturating(a: u32) -> u32 {
a.saturating_add(7).saturating_add(13)
}
gets compiled to
playground::test_saturating:
add edi, 7
mov eax, -1
cmovb edi, eax
add edi, 13
cmovae eax, edi
ret
but ideally it would get compiled to a.saturating_add(20)
, aka
playground::test_saturating:
add edi, 20
mov eax, -1
cmovae eax, edi
ret
Ditto for checked_add.
Playground repro: https://play.rust-lang.org/?gist=eeea31ea85491e38bdd6d456b9f6e47f&version=nightly&mode=release&edition=2015
Found looking at step_by, which would like .next(); .nth(step)
to collapse nicely for ranges (#52065).