Skip to content

Commit e74d5be

Browse files
committed
Add documentation to the likely/unlikely intrinsics
1 parent 4bd32cf commit e74d5be

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/libcore/intrinsics.rs

+15
Original file line numberDiff line numberDiff line change
@@ -603,8 +603,23 @@ extern "rust-intrinsic" {
603603
/// cast to a `u64`; if `T` has no discriminant, returns 0.
604604
pub fn discriminant_value<T>(v: &T) -> u64;
605605

606+
/// Hints to the compiler that a branch is likely to be taken. Returns the value
607+
/// passed to it. In order for the hint to take effect, it should be used as follows:
608+
///
609+
/// ```
610+
/// unsafe fn foo(a: i32, b: i32) -> i32 {
611+
/// if likely(a == b) {
612+
/// 1
613+
/// } else {
614+
/// 2
615+
/// }
616+
/// }
617+
/// ```
606618
#[cfg(not(stage0))]
607619
pub fn likely(v: bool) -> bool;
620+
621+
/// Hints to the compiler that a branch is not likely to be taken. See `likely` for
622+
/// more details
608623
#[cfg(not(stage0))]
609624
pub fn unlikely(v: bool) -> bool;
610625
}

0 commit comments

Comments
 (0)