diff options
author | Martin Fischer <martin@push-f.com> | 2023-09-10 09:02:38 +0200 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2023-09-28 10:36:08 +0200 |
commit | 3bcbdbae41c67dd41333097cd405dcdc26fce67f (patch) | |
tree | 330d26df6ad36772b36cbc356c0ea1a925b19b5d /src/let_else.rs | |
parent | 36ef13e79a08a6799b68e1942a799ec3f8bd52c8 (diff) |
refactor: clean up DefaultEmitter code
Diffstat (limited to 'src/let_else.rs')
-rw-r--r-- | src/let_else.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/let_else.rs b/src/let_else.rs new file mode 100644 index 0000000..da17a68 --- /dev/null +++ b/src/let_else.rs @@ -0,0 +1,23 @@ +/// Binds the given expression to the given pattern, or else executes +/// `debug_assert!(false);` with a helpful panic message and returns. +macro_rules! assume { + ($pattern:pat, $value:expr) => { + // The expression might change each time it's evaluated, so we + // have to bind it so that we can reuse it in the panic message. + let _value = $value; + + let $pattern = _value else { + debug_assert!( + false, + "assertion `left matches right` failed: + left: {} +right: {:?}", + stringify!($pattern), + _value + ); + return; + }; + }; +} + +pub(crate) use assume; |