Skip to content

Commit

Permalink
fn assume: Make safe (#1216)
Browse files Browse the repository at this point in the history
  • Loading branch information
kkysen authored Jun 21, 2024
2 parents a5d01ae + 6484e85 commit 4100ec4
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/assume.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
#![deny(unsafe_op_in_unsafe_fn)]

use std::hint::unreachable_unchecked;

/// A stable version of [`core::intrinsics::assume`].
///
/// # Safety
///
/// `condition` must always be `true`.
#[inline(always)]
pub unsafe fn assume(condition: bool) {
if !condition {
unreachable_unchecked();
// SAFETY: `condition` is `true` by the `# Safety` preconditions.
unsafe { unreachable_unchecked() };
}
}

0 comments on commit 4100ec4

Please sign in to comment.