From 0f06b07552e80f3438cb85d30ec407a2cd8995e8 Mon Sep 17 00:00:00 2001 From: Konrad Borowski Date: Fri, 12 Aug 2022 15:02:34 +0000 Subject: [PATCH] Implement UnwindSafe and RefUnwindSafe for Backtrace Backtrace doesn't have visible mutable state. --- library/std/src/backtrace.rs | 3 ++- library/std/src/backtrace/tests.rs | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/library/std/src/backtrace.rs b/library/std/src/backtrace.rs index f0e199fac73..e7110aebdea 100644 --- a/library/std/src/backtrace.rs +++ b/library/std/src/backtrace.rs @@ -92,6 +92,7 @@ use crate::env; use crate::ffi::c_void; use crate::fmt; +use crate::panic::UnwindSafe; use crate::sync::atomic::{AtomicUsize, Ordering::Relaxed}; use crate::sync::LazyLock; use crate::sys_common::backtrace::{lock, output_filename}; @@ -427,7 +428,7 @@ fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { } } -type LazyResolve = impl (FnOnce() -> Capture) + Send + Sync; +type LazyResolve = impl (FnOnce() -> Capture) + Send + Sync + UnwindSafe; fn lazy_resolve(mut capture: Capture) -> LazyResolve { move || { diff --git a/library/std/src/backtrace/tests.rs b/library/std/src/backtrace/tests.rs index ef419806dcc..73543a3af54 100644 --- a/library/std/src/backtrace/tests.rs +++ b/library/std/src/backtrace/tests.rs @@ -1,4 +1,5 @@ use super::*; +use crate::panic::{RefUnwindSafe, UnwindSafe}; fn generate_fake_frames() -> Vec { vec![ @@ -91,3 +92,9 @@ fn test_frames() { assert!(iter.all(|(f, e)| format!("{f:#?}") == *e)); } + +#[test] +fn backtrace_unwind_safe() { + fn assert_unwind_safe() {} + assert_unwind_safe::(); +}