From 32d84dcbacf607d7c6e1050b54d585622c8de4fc Mon Sep 17 00:00:00 2001 From: Jane Losare-Lusby Date: Wed, 13 Dec 2023 13:37:26 -0800 Subject: [PATCH] Revert "Automatically convert to external errors w/ ensure! and bail!" (#133) Reverts eyre-rs/eyre#95 --- eyre/src/macros.rs | 12 ++++++------ eyre/tests/test_macros.rs | 21 +-------------------- 2 files changed, 7 insertions(+), 26 deletions(-) diff --git a/eyre/src/macros.rs b/eyre/src/macros.rs index 4820b28..032f82a 100644 --- a/eyre/src/macros.rs +++ b/eyre/src/macros.rs @@ -51,13 +51,13 @@ #[macro_export] macro_rules! bail { ($msg:literal $(,)?) => { - return $crate::private::Err($crate::eyre!($msg).into()); + return $crate::private::Err($crate::eyre!($msg)); }; ($err:expr $(,)?) => { - return $crate::private::Err($crate::eyre!($err).into()); + return $crate::private::Err($crate::eyre!($err)); }; ($fmt:expr, $($arg:tt)*) => { - return $crate::private::Err($crate::eyre!($fmt, $($arg)*).into()); + return $crate::private::Err($crate::eyre!($fmt, $($arg)*)); }; } @@ -114,17 +114,17 @@ macro_rules! ensure { }; ($cond:expr, $msg:literal $(,)?) => { if !$cond { - return $crate::private::Err($crate::eyre!($msg).into()); + return $crate::private::Err($crate::eyre!($msg)); } }; ($cond:expr, $err:expr $(,)?) => { if !$cond { - return $crate::private::Err($crate::eyre!($err).into()); + return $crate::private::Err($crate::eyre!($err)); } }; ($cond:expr, $fmt:expr, $($arg:tt)*) => { if !$cond { - return $crate::private::Err($crate::eyre!($fmt, $($arg)*).into()); + return $crate::private::Err($crate::eyre!($fmt, $($arg)*)); } }; } diff --git a/eyre/tests/test_macros.rs b/eyre/tests/test_macros.rs index 9fddd8a..41d3ddb 100644 --- a/eyre/tests/test_macros.rs +++ b/eyre/tests/test_macros.rs @@ -40,8 +40,7 @@ fn test_ensure() { }; assert!(f().is_err()); - // Tests single-argument `ensure!` - let f = || -> Result<()> { + let f = || { ensure!(v + v == 1); Ok(()) }; @@ -49,24 +48,6 @@ fn test_ensure() { f().unwrap_err().to_string(), "Condition failed: `v + v == 1`", ); - - // Tests automatically converting to external errors with ensure!() - let f = || -> Result<(), SomeWrappingErr> { - ensure!(false, "this will fail"); - Ok(()) - }; - assert!(f().is_err()); -} - -#[allow(dead_code)] -struct SomeWrappingErr { - err: eyre::Error, -} - -impl From for SomeWrappingErr { - fn from(err: eyre::Error) -> Self { - SomeWrappingErr { err } - } } #[test]