From 3e70139e077324d4109cb6baf71c06ed8369fbd0 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 6 Sep 2024 12:00:20 -0700 Subject: [PATCH] Access generic_member_access APIs through core --- build/probe.rs | 4 ++-- src/backtrace.rs | 3 ++- src/context.rs | 2 +- src/error.rs | 4 ++-- src/wrapper.rs | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/build/probe.rs b/build/probe.rs index 21e776d..742d15c 100644 --- a/build/probe.rs +++ b/build/probe.rs @@ -4,9 +4,9 @@ #![feature(error_generic_member_access)] +use core::error::{self, Error, Request}; +use core::fmt::{self, Debug, Display}; use std::backtrace::Backtrace; -use std::error::{self, Error, Request}; -use std::fmt::{self, Debug, Display}; struct MyError(Thing); struct Thing; diff --git a/src/backtrace.rs b/src/backtrace.rs index 44fb66c..fc5c072 100644 --- a/src/backtrace.rs +++ b/src/backtrace.rs @@ -38,7 +38,8 @@ macro_rules! backtrace { #[cfg(error_generic_member_access)] macro_rules! backtrace_if_absent { ($err:expr) => { - match std::error::request_ref::($err as &dyn std::error::Error) { + match core::error::request_ref::($err as &dyn core::error::Error) + { Some(_) => None, None => backtrace!(), } diff --git a/src/context.rs b/src/context.rs index 11b31ba..d8c6273 100644 --- a/src/context.rs +++ b/src/context.rs @@ -4,7 +4,7 @@ use core::convert::Infallible; use core::fmt::{self, Debug, Display, Write}; #[cfg(error_generic_member_access)] -use std::error::Request; +use core::error::Request; mod ext { use super::*; diff --git a/src/error.rs b/src/error.rs index a5e7f6e..16ad92d 100644 --- a/src/error.rs +++ b/src/error.rs @@ -6,13 +6,13 @@ use crate::ptr::{Own, Ref}; use crate::{Error, StdError}; use alloc::boxed::Box; use core::any::TypeId; +#[cfg(error_generic_member_access)] +use core::error::{self, Request}; use core::fmt::{self, Debug, Display}; use core::mem::ManuallyDrop; #[cfg(not(anyhow_no_ptr_addr_of))] use core::ptr; use core::ptr::NonNull; -#[cfg(error_generic_member_access)] -use std::error::{self, Request}; #[cfg(feature = "std")] use core::ops::{Deref, DerefMut}; diff --git a/src/wrapper.rs b/src/wrapper.rs index 9726ae5..6639c50 100644 --- a/src/wrapper.rs +++ b/src/wrapper.rs @@ -5,7 +5,7 @@ use core::fmt::{self, Debug, Display}; use alloc::boxed::Box; #[cfg(error_generic_member_access)] -use std::error::Request; +use core::error::Request; #[repr(transparent)] pub struct MessageError(pub M);