Skip to content

Conversation

clarfonthey
Copy link
Contributor

@clarfonthey clarfonthey commented Aug 27, 2025

Tracking issue: #145938

Since constants don't actually care about branch prediction, this just uses const_eval_select to use a normal if statement in const-time, instead of having to make the intrinsic work in const context.

@rustbot
Copy link
Collaborator

rustbot commented Aug 27, 2025

r? @tgross35

rustbot has assigned @tgross35.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Aug 27, 2025
@clarfonthey clarfonthey changed the title const `select_unpredictable const select_unpredictable Aug 27, 2025
@rust-log-analyzer
Copy link
Collaborator

The job aarch64-gnu-llvm-19-2 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
    |
note: required by a bound in `select_predictable`
   --> library/core/src/hint.rs:807:12
    |
805 |     const fn select_predictable<T>(condition: bool, true_val: T, false_val: T) -> T
    |              ------------------ required by a bound in this function
806 |     where
807 |         T: [const] Destruct,
    |            ^^^^^^^^^^^^^^^^ required by this bound in `select_predictable`

error: const function that might be (indirectly) exposed to stable cannot use `#[feature(const_destruct)]`
   --> library/core/src/hint.rs:805:66
    |
805 |     const fn select_predictable<T>(condition: bool, true_val: T, false_val: T) -> T
    |                                                                  ^^^^^^^^^
    |
help: if the function is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
    |
805 +     #[rustc_const_unstable(feature = "...", issue = "...")]
806 |     const fn select_predictable<T>(condition: bool, true_val: T, false_val: T) -> T
    |

error: const function that might be (indirectly) exposed to stable cannot use `#[feature(const_destruct)]`
   --> library/core/src/hint.rs:805:53
    |
805 |     const fn select_predictable<T>(condition: bool, true_val: T, false_val: T) -> T
    |                                                     ^^^^^^^^
    |
help: if the function is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
    |
805 +     #[rustc_const_unstable(feature = "...", issue = "...")]
806 |     const fn select_predictable<T>(condition: bool, true_val: T, false_val: T) -> T
    |

For more information about this error, try `rustc --explain E0277`.
[RUSTC-TIMING] core test:false 23.229
error: could not compile `core` (lib) due to 3 previous errors

(condition, true_val, false_val),
select_predictable,
select_actually_unpredictable,
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't marking the select_unpredictable intrinsic itself as const work? It already has a fallback body equivalent to your select_predictable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I probably should have thought of that first…

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this would be blocked on #145725 then, if I did that. Which I'm fine doing, I think.

Since MaybeUninit::assume_init_drop requires ptr::drop_in_place.

@clarfonthey
Copy link
Contributor Author

@rustbot blocked

@rustbot rustbot added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 28, 2025
@bors
Copy link
Collaborator

bors commented Aug 31, 2025

☔ The latest upstream changes (presumably #146052) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-blocked Status: Blocked on something else such as an RFC or other implementation work. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants