Simplify handling of trailing commas

This commit is contained in:
David Tolnay 2019-10-06 12:59:11 -04:00
parent efce155177
commit 17cd390308
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -190,12 +190,9 @@ pub type Result<T> = std::result::Result<T, Error>;
/// This macro is equivalent to `return Err(From::from($err))`.
#[macro_export]
macro_rules! bail {
($err:expr) => {
($err:expr $(,)?) => {
return std::result::Result::Err(std::convert::From::from($err));
};
($err:expr,) => {
$crate::bail!($err);
};
}
/// Construct an ad-hoc error from a string.
@ -205,12 +202,9 @@ macro_rules! bail {
/// `Debug` and `Display`.
#[macro_export]
macro_rules! anyhow {
($msg:expr) => {
($msg:expr $(,)?) => {
$crate::private::new_adhoc($msg)
};
($msg:expr,) => {
$crate::anyhow!($msg)
};
($fmt:expr, $($arg:tt)*) => {
$crate::private::new_adhoc(format!($fmt, $($arg)*))
};