Skip to content
Myr

Recognize literal anyhow as a special case

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

authored by David Tolnay · committed by David Tolnay · parent 443cc8d · Browse files · 1 file+15 added−2 removed
This commit

State

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

Diff stats

1 file+15 added−2 removed

  • other:+15 added−2 removed

1 file+15 added−2 removed

modified:src/lib.rs+15 added-2 removed
283 unmodified lines
284/// # }285/// ```286#[macro_export]287macro_rules! bail {288 ($msg:literal $(,)?) => {289 return std::result::Result::Err($crate::anyhow!($msg));290 };291 ($err:expr $(,)?) => {292 return std::result::Result::Err($crate::anyhow!($err));293 };294 ($fmt:expr, $($arg:tt)*) => {
58 unmodified lines
353/// # }354/// ```355#[macro_export]356macro_rules! ensure {357 ($cond:expr, $msg:literal $(,)?) => {358 if !$cond {359 return std::result::Result::Err($crate::anyhow!($msg));360 }361 };362 ($cond:expr, $err:expr $(,)?) => {363 if !$cond {364 return std::result::Result::Err($crate::anyhow!($err));365 }
28 unmodified lines
394/// }395/// ```396#[macro_export]397macro_rules! anyhow {398 ($msg:literal $(,)?) => {399 // Handle $:literal as a special case to make cargo-expanded code more400 // concise in the common case.401 $crate::private::new_adhoc($msg)402 };390 ($msg:expr $(,)?) => ({403 ($err:expr $(,)?) => ({404 #[allow(unused_imports)]405 use $crate::private::{AdhocKind, TraitKind};393 let error = $msg;406 let error = $err;407 error.anyhow_kind().new(error)408 });409 ($fmt:expr, $($arg:tt)*) => {410 $crate::private::new_adhoc(format!($fmt, $($arg)*))
21 unmodified lines