by tdbgamer · 8y ago · 0 comments
I personally think it's a good thing to only allow overflows when explicitly allowed.
1. overflow is a "program error"
2. If `debug_assertions` are enabled, then overflow must panic
3. If overflow does not panic, then it must two's compliment wrap
This leaves the door open to always requiring a panic someday in the future, if performance gets there.
Can you expand on what that means to someone who hasn't used Rust yet? Does it mean a third thing distinct from (2) and (3)? Or is it that (2) and (3) are the things that might happen as a result of (1)?
This is similar. "program error" means "You're not supposed to do this. But the compiler will not assume that you've not done this; it has your back. If you do this your program will exhibit defined behavior. Perhaps undesired behavior (panicking, or segfaulting), but the behavior will be defined."
Mostly, it means "this is wrong but it is not undefined behavior".
> Or is it that (2) and (3) are the things that might happen as a result of (1)?
Yes, this.
It is very risky to have different behavior on such things in test and production.
Maybe Rust++ will fix this, someday :p
(Or, once people have the tolerance for the performance degradation and we can turn it on in rustc, exactly why we specified it the way we did.)
(Or, you can tweak it to include this behavior in release mode; always an option)
Few things are harder to debug than things that pass the tests but fail in production and anything that inserts behavior like that should be avoided like the proverbial plague.
If you're already of a mindset to have a Rust++ then you are missing the point, Rust quite possibly has a window of opportunity to displace C but for that to work at a level where it succeeds rather than as an 'also ran' you will need to religiously avoid repeating the past.