Auto merge of #128250 - Amanieu:select_unpredictable, r=nikic · model-checking/verify-rust-std@a50fe57 (original) (raw)

`@@ -1008,6 +1008,34 @@ pub const fn unlikely(b: bool) -> bool {

`

1008

1008

` b

`

1009

1009

`}

`

1010

1010

``

``

1011

`` +

/// Returns either true_val or false_val depending on condition b with a

``

``

1012

`+

/// hint to the compiler that this condition is unlikely to be correctly

`

``

1013

`+

/// predicted by a CPU's branch predictor (e.g. a binary search).

`

``

1014

`+

///

`

``

1015

`` +

/// This is otherwise functionally equivalent to if b { true_val } else { false_val }.

``

``

1016

`+

///

`

``

1017

`+

/// Note that, unlike most intrinsics, this is safe to call;

`

``

1018

`` +

/// it does not require an unsafe block.

``

``

1019

`+

/// Therefore, implementations must not require the user to uphold

`

``

1020

`+

/// any safety invariants.

`

``

1021

`+

///

`

``

1022

`+

/// This intrinsic does not have a stable counterpart.

`

``

1023

`+

#[cfg(not(bootstrap))]

`

``

1024

`+

#[unstable(feature = "core_intrinsics", issue = "none")]

`

``

1025

`+

#[rustc_intrinsic]

`

``

1026

`+

#[rustc_nounwind]

`

``

1027

`+

#[miri::intrinsic_fallback_is_spec]

`

``

1028

`+

#[inline]

`

``

1029

`+

pub fn select_unpredictable(b: bool, true_val: T, false_val: T) -> T {

`

``

1030

`+

if b { true_val } else { false_val }

`

``

1031

`+

}

`

``

1032

+

``

1033

`+

#[cfg(bootstrap)]

`

``

1034

`+

#[inline]

`

``

1035

`+

pub fn select_unpredictable(b: bool, true_val: T, false_val: T) -> T {

`

``

1036

`+

if b { true_val } else { false_val }

`

``

1037

`+

}

`

``

1038

+

1011

1039

`extern "rust-intrinsic" {

`

1012

1040

`/// Executes a breakpoint trap, for inspection by a debugger.

`

1013

1041

`///

`