Skip to content

Commit 4762301

Browse files
committed
Auto merge of #2914 - RalfJung:unchecked_shl, r=RalfJung
add unchecked_shl test rust-lang/rust#112238 made me realize that we have a test for add,sub,mul,shr but not shl. Add the missing test. Also name the existing tests more consistently.
2 parents 8095bbc + 77a984b commit 4762301

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![feature(unchecked_math)]
2+
3+
fn main() {
4+
unsafe {
5+
let _n = 1i8.unchecked_shl(8);
6+
//~^ ERROR: overflowing shift by 8 in `unchecked_shl`
7+
}
8+
}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: Undefined Behavior: overflowing shift by 8 in `unchecked_shl`
2+
--> $DIR/unchecked_shl.rs:LL:CC
3+
|
4+
LL | let _n = 1i8.unchecked_shl(8);
5+
| ^^^^^^^^^^^^^^^^^^^^ overflowing shift by 8 in `unchecked_shl`
6+
|
7+
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
8+
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9+
= note: BACKTRACE:
10+
= note: inside `main` at $DIR/unchecked_shl.rs:LL:CC
11+
12+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
13+
14+
error: aborting due to previous error
15+

tests/fail/intrinsics/overflowing-unchecked-rsh.stderr tests/fail/intrinsics/unchecked_shr.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error: Undefined Behavior: overflowing shift by 64 in `unchecked_shr`
2-
--> $DIR/overflowing-unchecked-rsh.rs:LL:CC
2+
--> $DIR/unchecked_shr.rs:LL:CC
33
|
44
LL | let _n = 1i64.unchecked_shr(64);
55
| ^^^^^^^^^^^^^^^^^^^^^^ overflowing shift by 64 in `unchecked_shr`
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
99
= note: BACKTRACE:
10-
= note: inside `main` at $DIR/overflowing-unchecked-rsh.rs:LL:CC
10+
= note: inside `main` at $DIR/unchecked_shr.rs:LL:CC
1111

1212
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
1313

0 commit comments

Comments
 (0)