Skip to content

Commit

Permalink
Merge pull request #185 from dtolnay/fmt
Browse files Browse the repository at this point in the history
Use processed format string even on old rust, but as String
  • Loading branch information
dtolnay authored Nov 4, 2021
2 parents 861c7a4 + d279e40 commit a7f6089
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ pub trait Context<T, E>: context::private::Sealed {
pub mod private {
use crate::Error;
use alloc::fmt;
use core::fmt::{Arguments, Debug, Display};
use core::fmt::Arguments;

pub use alloc::format;
pub use core::result::Result::Err;
Expand All @@ -621,13 +621,11 @@ pub mod private {
}

#[doc(hidden)]
#[inline]
#[cold]
pub fn format_err<M>(_message: M, args: Arguments) -> Error
where
M: Display + Debug + Send + Sync + 'static,
{
pub fn format_err(args: Arguments) -> Error {
#[cfg(anyhow_no_fmt_arguments_as_str)]
let fmt_arguments_as_str = Some(_message);
let fmt_arguments_as_str = None::<&str>;
#[cfg(not(anyhow_no_fmt_arguments_as_str))]
let fmt_arguments_as_str = args.as_str();

Expand Down
2 changes: 1 addition & 1 deletion src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ macro_rules! ensure {
#[macro_export]
macro_rules! anyhow {
($msg:literal $(,)?) => ({
let error = $crate::private::format_err($msg, $crate::private::format_args!($msg));
let error = $crate::private::format_err($crate::private::format_args!($msg));
error
});
($err:expr $(,)?) => ({
Expand Down

0 comments on commit a7f6089

Please sign in to comment.