Remove must_use call from ensure! and bail! expansions
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 ffa919c · Browse files · 2 files·+34 added−12 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+34 added−12 removed
- other:+34 added−12 removed
Provenance
- Commit
573689b- Tree
34657a8- Author
David Tolnay <dtolnay@gmail.com>- Committer
David Tolnay <dtolnay@gmail.com>- Parent
ffa919c
2 files changed+34 added−12 removed
modified:src/ensure.rs+3 added-3 removed
816 unmodified lines817 }818 };819 ($cond:expr, $msg:literal $(,)?) => {820 if !$cond {821- return $crate::private::Err($crate::anyhow!($msg));821+ return $crate::private::Err($crate::__anyhow!($msg));822 }823 };824 ($cond:expr, $err:expr $(,)?) => {825 if !$cond {826- return $crate::private::Err($crate::anyhow!($err));826+ return $crate::private::Err($crate::__anyhow!($err));827 }828 };829 ($cond:expr, $fmt:expr, $($arg:tt)*) => {830 if !$cond {831- return $crate::private::Err($crate::anyhow!($fmt, $($arg)*));831+ return $crate::private::Err($crate::__anyhow!($fmt, $($arg)*));832 }833 };834 }modified:src/macros.rs+31 added-9 removed
52 unmodified lines53 #[cfg(doc)]54 #[macro_export]55 macro_rules! bail {56 ($msg:literal $(,)?) => {57- return $crate::private::Err($crate::anyhow!($msg))57+ return $crate::private::Err($crate::__anyhow!($msg))58 };59 ($err:expr $(,)?) => {60- return $crate::private::Err($crate::anyhow!($err))60+ return $crate::private::Err($crate::__anyhow!($err))61 };62 ($fmt:expr, $($arg:tt)*) => {63- return $crate::private::Err($crate::anyhow!($fmt, $($arg)*))63+ return $crate::private::Err($crate::__anyhow!($fmt, $($arg)*))64 };65 }66 67 // Workaround for crates that intentionally contained `{}` in an error message6 unmodified lines74 ("pattern does not contain `{}`") => {75 return $crate::private::Err($crate::Error::msg("pattern does not contain `{}`"))76 };77 ($msg:literal $(,)?) => {78- return $crate::private::Err($crate::anyhow!($msg))78+ return $crate::private::Err($crate::__anyhow!($msg))79 };80 ($err:expr $(,)?) => {81- return $crate::private::Err($crate::anyhow!($err))81+ return $crate::private::Err($crate::__anyhow!($err))82 };83 ($fmt:expr, $($arg:tt)*) => {84- return $crate::private::Err($crate::anyhow!($fmt, $($arg)*))84+ return $crate::private::Err($crate::__anyhow!($fmt, $($arg)*))85 };86 }87 88 /// Return early with an error if a condition is not satisfied.55 unmodified lines144 }145 };146 ($cond:expr, $msg:literal $(,)?) => {147 if !$cond {148- return $crate::private::Err($crate::anyhow!($msg));148+ return $crate::private::Err($crate::__anyhow!($msg));149 }150 };151 ($cond:expr, $err:expr $(,)?) => {152 if !$cond {153- return $crate::private::Err($crate::anyhow!($err));153+ return $crate::private::Err($crate::__anyhow!($err));154 }155 };156 ($cond:expr, $fmt:expr, $($arg:tt)*) => {157 if !$cond {158- return $crate::private::Err($crate::anyhow!($fmt, $($arg)*));158+ return $crate::private::Err($crate::__anyhow!($fmt, $($arg)*));159 }160 };161 }162 61 unmodified lines224 ($fmt:expr, $($arg:tt)*) => {225 $crate::Error::msg($crate::private::format!($fmt, $($arg)*))226 };227 }228+229+// Not public API. This is used in the implementation of some of the other230+// macros, in which the must_use call is not needed because the value is known231+// to be used.232+#[doc(hidden)]233+#[macro_export]234+macro_rules! __anyhow {235+ ($msg:literal $(,)?) => ({236+ let error = $crate::private::format_err($crate::private::format_args!($msg));237+ error238+ });239+ ($err:expr $(,)?) => ({240+ use $crate::private::kind::*;241+ let error = match $err {242+ error => (&error).anyhow_kind().new(error),243+ };244+ error245+ });246+ ($fmt:expr, $($arg:tt)*) => {247+ $crate::Error::msg($crate::private::format!($fmt, $($arg)*))248+ };249+}