Skip to content

Require T: Copy for hint::select_unpredictable #139933

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions library/core/src/hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,9 +735,9 @@ pub const fn cold_path() {
crate::intrinsics::cold_path()
}

/// Returns either `true_val` or `false_val` depending on the value of `b`,
/// with a hint to the compiler that `b` is unlikely to be correctly
/// predicted by a CPU’s branch predictor.
/// Returns either `true_val` or `false_val` depending on the value of
/// `condition`, with a hint to the compiler that `condition` is unlikely to be
/// correctly predicted by a CPU’s branch predictor.
///
/// This method is functionally equivalent to
/// ```ignore (this is just for illustrative purposes)
Expand All @@ -753,9 +753,9 @@ pub const fn cold_path() {
/// search.
///
/// Note however that this lowering is not guaranteed (on any platform) and
/// should not be relied upon when trying to write constant-time code. Also
/// be aware that this lowering might *decrease* performance if `condition`
/// is well-predictable. It is advisable to perform benchmarks to tell if
/// should not be relied upon when trying to write cryptographic constant-time
/// code. Also be aware that this lowering might *decrease* performance if
/// `condition` is well-predictable. It is advisable to perform benchmarks to tell if
/// this function is useful.
///
/// # Examples
Expand All @@ -780,6 +780,6 @@ pub const fn cold_path() {
/// ```
#[inline(always)]
#[unstable(feature = "select_unpredictable", issue = "133962")]
pub fn select_unpredictable<T>(b: bool, true_val: T, false_val: T) -> T {
crate::intrinsics::select_unpredictable(b, true_val, false_val)
pub fn select_unpredictable<T: Copy>(condition: bool, true_val: T, false_val: T) -> T {
crate::intrinsics::select_unpredictable(condition, true_val, false_val)
}
1 change: 1 addition & 0 deletions tests/codegen/intrinsics/select_unpredictable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub fn test_pair(p: bool, a: (u64, u64), b: (u64, u64)) -> (u64, u64) {
core::intrinsics::select_unpredictable(p, a, b)
}

#[derive(Copy)]
struct Large {
e: [u64; 100],
}
Expand Down
Loading