Skip to content

Commit

Permalink
Rename cfg(backtrace) -> cfg(std_backtrace)
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Dec 26, 2023
1 parent cf66194 commit df47705
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn main() {

match compile_probe() {
Some(status) if status.success() => {
println!("cargo:rustc-cfg=backtrace");
println!("cargo:rustc-cfg=std_backtrace");
println!("cargo:rustc-cfg=error_generic_member_access");
}
_ => {}
Expand Down
20 changes: 10 additions & 10 deletions src/backtrace.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
#[cfg(backtrace)]
#[cfg(std_backtrace)]
pub(crate) use std::backtrace::{Backtrace, BacktraceStatus};

#[cfg(all(not(backtrace), feature = "backtrace"))]
#[cfg(all(not(std_backtrace), feature = "backtrace"))]
pub(crate) use self::capture::{Backtrace, BacktraceStatus};

#[cfg(not(any(backtrace, feature = "backtrace")))]
#[cfg(not(any(std_backtrace, feature = "backtrace")))]
pub(crate) enum Backtrace {}

#[cfg(backtrace)]
#[cfg(std_backtrace)]
macro_rules! impl_backtrace {
() => {
std::backtrace::Backtrace
};
}

#[cfg(all(not(backtrace), feature = "backtrace"))]
#[cfg(all(not(std_backtrace), feature = "backtrace"))]
macro_rules! impl_backtrace {
() => {
impl core::fmt::Debug + core::fmt::Display
};
}

#[cfg(any(backtrace, feature = "backtrace"))]
#[cfg(any(std_backtrace, feature = "backtrace"))]
macro_rules! backtrace {
() => {
Some(crate::backtrace::Backtrace::capture())
};
}

#[cfg(not(any(backtrace, feature = "backtrace")))]
#[cfg(not(any(std_backtrace, feature = "backtrace")))]
macro_rules! backtrace {
() => {
None
Expand All @@ -48,22 +48,22 @@ macro_rules! backtrace_if_absent {
#[cfg(all(
feature = "std",
not(error_generic_member_access),
any(backtrace, feature = "backtrace")
any(std_backtrace, feature = "backtrace")
))]
macro_rules! backtrace_if_absent {
($err:expr) => {
backtrace!()
};
}

#[cfg(all(feature = "std", not(backtrace), not(feature = "backtrace")))]
#[cfg(all(feature = "std", not(std_backtrace), not(feature = "backtrace")))]
macro_rules! backtrace_if_absent {
($err:expr) => {
None
};
}

#[cfg(all(not(backtrace), feature = "backtrace"))]
#[cfg(all(not(std_backtrace), feature = "backtrace"))]
mod capture {
use backtrace::{BacktraceFmt, BytesOrWideString, Frame, PrintFmt, SymbolName};
use core::cell::UnsafeCell;
Expand Down
22 changes: 11 additions & 11 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl Error {
object_drop_rest: object_drop_front::<E>,
#[cfg(all(
not(error_generic_member_access),
any(backtrace, feature = "backtrace")
any(std_backtrace, feature = "backtrace")
))]
object_backtrace: no_backtrace,
};
Expand Down Expand Up @@ -129,7 +129,7 @@ impl Error {
object_drop_rest: object_drop_front::<M>,
#[cfg(all(
not(error_generic_member_access),
any(backtrace, feature = "backtrace")
any(std_backtrace, feature = "backtrace")
))]
object_backtrace: no_backtrace,
};
Expand Down Expand Up @@ -158,7 +158,7 @@ impl Error {
object_drop_rest: object_drop_front::<M>,
#[cfg(all(
not(error_generic_member_access),
any(backtrace, feature = "backtrace")
any(std_backtrace, feature = "backtrace")
))]
object_backtrace: no_backtrace,
};
Expand Down Expand Up @@ -189,7 +189,7 @@ impl Error {
object_drop_rest: context_drop_rest::<C, E>,
#[cfg(all(
not(error_generic_member_access),
any(backtrace, feature = "backtrace")
any(std_backtrace, feature = "backtrace")
))]
object_backtrace: no_backtrace,
};
Expand Down Expand Up @@ -218,7 +218,7 @@ impl Error {
object_drop_rest: object_drop_front::<Box<dyn StdError + Send + Sync>>,
#[cfg(all(
not(error_generic_member_access),
any(backtrace, feature = "backtrace")
any(std_backtrace, feature = "backtrace")
))]
object_backtrace: no_backtrace,
};
Expand Down Expand Up @@ -334,7 +334,7 @@ impl Error {
object_drop_rest: context_chain_drop_rest::<C>,
#[cfg(all(
not(error_generic_member_access),
any(backtrace, feature = "backtrace")
any(std_backtrace, feature = "backtrace")
))]
object_backtrace: context_backtrace::<C>,
};
Expand Down Expand Up @@ -376,7 +376,7 @@ impl Error {
/// ```
///
/// [tracking]: https://github.com/rust-lang/rust/issues/53487
#[cfg(any(backtrace, feature = "backtrace"))]
#[cfg(any(std_backtrace, feature = "backtrace"))]
#[cfg_attr(doc_cfg, doc(cfg(any(nightly, feature = "backtrace"))))]
pub fn backtrace(&self) -> &impl_backtrace!() {
unsafe { ErrorImpl::backtrace(self.inner.by_ref()) }
Expand Down Expand Up @@ -622,7 +622,7 @@ struct ErrorVTable {
object_drop_rest: unsafe fn(Own<ErrorImpl>, TypeId),
#[cfg(all(
not(error_generic_member_access),
any(backtrace, feature = "backtrace")
any(std_backtrace, feature = "backtrace")
))]
object_backtrace: unsafe fn(Ref<ErrorImpl>) -> Option<&Backtrace>,
}
Expand Down Expand Up @@ -730,7 +730,7 @@ where

