diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:03 +0000 |
commit | 64d98f8ee037282c35007b64c2649055c56af1db (patch) | |
tree | 5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/ui/consts/const-err2.rs | |
parent | Adding debian version 1.67.1+dfsg1-1. (diff) | |
download | rustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip |
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/consts/const-err2.rs')
-rw-r--r-- | tests/ui/consts/const-err2.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/ui/consts/const-err2.rs b/tests/ui/consts/const-err2.rs new file mode 100644 index 000000000..db49ec25a --- /dev/null +++ b/tests/ui/consts/const-err2.rs @@ -0,0 +1,39 @@ +// needed because negating int::MIN will behave differently between +// optimized compilation and unoptimized compilation and thus would +// lead to different lints being emitted + +// revisions: noopt opt opt_with_overflow_checks +//[noopt]compile-flags: -C opt-level=0 +//[opt]compile-flags: -O +//[opt_with_overflow_checks]compile-flags: -C overflow-checks=on -O + +// build-fail + +#![feature(rustc_attrs)] + +fn black_box<T>(_: T) { + unimplemented!() +} + +fn main() { + let a = -i8::MIN; + //~^ ERROR arithmetic operation will overflow + let a_i128 = -i128::MIN; + //~^ ERROR arithmetic operation will overflow + let b = 200u8 + 200u8 + 200u8; + //~^ ERROR arithmetic operation will overflow + let b_i128 = i128::MIN - i128::MAX; + //~^ ERROR arithmetic operation will overflow + let c = 200u8 * 4; + //~^ ERROR arithmetic operation will overflow + let d = 42u8 - (42u8 + 1); + //~^ ERROR arithmetic operation will overflow + let _e = [5u8][1]; + //~^ ERROR operation will panic + black_box(a); + black_box(a_i128); + black_box(b); + black_box(b_i128); + black_box(c); + black_box(d); +} |