Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Overflowing addition is never UB in Rust - it is defined to wrap around in release builds (i.e. it would be a compiler bug if adding 1 to 255_u8 in a release build produced any value other than 0_u8).


Sorry, was thinking of signed integer overflow which while considered sound is simultaneously considered to be a a bug in your code (hence the panic in debug mode and requires the use of wrapping_add if you intend the wrapping).


Rust behaves as you describe for both signed and unsigned.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: