Skip to content

Commit c695d1b

Browse files
committed
Make ptr_guaranteed_cmp a rustc_intrinsic and favor its body over backends implementing it
1 parent e2f11bc commit c695d1b

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

core/src/intrinsics.rs

+18-9
Original file line numberDiff line numberDiff line change
@@ -2434,20 +2434,29 @@ extern "rust-intrinsic" {
24342434
#[rustc_nounwind]
24352435
pub fn ptr_offset_from_unsigned<T>(ptr: *const T, base: *const T) -> usize;
24362436

2437-
/// See documentation of `<*const T>::guaranteed_eq` for details.
2438-
/// Returns `2` if the result is unknown.
2439-
/// Returns `1` if the pointers are guaranteed equal
2440-
/// Returns `0` if the pointers are guaranteed inequal
2441-
///
2442-
/// Note that, unlike most intrinsics, this is safe to call;
2443-
/// it does not require an `unsafe` block.
2444-
/// Therefore, implementations must not require the user to uphold
2445-
/// any safety invariants.
24462437
#[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
24472438
#[rustc_safe_intrinsic]
24482439
#[rustc_nounwind]
2440+
#[cfg(bootstrap)]
24492441
pub fn ptr_guaranteed_cmp<T>(ptr: *const T, other: *const T) -> u8;
2442+
}
24502443

2444+
/// See documentation of `<*const T>::guaranteed_eq` for details.
2445+
/// Returns `2` if the result is unknown.
2446+
/// Returns `1` if the pointers are guaranteed equal
2447+
/// Returns `0` if the pointers are guaranteed inequal
2448+
#[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
2449+
#[unstable(feature = "core_intrinsics", issue = "none")]
2450+
#[rustc_intrinsic]
2451+
#[cfg(not(bootstrap))]
2452+
#[rustc_nounwind]
2453+
#[rustc_do_not_const_check]
2454+
#[inline]
2455+
pub const fn ptr_guaranteed_cmp<T>(ptr: *const T, other: *const T) -> u8 {
2456+
(ptr == other) as u8
2457+
}
2458+
2459+
extern "rust-intrinsic" {
24512460
/// Determines whether the raw bytes of the two values are equal.
24522461
///
24532462
/// This is particularly handy for arrays, since it allows things like just

0 commit comments

Comments
 (0)