Skip to content

Commit e1ecb2b

Browse files
committed
SQUASHME: Fix up debug module
* Fix typos in `trace!` and `check!` macros that caused syntax errors * Rename `trace!` to `fail!` to avoid name conflict with existing `log::trace` function. * Guard `Display` implementation of `manticore::Error` with the `log` feature Signed-off-by: Kesavan Yogeswaran <[email protected]>
1 parent deb1e25 commit e1ecb2b

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/debug.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ impl<E> AsMut<E> for Error<E> {
6969
}
7070
}
7171

72+
#[cfg(feature = "log")]
7273
impl<E: fmt::Display> fmt::Display for Error<E> {
7374
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7475
struct DisplayAsDebug<'a, E>(&'a E);
@@ -118,30 +119,31 @@ macro_rules! check {
118119
($cond:expr, $error:expr) => {
119120
if !$cond {
120121
let error = $error;
121-
trace!(
122+
fail!(
123+
error,
124+
"check failure: `{}`; returned {:?}",
125+
stringify!($cond),
122126
error,
123-
"check failure: `{}`; returned {:?}"
124-
stringify!($cond), error,
125127
)?;
126128
}
127-
}
129+
};
128130
}
129131

130132
/// Logs a newly-created error value and returns it.
131133
///
132134
/// This macro is the main way to generate [`Error`] values.
133135
///
134136
/// For example, instead of writing `foo.ok_or(MyError)`, instead write
135-
/// `foo.ok_or_else(|| trace!(MyError))`.
136-
macro_rules! trace {
137+
/// `foo.ok_or_else(|| fail!(MyError))`.
138+
macro_rules! fail {
137139
($error:expr, $($format:tt)+) => {{
138140
error!($($format)+);
139-
$crate::debug::Error::__new($error)
141+
Err($crate::debug::Error::__new($error))
140142
}};
141143
($error:expr) => {{
142144
let error = $error;
143145
error!("generated error: `{:?}`", error);
144-
$crate::debug::Error::__new(error)
146+
Err($crate::debug::Error::__new(error))
145147
}};
146148
}
147149

0 commit comments

Comments
 (0)