Skip to content

Commit 388f774

Browse files
committed
Give the assume intrinsic a fallback body
1 parent 56b5d35 commit 388f774

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

core/src/intrinsics.rs

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -937,20 +937,30 @@ extern "rust-intrinsic" {
937937
#[rustc_nounwind]
938938
pub fn unreachable() -> !;
939939

940-
/// Informs the optimizer that a condition is always true.
941-
/// If the condition is false, the behavior is undefined.
942-
///
943-
/// No code is generated for this intrinsic, but the optimizer will try
944-
/// to preserve it (and its condition) between passes, which may interfere
945-
/// with optimization of surrounding code and reduce performance. It should
946-
/// not be used if the invariant can be discovered by the optimizer on its
947-
/// own, or if it does not enable any significant optimizations.
948-
///
949-
/// This intrinsic does not have a stable counterpart.
950-
#[rustc_const_stable(feature = "const_assume", since = "1.77.0")]
951-
#[rustc_nounwind]
952-
pub fn assume(b: bool);
940+
}
941+
942+
/// Informs the optimizer that a condition is always true.
943+
/// If the condition is false, the behavior is undefined.
944+
///
945+
/// No code is generated for this intrinsic, but the optimizer will try
946+
/// to preserve it (and its condition) between passes, which may interfere
947+
/// with optimization of surrounding code and reduce performance. It should
948+
/// not be used if the invariant can be discovered by the optimizer on its
949+
/// own, or if it does not enable any significant optimizations.
950+
///
951+
/// This intrinsic does not have a stable counterpart.
952+
#[rustc_const_stable(feature = "const_assume", since = "1.77.0")]
953+
#[rustc_nounwind]
954+
#[unstable(feature = "core_intrinsics", issue = "none")]
955+
#[cfg_attr(not(bootstrap), rustc_intrinsic)]
956+
pub const unsafe fn assume(b: bool) {
957+
if !b {
958+
// SAFETY: the caller must guarantee the argument is never `false`
959+
unsafe { unreachable() }
960+
}
961+
}
953962

963+
extern "rust-intrinsic" {
954964
/// Hints to the compiler that branch condition is likely to be true.
955965
/// Returns the value passed to it.
956966
///

0 commit comments

Comments
 (0)