diff options
| author | Stuart Cook <Zalathar@users.noreply.github.com> | 2025-08-08 12:52:49 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-08 12:52:49 +1000 |
| commit | cb271d055e6134c23b7cca5351353a7feb46458b (patch) | |
| tree | 8b10d62a2f1e5fa51a2ff271732600ccb8162c6e /tests/ui/drop | |
| parent | 2fd855fbfc8239285aa2d596f76a8cc75e17ce02 (diff) | |
| parent | b6e13e35911d1aabc7164fc069b09c4e8c91981e (diff) | |
| download | rust-cb271d055e6134c23b7cca5351353a7feb46458b.tar.gz rust-cb271d055e6134c23b7cca5351353a7feb46458b.zip | |
Rollup merge of #144400 - Kivooeo:issue3, r=jieyouxu
`tests/ui/issues/`: The Issues Strike Back [3/N] Some `tests/ui/issues/` housekeeping, to trim down number of tests directly under `tests/ui/issues/`. Part of https://github.com/rust-lang/rust/issues/133895. r? ```@jieyouxu```
Diffstat (limited to 'tests/ui/drop')
| -rw-r--r-- | tests/ui/drop/panic-during-drop-14875.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/ui/drop/panic-during-drop-14875.rs b/tests/ui/drop/panic-during-drop-14875.rs new file mode 100644 index 00000000000..5a6f8f42775 --- /dev/null +++ b/tests/ui/drop/panic-during-drop-14875.rs @@ -0,0 +1,38 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/14875 + +//@ run-pass +//@ needs-unwind +//@ ignore-backends: gcc + +// Check that values are not leaked when a dtor panics (#14875) + +use std::panic::{self, UnwindSafe}; + +struct SetInnerOnDrop<'a>(&'a mut bool); + +impl<'a> UnwindSafe for SetInnerOnDrop<'a> {} + +impl<'a> Drop for SetInnerOnDrop<'a> { + fn drop(&mut self) { + *self.0 = true; + } +} + +struct PanicOnDrop; +impl Drop for PanicOnDrop { + fn drop(&mut self) { + panic!("test panic"); + } +} + +fn main() { + let mut set_on_drop = false; + { + let set_inner_on_drop = SetInnerOnDrop(&mut set_on_drop); + let _ = panic::catch_unwind(|| { + let _set_inner_on_drop = set_inner_on_drop; + let _panic_on_drop = PanicOnDrop; + }); + } + assert!(set_on_drop); +} |
