Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace macro-generated calls to new_adhoc with Error::msg public API #173

Merged
merged 1 commit into from Oct 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)*))
};
}