blob: a1627f1b53ccd6fad20470fcde03e1a12892b2a9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
/// 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;
/// Binds the given expression to the given pattern, or else executes
/// `unreachable!();` with a helpful panic message and returns.
macro_rules! know {
($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 {
unreachable!(
"assertion `left matches right` failed:
left: {}
right: {:?}",
stringify!($pattern),
_value
);
};
};
}
pub(crate) use know;
|