Skip to content

Commit 6a671bd

Browse files
committed
Give the assume intrinsic a fallback body
1 parent ae9d7b0 commit 6a671bd

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

compiler/rustc_hir_analysis/src/check/intrinsic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ pub fn check_intrinsic_type(
407407
}
408408
sym::float_to_int_unchecked => (2, 0, vec![param(0)], param(1)),
409409

410-
sym::assume => (0, 0, vec![tcx.types.bool], Ty::new_unit(tcx)),
410+
sym::assume => (0, 1, vec![tcx.types.bool], Ty::new_unit(tcx)),
411411
sym::likely => (0, 0, vec![tcx.types.bool], tcx.types.bool),
412412
sym::unlikely => (0, 0, vec![tcx.types.bool], tcx.types.bool),
413413

library/core/src/intrinsics.rs

+23-13
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)