#[cfg(all(
not(error_generic_member_access),
any(backtrace, feature = "backtrace")
any(std_backtrace, feature = "backtrace")
))]
fn no_backtrace(e: Ref<ErrorImpl>) -> Option<&Backtrace> {
let _ = e;
Expand Down Expand Up @@ -854,7 +854,7 @@ where
// Safety: requires layout of *e to match ErrorImpl<ContextError<C, Error>>.
#[cfg(all(
not(error_generic_member_access),
any(backtrace, feature = "backtrace")
any(std_backtrace, feature = "backtrace")
))]
#[allow(clippy::unnecessary_wraps)]
unsafe fn context_backtrace<C>(e: Ref<ErrorImpl>) -> Option<&Backtrace>
Expand Down Expand Up @@ -926,7 +926,7 @@ impl ErrorImpl {
return unsafe { (vtable(this.ptr).object_mut)(this) };
}

#[cfg(any(backtrace, feature = "backtrace"))]
#[cfg(any(std_backtrace, feature = "backtrace"))]
pub(crate) unsafe fn backtrace(this: Ref<Self>) -> &Backtrace {
// This unwrap can only panic if the underlying error's backtrace method
// is nondeterministic, which would only happen in maliciously
Expand Down
2 changes: 1 addition & 1 deletion src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl ErrorImpl {
}
}

#[cfg(any(backtrace, feature = "backtrace"))]
#[cfg(any(std_backtrace, feature = "backtrace"))]
{
use crate::backtrace::BacktraceStatus;

Expand Down
2 changes: 1 addition & 1 deletion tests/test_fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fn test_altdisplay() {
}

#[test]
#[cfg_attr(not(backtrace), ignore)]
#[cfg_attr(not(std_backtrace), ignore)]
fn test_debug() {
assert_eq!(EXPECTED_DEBUG_F, format!("{:?}", f().unwrap_err()));
assert_eq!(EXPECTED_DEBUG_G, format!("{:?}", g().unwrap_err()));
Expand Down

0 comments on commit df47705

Please sign in to comment.