diff --git a/src/chain.rs b/src/chain.rs index 19d8b72..b75885d 100644 --- a/src/chain.rs +++ b/src/chain.rs @@ -2,7 +2,7 @@ use self::ChainState::*; use crate::StdError; #[cfg(feature = "std")] -use alloc::vec; +use alloc::vec::{self, Vec}; #[cfg(feature = "std")] pub(crate) use crate::Chain; diff --git a/src/fmt.rs b/src/fmt.rs index a99649b..85c84a9 100644 --- a/src/fmt.rs +++ b/src/fmt.rs @@ -43,6 +43,7 @@ impl ErrorImpl { #[cfg(any(std_backtrace, feature = "backtrace"))] { use crate::backtrace::BacktraceStatus; + use alloc::string::ToString; let backtrace = unsafe { Self::backtrace(this) }; if let BacktraceStatus::Captured = backtrace.status() { @@ -102,6 +103,7 @@ where #[cfg(test)] mod tests { use super::*; + use alloc::string::String; #[test] fn one_digit() { diff --git a/src/kind.rs b/src/kind.rs index 21d76aa..15d9f9b 100644 --- a/src/kind.rs +++ b/src/kind.rs @@ -49,6 +49,8 @@ use core::fmt::{Debug, Display}; #[cfg(feature = "std")] use crate::StdError; +#[cfg(feature = "std")] +use alloc::boxed::Box; pub struct Adhoc; diff --git a/src/lib.rs b/src/lib.rs index 62ee88d..be60401 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -209,7 +209,7 @@ #![doc(html_root_url = "https://docs.rs/anyhow/1.0.79")] #![cfg_attr(error_generic_member_access, feature(error_generic_member_access))] #![cfg_attr(doc_cfg, feature(doc_cfg))] -#![cfg_attr(not(feature = "std"), no_std)] +#![no_std] #![deny(dead_code, unused_imports, unused_mut)] #![cfg_attr( not(anyhow_no_unsafe_op_in_unsafe_fn_lint), @@ -247,6 +247,9 @@ compile_error!("Build script probe failed to compile."); extern crate alloc; +#[cfg(feature = "std")] +extern crate std; + #[macro_use] mod backtrace; mod chain; diff --git a/src/wrapper.rs b/src/wrapper.rs index 0eb5478..9726ae5 100644 --- a/src/wrapper.rs +++ b/src/wrapper.rs @@ -1,6 +1,9 @@ use crate::StdError; use core::fmt::{self, Debug, Display}; +#[cfg(feature = "std")] +use alloc::boxed::Box; + #[cfg(error_generic_member_access)] use std::error::Request; diff --git a/tests/test_repr.rs b/tests/test_repr.rs index 065041c..2976cd8 100644 --- a/tests/test_repr.rs +++ b/tests/test_repr.rs @@ -4,7 +4,6 @@ mod drop; use self::drop::{DetectDrop, Flag}; use anyhow::Error; -use std::marker::Unpin; use std::mem; #[test]