Skip to content

Commit

Permalink
Merge pull request #173 from dtolnay/newadhoc
Browse files Browse the repository at this point in the history
Replace macro-generated calls to new_adhoc with Error::msg public API
  • Loading branch information
dtolnay committed Oct 12, 2021
2 parents 74fd4a2 + ce20d04 commit b5556c9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
11 changes: 0 additions & 11 deletions src/lib.rs
Expand Up @@ -613,9 +613,6 @@ pub trait Context<T, E>: context::private::Sealed {
// Not public API. Referenced by macro-generated code.
#[doc(hidden)]
pub mod private {
use crate::Error;
use core::fmt::{Debug, Display};

pub use core::result::Result::Err;

#[doc(hidden)]
Expand All @@ -626,14 +623,6 @@ pub mod private {
pub use crate::kind::BoxedKind;
}

#[cold]
pub fn new_adhoc<M>(message: M) -> Error
where
M: Display + Debug + Send + Sync + 'static,
{
Error::from_adhoc(message, backtrace!())
}

#[cfg(anyhow_no_macro_reexport)]
pub use crate::{__anyhow_concat as concat, __anyhow_stringify as stringify};
#[cfg(not(anyhow_no_macro_reexport))]
Expand Down
6 changes: 3 additions & 3 deletions src/macros.rs
Expand Up @@ -115,7 +115,7 @@ macro_rules! bail {
macro_rules! ensure {
($cond:expr $(,)?) => {
if !$cond {
return $crate::private::Err($crate::private::new_adhoc(
return $crate::private::Err($crate::Error::msg(
$crate::private::concat!("Condition failed: `", $crate::private::stringify!($cond), "`")
));
}
Expand Down Expand Up @@ -170,7 +170,7 @@ macro_rules! anyhow {
($msg:literal $(,)?) => {
// Handle $:literal as a special case to make cargo-expanded code more
// concise in the common case.
$crate::private::new_adhoc($msg)
$crate::Error::msg($msg)
};
($err:expr $(,)?) => ({
use $crate::private::kind::*;
Expand All @@ -179,6 +179,6 @@ macro_rules! anyhow {
}
});
($fmt:expr, $($arg:tt)*) => {
$crate::private::new_adhoc(format!($fmt, $($arg)*))
$crate::Error::msg(format!($fmt, $($arg)*))
};
}

0 comments on commit b5556c9

Please sign in to comment.