Skip to content
Myr

Merge pull request #173 from dtolnay/newadhoc

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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

authored by David Tolnay · committed by GitHub · parents 74fd4a2, ce20d04 · Browse files · 2 files+3 added−14 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+3 added−14 removed

  • other:+3 added−14 removed

2 files+3 added−14 removed

modified:src/lib.rs-11 removed
611 unmodified lines
612613// Not public API. Referenced by macro-generated code.614#[doc(hidden)]615pub mod private {616 use crate::Error;617 use core::fmt::{Debug, Display};618616 pub use core::result::Result::Err;617618 #[doc(hidden)]619 pub mod kind {
2 unmodified lines
622 #[cfg(feature = "std")]623 pub use crate::kind::BoxedKind;624 }625629 #[cold]630 pub fn new_adhoc<M>(message: M) -> Error631 where632 M: Display + Debug + Send + Sync + 'static,633 {634 Error::from_adhoc(message, backtrace!())635 }636626 #[cfg(anyhow_no_macro_reexport)]627 pub use crate::{__anyhow_concat as concat, __anyhow_stringify as stringify};628 #[cfg(not(anyhow_no_macro_reexport))]629 pub use core::{concat, stringify};
19 unmodified lines
modified:src/macros.rs+3 added-3 removed
113 unmodified lines
114#[macro_export]115macro_rules! ensure {116 ($cond:expr $(,)?) => {117 if !$cond {118 return $crate::private::Err($crate::private::new_adhoc(118 return $crate::private::Err($crate::Error::msg(119 $crate::private::concat!("Condition failed: `", $crate::private::stringify!($cond), "`")120 ));121 }122 };
46 unmodified lines
169macro_rules! anyhow {170 ($msg:literal $(,)?) => {171 // Handle $:literal as a special case to make cargo-expanded code more172 // concise in the common case.173 $crate::private::new_adhoc($msg)173 $crate::Error::msg($msg)174 };175 ($err:expr $(,)?) => ({176 use $crate::private::kind::*;177 match $err {178 error => (&error).anyhow_kind().new(error),179 }180 });181 ($fmt:expr, $($arg:tt)*) => {182 $crate::private::new_adhoc(format!($fmt, $($arg)*))182 $crate::Error::msg(format!($fmt, $($arg)*))183 };184}