Skip to content

Conversation

@RedDaedalus
Copy link
Contributor

intrinsics::select_unpredictable does not drop the value that is not selected, but the fallback impl did not consider this behavior. This creates an observable difference between Miri and actual execution, and possibly does not play well with the core::hint version which has extra logic to drop the value that was not selected.

#![feature(core_intrinsics)]

fn main() {
    core::intrinsics::select_unpredictable(true, LoudDrop(0), LoudDrop(1));
    // cargo run: "0"; cargo miri run: "1 0"
}

struct LoudDrop(u8);

impl Drop for LoudDrop {
    fn drop(&mut self) {
        print!("{} ", self.0);
    }
}

This change let me remove the T: [const] Destruct bound as well, since the destructor is no longer relevant.

@rustbot
Copy link
Collaborator

rustbot commented Jan 13, 2026

Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter
gets adapted for the changes, if necessary.

cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr

@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 Jan 13, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 13, 2026

r? @joboet

rustbot has assigned @joboet.
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

@rust-log-analyzer

This comment has been minimized.

@RalfJung
Copy link
Member

Good catch!

Could you add a Miri test?

@rustbot
Copy link
Collaborator

rustbot commented Jan 13, 2026

The Miri subtree was changed

cc @rust-lang/miri

@rustbot
Copy link
Collaborator

rustbot commented Jan 13, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rustbot

This comment has been minimized.

@rustbot rustbot added has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 13, 2026
@RedDaedalus RedDaedalus force-pushed the fix-select-unpredictable-fallback branch from a69e8e6 to 44ae04e Compare January 13, 2026 15:10
@rustbot rustbot removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. has-merge-commits PR has merge commits, merge with caution. labels Jan 13, 2026
@RedDaedalus
Copy link
Contributor Author

@RalfJung test added!

@RedDaedalus RedDaedalus force-pushed the fix-select-unpredictable-fallback branch from 44ae04e to 7d3bf37 Compare January 16, 2026 13:46
Copy link
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

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

Libs bits LGTM, but since this is mostly miri:

r? @RalfJung

@rustbot rustbot assigned RalfJung and unassigned joboet Jan 22, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 22, 2026

RalfJung is not on the review rotation at the moment.
They may take a while to respond.

@RalfJung
Copy link
Member

@bors r+ rollup

@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 22, 2026

📌 Commit 7d3bf37 has been approved by RalfJung

It is now in the queue for this repository.

@rust-bors rust-bors bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 22, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jan 22, 2026
…le-fallback, r=RalfJung

fix fallback impl for select_unpredictable intrinsic

`intrinsics::select_unpredictable` does not drop the value that is not selected, but the fallback impl did not consider this behavior. This creates an observable difference between Miri and actual execution, and possibly does not play well with the `core::hint` version which has extra logic to drop the value that was not selected.
```rust
#![feature(core_intrinsics)]

fn main() {
    core::intrinsics::select_unpredictable(true, LoudDrop(0), LoudDrop(1));
    // cargo run: "0"; cargo miri run: "1 0"
}

struct LoudDrop(u8);

impl Drop for LoudDrop {
    fn drop(&mut self) {
        print!("{} ", self.0);
    }
}
```

This change let me remove the `T: [const] Destruct` bound as well, since the destructor is no longer relevant.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jan 22, 2026
…le-fallback, r=RalfJung

fix fallback impl for select_unpredictable intrinsic

`intrinsics::select_unpredictable` does not drop the value that is not selected, but the fallback impl did not consider this behavior. This creates an observable difference between Miri and actual execution, and possibly does not play well with the `core::hint` version which has extra logic to drop the value that was not selected.
```rust
#![feature(core_intrinsics)]

fn main() {
    core::intrinsics::select_unpredictable(true, LoudDrop(0), LoudDrop(1));
    // cargo run: "0"; cargo miri run: "1 0"
}

struct LoudDrop(u8);

impl Drop for LoudDrop {
    fn drop(&mut self) {
        print!("{} ", self.0);
    }
}
```

This change let me remove the `T: [const] Destruct` bound as well, since the destructor is no longer relevant.
rust-bors bot pushed a commit that referenced this pull request Jan 22, 2026
…uwer

Rollup of 8 pull requests

Successful merges:

 - #148206 (Deduplicated float tests and unified in floats/mod.rs)
 - #151042 (fix fallback impl for select_unpredictable intrinsic)
 - #151220 (option: Use Option::map in Option::cloned)
 - #151260 (Handle unevaluated ConstKind in in_operand)
 - #151441 (Fix ICE: Don't try to evaluate type_consts when eagerly collecting items)
 - #151465 (codegen: clarify some variable names around function calls)
 - #151469 (llvm: Tolerate dead_on_return attribute changes)
 - #151476 (Avoid `-> ()` in derived functions.)

r? @ghost
rust-bors bot pushed a commit that referenced this pull request Jan 22, 2026
…uwer

Rollup of 8 pull requests

Successful merges:

 - #148206 (Deduplicated float tests and unified in floats/mod.rs)
 - #151042 (fix fallback impl for select_unpredictable intrinsic)
 - #151220 (option: Use Option::map in Option::cloned)
 - #151260 (Handle unevaluated ConstKind in in_operand)
 - #151441 (Fix ICE: Don't try to evaluate type_consts when eagerly collecting items)
 - #151465 (codegen: clarify some variable names around function calls)
 - #151469 (llvm: Tolerate dead_on_return attribute changes)
 - #151476 (Avoid `-> ()` in derived functions.)

r? @ghost
rust-bors bot pushed a commit that referenced this pull request Jan 22, 2026
…uwer

