Skip to content

Commit c97af34

Browse files
authored
Rollup merge of #100455 - xfix:backtrace-ref-unwind-safe, r=dtolnay
Implement RefUnwindSafe for Backtrace Backtrace doesn't have visible mutable state. See also https://internals.rust-lang.org/t/should-backtrace-be-refunwindsafe/17169?u=xfix
2 parents c435af0 + 0f06b07 commit c97af34

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

library/std/src/backtrace.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ use crate::backtrace_rs::{self, BytesOrWideString};
9292
use crate::env;
9393
use crate::ffi::c_void;
9494
use crate::fmt;
95+
use crate::panic::UnwindSafe;
9596
use crate::sync::atomic::{AtomicUsize, Ordering::Relaxed};
9697
use crate::sync::LazyLock;
9798
use crate::sys_common::backtrace::{lock, output_filename};
@@ -427,7 +428,7 @@ impl fmt::Display for Backtrace {
427428
}
428429
}
429430

430-
type LazyResolve = impl (FnOnce() -> Capture) + Send + Sync;
431+
type LazyResolve = impl (FnOnce() -> Capture) + Send + Sync + UnwindSafe;
431432

432433
fn lazy_resolve(mut capture: Capture) -> LazyResolve {
433434
move || {

library/std/src/backtrace/tests.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use super::*;
2+
use crate::panic::{RefUnwindSafe, UnwindSafe};
23

34
fn generate_fake_frames() -> Vec<BacktraceFrame> {
45
vec![
@@ -91,3 +92,9 @@ fn test_frames() {
9192

9293
assert!(iter.all(|(f, e)| format!("{f:#?}") == *e));
9394
}
95+
96+
#[test]
97+
fn backtrace_unwind_safe() {
98+
fn assert_unwind_safe<T: UnwindSafe + RefUnwindSafe>() {}
99+
assert_unwind_safe::<Backtrace>();
100+
}

0 commit comments

Comments
 (0)