Skip to content

Commit 4f1b5ff

Browse files
committed
Auto merge of #2929 - RalfJung:tls-panic, r=RalfJung
add tests for panicky drop in thread_local destructor Adds a test for rust-lang/rust#112285
2 parents 71312d6 + 4e598b8 commit 4f1b5ff

4 files changed

+75
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@error-in-other-file: aborted execution
2+
3+
pub struct NoisyDrop {}
4+
5+
impl Drop for NoisyDrop {
6+
fn drop(&mut self) {
7+
panic!("ow");
8+
}
9+
}
10+
11+
thread_local! {
12+
pub static NOISY: NoisyDrop = const { NoisyDrop {} };
13+
}
14+
15+
fn main() {
16+
NOISY.with(|_| ());
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
thread '<unnamed>' panicked at 'ow', $DIR/thread_local_const_drop_panic.rs:LL:CC
2+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
3+
fatal runtime error: thread local panicked on drop
4+
error: abnormal termination: the program aborted execution
5+
--> RUSTLIB/std/src/sys/PLATFORM/mod.rs:LL:CC
6+
|
7+
LL | unsafe { libc::abort() }
8+
| ^^^^^^^^^^^^^ the program aborted execution
9+
|
10+
= note: inside `std::sys::PLATFORM::abort_internal` at RUSTLIB/std/src/sys/PLATFORM/mod.rs:LL:CC
11+
= note: inside `<std::thread::local_impl::abort_on_dtor_unwind::DtorUnwindGuard as std::ops::Drop>::drop` at RUSTLIB/std/src/rt.rs:LL:CC
12+
= note: inside `std::ptr::drop_in_place::<std::thread::local_impl::abort_on_dtor_unwind::DtorUnwindGuard> - shim(Some(std::thread::local_impl::abort_on_dtor_unwind::DtorUnwindGuard))` at RUSTLIB/core/src/ptr/mod.rs:LL:CC
13+
= note: inside `RUSTLIB/std/src/sys/PLATFORM/thread_local/fast_local.rs:LL:CC]>` at RUSTLIB/std/src/sys/PLATFORM/thread_local/mod.rs:LL:CC
14+
note: inside `NOISY::__getit::destroy`
15+
--> $DIR/thread_local_const_drop_panic.rs:LL:CC
16+
|
17+
LL | / thread_local! {
18+
LL | | pub static NOISY: NoisyDrop = const { NoisyDrop {} };
19+
LL | | }
20+
| |_^
21+
= note: this error originates in the macro `$crate::thread::local_impl::thread_local_inner` which comes from the expansion of the macro `thread_local` (in Nightly builds, run with -Z macro-backtrace for more info)
22+
23+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
24+
25+
error: aborting due to previous error
26+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@error-in-other-file: aborted execution
2+
3+
pub struct NoisyDrop {}
4+
5+
impl Drop for NoisyDrop {
6+
fn drop(&mut self) {
7+
panic!("ow");
8+
}
9+
}
10+
11+
thread_local! {
12+
pub static NOISY: NoisyDrop = NoisyDrop {};
13+
}
14+
15+
fn main() {
16+
NOISY.with(|_| ());
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
thread '<unnamed>' panicked at 'ow', $DIR/thread_local_drop_panic.rs:LL:CC
2+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
3+
fatal runtime error: thread local panicked on drop
4+
error: abnormal termination: the program aborted execution
5+
--> RUSTLIB/std/src/sys/PLATFORM/mod.rs:LL:CC
6+
|
7+
LL | unsafe { libc::abort() }
8+
| ^^^^^^^^^^^^^ the program aborted execution
9+
|
10+
= note: inside `std::sys::PLATFORM::abort_internal` at RUSTLIB/std/src/sys/PLATFORM/mod.rs:LL:CC
11+
= note: inside `std::sys::PLATFORM::thread_local::fast_local::destroy_value::<NoisyDrop>` at RUSTLIB/std/src/rt.rs:LL:CC
12+
= note: inside `std::sys_common::thread_local_dtor::register_dtor_fallback::run_dtors` at RUSTLIB/std/src/sys_common/thread_local_dtor.rs:LL:CC
13+
14+
error: aborting due to previous error
15+

0 commit comments

Comments
 (0)