ice_code/
lib.rs

1#[macro_export]
2macro_rules! ice {
3    // If the invocation includes a label...
4    ($label:ident => $expr:expr) => {{
5        // ...define a named function whose definition will never be inlined...
6        #[cold]
7        #[inline(never)]
8        fn $label<T, F: FnOnce() -> T>(f: F) -> T {
9            f()
10        }
11        // ...and then wrap our `expr` in a closure and pass it to the function.
12        $label(|| $expr)
13    }};
14    // If no label is specified, just define a closure to do the same thing.
15    ($expr:expr) => {{
16        // Closures that are passed in argument position are allowed to have annotations for
17        // obscure historical reasons.
18        let mut closure = core::convert::identity(
19            #[cold]
20            #[inline(never)]
21            || $expr,
22        );
23        closure()
24    }};
25}