From 95351e3efed6d7a192238939dd0a7dec49da69b4 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 1 Nov 2021 22:42:46 -0700 Subject: [PATCH] Refer to format macro by absolute path --- src/lib.rs | 20 ++++++++++++++++++-- src/macros.rs | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index e480714..fc5eac1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -233,7 +233,7 @@ mod alloc { #[cfg(not(feature = "std"))] - extern crate alloc; + pub extern crate alloc; #[cfg(not(feature = "std"))] pub use alloc::boxed::Box; @@ -624,10 +624,17 @@ pub mod private { } #[cfg(anyhow_no_macro_reexport)] - pub use crate::{__anyhow_concat as concat, __anyhow_stringify as stringify}; + pub use crate::{ + __anyhow_concat as concat, __anyhow_format as format, __anyhow_stringify as stringify, + }; #[cfg(not(anyhow_no_macro_reexport))] pub use core::{concat, stringify}; + #[cfg(all(not(anyhow_no_macro_reexport), not(feature = "std")))] + pub use crate::alloc::alloc::format; + #[cfg(all(not(anyhow_no_macro_reexport), feature = "std"))] + pub use std::format; + #[cfg(anyhow_no_macro_reexport)] #[doc(hidden)] #[macro_export] @@ -637,6 +644,15 @@ pub mod private { }; } + #[cfg(anyhow_no_macro_reexport)] + #[doc(hidden)] + #[macro_export] + macro_rules! __anyhow_format { + ($($tt:tt)*) => { + format!($($tt)*) + }; + } + #[cfg(anyhow_no_macro_reexport)] #[doc(hidden)] #[macro_export] diff --git a/src/macros.rs b/src/macros.rs index 038c496..495caa9 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -179,6 +179,6 @@ macro_rules! anyhow { } }); ($fmt:expr, $($arg:tt)*) => { - $crate::Error::msg(format!($fmt, $($arg)*)) + $crate::Error::msg($crate::private::format!($fmt, $($arg)*)) }; }