Closed econoplas closed 9 years ago
Closing this issue as my patch incorrectly produces warnings for values like -128i8 and -32768i16 and -2147483648i32, which is clearly incorrect. I should have tested more thoroughly before posting the issue. I will keep digging for another work-around.
I included a patch for review below rather than forking all of rust to propose a change to 3 lines of code.
Even though the subject says 1.0.0 this fix may be applicable to master and 1.1.0-dev as well.
Problem:
Building rust-1.0.0 from source crashes building stage1 libcore due to librustc_lint/builtins.rs in TypeLimits.LintPass::check_expr calling MIN::abs() resulting in panick at 'arithmetic operation overflowed'.
This is coincidentally related to the decision to close #25378 and not back-port range check to abs() since the abs() panic issue had already been fixed in master and 1.1.0-dev (confirmed).
In librustc_lint/builtins.rs check_expr can easily be modified to eliminate the need to call i32::MIN::abs() and avoid the panic during compile. The call to abs() is within a match block that deals only with signed integer literals with a positive sign (as far as I can tell that's what ast::Plus means), so there should not be a need to check for negative or call min.abs() here:
I am contributing the following patch against 1.0.0 but this same fix applies to master and 1.1.0-dev as far as I can tell. Not only does this fix the compile panic issue by not calling abs() and also simplifies the code a bit in this section:
I tried this code:
I expected to see this happen:
A successful compile of rust 1.0.0 from sources.
Instead, this happened:
thread 'rustc' panicked at 'arithmetic operation overflowed', /tmp/build/rustc-1.0.0/src/libcore/num/mod.rs:509
NOTES:
Meta
Backtrace: