Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement RefUnwindSafe for Backtrace #100455

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion library/std/src/backtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ use crate::backtrace_rs::{self, BytesOrWideString};
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};
Expand Down Expand Up @@ -427,7 +428,7 @@ impl fmt::Display for Backtrace {
}
}

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

fn lazy_resolve(mut capture: Capture) -> LazyResolve {
move || {
Expand Down
7 changes: 7 additions & 0 deletions library/std/src/backtrace/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::*;
use crate::panic::{RefUnwindSafe, UnwindSafe};

fn generate_fake_frames() -> Vec<BacktraceFrame> {
vec![
Expand Down Expand Up @@ -91,3 +92,9 @@ fn test_frames() {

assert!(iter.all(|(f, e)| format!("{f:#?}") == *e));
}

#[test]
fn backtrace_unwind_safe() {
fn assert_unwind_safe<T: UnwindSafe + RefUnwindSafe>() {}
assert_unwind_safe::<Backtrace>();
}