Skip to content

Commit

Permalink
Test failure of unchecked arithmetic intrinsics in const eval
Browse files Browse the repository at this point in the history
  • Loading branch information
ecstatic-morse committed Feb 11, 2020
1 parent a29424a commit ee52fe6
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 41 deletions.
22 changes: 22 additions & 0 deletions src/test/ui/consts/const-int-unchecked.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![feature(core_intrinsics)]
#![feature(const_int_unchecked_arith)]

use std::intrinsics;

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

// Other arithmetic functions:

const _: u16 = unsafe { std::intrinsics::unchecked_add(40000u16, 30000) };
//~^ ERROR any use of this value will cause an error

const _: u32 = unsafe { std::intrinsics::unchecked_sub(14u32, 22) };
//~^ ERROR any use of this value will cause an error

const _: u16 = unsafe { std::intrinsics::unchecked_mul(300u16, 250u16) };
//~^ ERROR any use of this value will cause an error

const _: i32 = unsafe { std::intrinsics::unchecked_div(1, 0) };
//~^ ERROR any use of this value will cause an error
const _: i32 = unsafe { std::intrinsics::unchecked_div(i32::min_value(), -1) };
//~^ ERROR any use of this value will cause an error

const _: i32 = unsafe { std::intrinsics::unchecked_rem(1, 0) };
//~^ ERROR any use of this value will cause an error
const _: i32 = unsafe { std::intrinsics::unchecked_rem(i32::min_value(), -1) };
//~^ ERROR any use of this value will cause an error

fn main() {}
Loading

0 comments on commit ee52fe6

Please sign in to comment.