Rollup of 8 pull requests

Successful merges:

 - #148206 (Deduplicated float tests and unified in floats/mod.rs)
 - #151042 (fix fallback impl for select_unpredictable intrinsic)
 - #151220 (option: Use Option::map in Option::cloned)
 - #151260 (Handle unevaluated ConstKind in in_operand)
 - #151441 (Fix ICE: Don't try to evaluate type_consts when eagerly collecting items)
 - #151465 (codegen: clarify some variable names around function calls)
 - #151469 (llvm: Tolerate dead_on_return attribute changes)
 - #151476 (Avoid `-> ()` in derived functions.)

r? @ghost
rust-bors bot pushed a commit that referenced this pull request Jan 22, 2026
…uwer

Rollup of 11 pull requests

Successful merges:

 - #151001 (rustdoc: render doc(hidden) as a code attribute)
 - #151042 (fix fallback impl for select_unpredictable intrinsic)
 - #151220 (option: Use Option::map in Option::cloned)
 - #151260 (Handle unevaluated ConstKind in in_operand)
 - #151296 (MGCA: Fix incorrect pretty printing of valtree arrays)
 - #151423 (Move assert_matches to planned stable path)
 - #151441 (Fix ICE: Don't try to evaluate type_consts when eagerly collecting items)
 - #151465 (codegen: clarify some variable names around function calls)
 - #151468 (fix `f16` doctest FIXMEs)
 - #151469 (llvm: Tolerate dead_on_return attribute changes)
 - #151476 (Avoid `-> ()` in derived functions.)

r? @ghost
rust-bors bot pushed a commit that referenced this pull request Jan 22, 2026
…uwer

Rollup of 11 pull requests

Successful merges:

 - #151001 (rustdoc: render doc(hidden) as a code attribute)
 - #151042 (fix fallback impl for select_unpredictable intrinsic)
 - #151220 (option: Use Option::map in Option::cloned)
 - #151260 (Handle unevaluated ConstKind in in_operand)
 - #151296 (MGCA: Fix incorrect pretty printing of valtree arrays)
 - #151423 (Move assert_matches to planned stable path)
 - #151441 (Fix ICE: Don't try to evaluate type_consts when eagerly collecting items)
 - #151465 (codegen: clarify some variable names around function calls)
 - #151468 (fix `f16` doctest FIXMEs)
 - #151469 (llvm: Tolerate dead_on_return attribute changes)
 - #151476 (Avoid `-> ()` in derived functions.)

r? @ghost
rust-bors bot pushed a commit that referenced this pull request Jan 22, 2026
…uwer

Rollup of 11 pull requests

Successful merges:

 - #151001 (rustdoc: render doc(hidden) as a code attribute)
 - #151042 (fix fallback impl for select_unpredictable intrinsic)
 - #151220 (option: Use Option::map in Option::cloned)
 - #151260 (Handle unevaluated ConstKind in in_operand)
 - #151296 (MGCA: Fix incorrect pretty printing of valtree arrays)
 - #151423 (Move assert_matches to planned stable path)
 - #151441 (Fix ICE: Don't try to evaluate type_consts when eagerly collecting items)
 - #151465 (codegen: clarify some variable names around function calls)
 - #151468 (fix `f16` doctest FIXMEs)
 - #151469 (llvm: Tolerate dead_on_return attribute changes)
 - #151476 (Avoid `-> ()` in derived functions.)

r? @ghost
@rust-bors rust-bors bot merged commit ddd8965 into rust-lang:main Jan 22, 2026
11 checks passed
@rustbot rustbot added this to the 1.95.0 milestone Jan 22, 2026
rust-timer added a commit that referenced this pull request Jan 22, 2026
Rollup merge of #151042 - RedDaedalus:fix-select-unpredictable-fallback, r=RalfJung

fix fallback impl for select_unpredictable intrinsic

`intrinsics::select_unpredictable` does not drop the value that is not selected, but the fallback impl did not consider this behavior. This creates an observable difference between Miri and actual execution, and possibly does not play well with the `core::hint` version which has extra logic to drop the value that was not selected.
```rust
#![feature(core_intrinsics)]

fn main() {
    core::intrinsics::select_unpredictable(true, LoudDrop(0), LoudDrop(1));
    // cargo run: "0"; cargo miri run: "1 0"
}

struct LoudDrop(u8);

impl Drop for LoudDrop {
    fn drop(&mut self) {
        print!("{} ", self.0);
    }
}
```

This change let me remove the `T: [const] Destruct` bound as well, since the destructor is no longer relevant.
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Jan 23, 2026
…uwer

Rollup of 11 pull requests

Successful merges:

 - rust-lang/rust#151001 (rustdoc: render doc(hidden) as a code attribute)
 - rust-lang/rust#151042 (fix fallback impl for select_unpredictable intrinsic)
 - rust-lang/rust#151220 (option: Use Option::map in Option::cloned)
 - rust-lang/rust#151260 (Handle unevaluated ConstKind in in_operand)
 - rust-lang/rust#151296 (MGCA: Fix incorrect pretty printing of valtree arrays)
 - rust-lang/rust#151423 (Move assert_matches to planned stable path)
 - rust-lang/rust#151441 (Fix ICE: Don't try to evaluate type_consts when eagerly collecting items)
 - rust-lang/rust#151465 (codegen: clarify some variable names around function calls)
 - rust-lang/rust#151468 (fix `f16` doctest FIXMEs)
 - rust-lang/rust#151469 (llvm: Tolerate dead_on_return attribute changes)
 - rust-lang/rust#151476 (Avoid `-> ()` in derived functions.)

r? @ghost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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