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

Conversation

Amanieu
Copy link
Member

@Amanieu Amanieu commented Apr 16, 2025

The current implementation doesn't call the drop the value that is not selected. This could be fixed in the future but for now it is sufficient to limit this to Copy types.

The current implementation doesn't call the drop the value that is not
selected. This could be fixed in the future but for now it is sufficient
to limit this to `Copy` types.
@rustbot
Copy link
Collaborator

rustbot commented Apr 16, 2025

r? @ibraheemdev

rustbot has assigned @ibraheemdev.
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-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 16, 2025
@rust-log-analyzer
Copy link
Collaborator

The job mingw-check failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
---- library/core/src/hint.rs - hint::select_unpredictable (line 764) stdout ----
error[E0277]: the trait bound `&mut Vec<i32>: Copy` is not satisfied
   --> library/core/src/hint.rs:773:18
    |
12  |     let bucket = hint::select_unpredictable(hash % 2 == 0, bucket_one, bucket_two);
    |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `&mut Vec<i32>`
    |
    = note: `Copy` is implemented for `&Vec<i32>`, but not for `&mut Vec<i32>`
note: required by a bound in `std::hint::select_unpredictable`
   --> /checkout/library/core/src/hint.rs:783:32
    |
783 | pub fn select_unpredictable<T: Copy>(condition: bool, true_val: T, false_val: T) -> T {
    |                                ^^^^ required by this bound in `select_unpredictable`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0277`.

@workingjubilee
Copy link
Member

need to fix an example, looks like

@joboet
Copy link
Member

joboet commented Apr 17, 2025

I don't think this is a good idea as it also forbids the usage of select_unpredictable with mutable references.

@Amanieu
Copy link
Member Author

Amanieu commented Apr 17, 2025

Closing in favor of #139977 which fixes drop handling.

@Amanieu Amanieu closed this Apr 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. 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