mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 17:24:06 +00:00
5010ca001c
This fixes the issue wherein the lint didn't fire for promoteds in the case of SHL/SHR operators in non-optimized builds and all arithmetic operators in optimized builds
21 lines
1.0 KiB
Rust
21 lines
1.0 KiB
Rust
// Regression test for issue #117949
|
|
|
|
//@ revisions: noopt opt opt_with_overflow_checks
|
|
//@ [noopt]compile-flags: -C opt-level=0 -Z deduplicate-diagnostics=yes
|
|
//@ [opt]compile-flags: -O
|
|
//@ [opt_with_overflow_checks]compile-flags: -C overflow-checks=on -O -Z deduplicate-diagnostics=yes
|
|
//@ build-fail
|
|
//@ ignore-pass (test tests codegen-time behaviour)
|
|
|
|
|
|
fn main() {
|
|
format_args!("{}", 1 << 32); //~ ERROR: arithmetic operation will overflow
|
|
format_args!("{}", 1 >> 32); //~ ERROR: arithmetic operation will overflow
|
|
format_args!("{}", 1 + i32::MAX); //~ ERROR: arithmetic operation will overflow
|
|
format_args!("{}", -5 - i32::MAX); //~ ERROR: arithmetic operation will overflow
|
|
format_args!("{}", 5 * i32::MAX); //~ ERROR: arithmetic operation will overflow
|
|
format_args!("{}", 1 / 0); //~ ERROR: this operation will panic at runtime
|
|
format_args!("{}", 1 % 0); //~ ERROR: this operation will panic at runtime
|
|
format_args!("{}", [1, 2, 3][4]); //~ ERROR: this operation will panic at runtime
|
|
}
|