Skip to content

Commit 4387480

Browse files
committed
Add unstably const support for assume intrinsic
1 parent 3e08354 commit 4387480

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

compiler/rustc_mir/src/interpret/intrinsics.rs

+6
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
435435
// These just return their argument
436436
self.copy_op(args[0], dest)?;
437437
}
438+
sym::assume => {
439+
let cond = self.read_scalar(args[0])?.check_init()?.to_bool()?;
440+
if !cond {
441+
throw_ub_format!("`assume` intrinsic called with `false`");
442+
}
443+
}
438444
_ => return Ok(false),
439445
}
440446

library/core/src/intrinsics.rs

+1
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,7 @@ extern "rust-intrinsic" {
733733
/// own, or if it does not enable any significant optimizations.
734734
///
735735
/// This intrinsic does not have a stable counterpart.
736+
#[rustc_const_unstable(feature = "const_assume", issue = "76972")]
736737
pub fn assume(b: bool);
737738

738739
/// Hints to the compiler that branch condition is likely to be true.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// check-pass
2+
3+
// Check that `const_assume` feature allow `assume` intrinsic
4+
// to be used in const contexts.
5+
6+
#![feature(core_intrinsics, const_assume)]
7+
8+
extern crate core;
9+
10+
use core::intrinsics::assume;
11+
12+
pub const unsafe fn foo(x: usize, y: usize) -> usize {
13+
assume(y != 0);
14+
x / y
15+
}
16+
17+
fn main() {}

0 commit comments

Comments
 (0)