-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
C-bugCategory: This is a bug.Category: This is a bug.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Description
I tried this code:
struct Thing {
label: &'static str,
panic_on_drop: bool,
}
impl Drop for Thing {
fn drop(&mut self) {
println!("Dropping: {}", self.label);
if self.panic_on_drop {
println!("Panicking...");
panic!("Drop panicked");
} else {
println!("Not panicking.")
}
}
}
fn main() {
let a = Thing {
label: "a",
panic_on_drop: false,
};
let b = Thing {
label: "b",
panic_on_drop: true,
};
let _ = std::hint::select_unpredictable(true, a, b);
}
I expected b
to be dropped, at which point a panic occurs, then a
is dropped. Instead, a
is not dropped at all.
Dropping: b
Panicking...
thread 'main' (133912) panicked at src/main.rs:11:13:
Drop panicked
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Meta
rustc --version --verbose
:
rustc 1.91.0-nightly (de3efa79f 2025-08-08)
binary: rustc
commit-hash: de3efa79f95852c7427587f1d535bfea7c0d6779
commit-date: 2025-08-08
host: aarch64-apple-darwin
release: 1.91.0-nightly
LLVM version: 21.1.0
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.