Skip to content

Commit 830c399

Browse files
authored
Merge pull request #386 from dtolnay/unwindsafe
Ensure UnwindSafe even with "backtrace" feature enabled and old Rust
2 parents a85e414 + 8454be3 commit 830c399

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

build.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ fn main() {
6868
if rustc >= 80 {
6969
println!("cargo:rustc-check-cfg=cfg(anyhow_nightly_testing)");
7070
println!("cargo:rustc-check-cfg=cfg(anyhow_no_core_error)");
71+
println!("cargo:rustc-check-cfg=cfg(anyhow_no_core_unwind_safe)");
7172
println!("cargo:rustc-check-cfg=cfg(anyhow_no_fmt_arguments_as_str)");
7273
println!("cargo:rustc-check-cfg=cfg(anyhow_no_ptr_addr_of)");
7374
println!("cargo:rustc-check-cfg=cfg(anyhow_no_unsafe_op_in_unsafe_fn_lint)");
@@ -91,6 +92,12 @@ fn main() {
9192
println!("cargo:rustc-cfg=anyhow_no_unsafe_op_in_unsafe_fn_lint");
9293
}
9394

95+
if rustc < 56 {
96+
// core::panic::{UnwindSafe, RefUnwindSafe}
97+
// https://blog.rust-lang.org/2021/10/21/Rust-1.56.0.html#stabilized-apis
98+
println!("cargo:rustc-cfg=anyhow_no_core_unwind_safe");
99+
}
100+
94101
if !error_generic_member_access && cfg!(feature = "std") && rustc >= 65 {
95102
// std::backtrace::Backtrace
96103
// https://blog.rust-lang.org/2022/11/03/Rust-1.65.0.html#stabilized-apis

src/error.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ use core::fmt::{self, Debug, Display};
1212
use core::mem::ManuallyDrop;
1313
#[cfg(any(feature = "std", not(anyhow_no_core_error)))]
1414
use core::ops::{Deref, DerefMut};
15+
#[cfg(not(anyhow_no_core_unwind_safe))]
16+
use core::panic::{RefUnwindSafe, UnwindSafe};
1517
#[cfg(not(anyhow_no_ptr_addr_of))]
1618
use core::ptr;
1719
use core::ptr::NonNull;
20+
#[cfg(all(feature = "std", anyhow_no_core_unwind_safe))]
21+
use std::panic::{RefUnwindSafe, UnwindSafe};
1822

1923
impl Error {
2024
/// Create a new error object from any error type.
@@ -1015,3 +1019,9 @@ impl AsRef<dyn StdError> for Error {
10151019
&**self
10161020
}
10171021
}
1022+
1023+
#[cfg(any(feature = "std", not(anyhow_no_core_unwind_safe)))]
1024+
impl UnwindSafe for Error {}
1025+
1026+
#[cfg(any(feature = "std", not(anyhow_no_core_unwind_safe)))]
1027+
impl RefUnwindSafe for Error {}

0 commit comments

Comments
 (0)