Skip to content

Commit 4b82b51

Browse files
authored
Rollup merge of rust-lang#68937 - ecstatic-morse:unchecked-intrinsics-test, r=RalfJung
Test failure of unchecked arithmetic intrinsics in const eval Test that the unchecked arithmetic intrinsics that were made unstably const in rust-lang#68809 emit an error during const-eval if given invalid input. Addresses [this comment](rust-lang#68809 (comment)). r? @RalfJung
2 parents 19b0c00 + ee52fe6 commit 4b82b51

File tree

2 files changed

+119
-41
lines changed

2 files changed

+119
-41
lines changed

src/test/ui/consts/const-int-unchecked.rs

+22
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![feature(core_intrinsics)]
2+
#![feature(const_int_unchecked_arith)]
23

34
use std::intrinsics;
45

@@ -117,4 +118,25 @@ const SHR_I64_NEG_RANDOM: i64 = unsafe { intrinsics::unchecked_shr(5_i64, -30) }
117118
const SHR_I128_NEG_RANDOM: i128 = unsafe { intrinsics::unchecked_shr(5_i128, -93) };
118119
//~^ ERROR any use of this value will cause an error
119120

121+
// Other arithmetic functions:
122+
123+
const _: u16 = unsafe { std::intrinsics::unchecked_add(40000u16, 30000) };
124+
//~^ ERROR any use of this value will cause an error
125+
126+
const _: u32 = unsafe { std::intrinsics::unchecked_sub(14u32, 22) };
127+
//~^ ERROR any use of this value will cause an error
128+
129+
const _: u16 = unsafe { std::intrinsics::unchecked_mul(300u16, 250u16) };
130+
//~^ ERROR any use of this value will cause an error
131+
132+
const _: i32 = unsafe { std::intrinsics::unchecked_div(1, 0) };
133+
//~^ ERROR any use of this value will cause an error
134+
const _: i32 = unsafe { std::intrinsics::unchecked_div(i32::min_value(), -1) };
135+
//~^ ERROR any use of this value will cause an error
136+
137+
const _: i32 = unsafe { std::intrinsics::unchecked_rem(1, 0) };
138+
//~^ ERROR any use of this value will cause an error
139+
const _: i32 = unsafe { std::intrinsics::unchecked_rem(i32::min_value(), -1) };
140+
//~^ ERROR any use of this value will cause an error
141+
120142
fn main() {}

0 commit comments

Comments
 (0)