Skip to content

Commit

Permalink
Rollup merge of rust-lang#68937 - ecstatic-morse:unchecked-intrinsics…
Browse files Browse the repository at this point in the history
…-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
  • Loading branch information
JohnTitor authored Feb 12, 2020
2 parents 19b0c00 + ee52fe6 commit 4b82b51
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 4b82b51

Please sign in to comment.