Skip to main content

debug_assert_ir

Macro debug_assert_ir 

Source
macro_rules! debug_assert_ir {
    ($($tt:tt)*) => { ... };
}
Expand description

Like assert_ir!, but only performs the IR assertion when cfg(debug_assertions) is enabled (i.e. debug builds).

With cfg(debug_assertions) on, this delegates entirely to assert_ir! and supports any number of targets.

With cfg(debug_assertions) off, the predicate is skipped:

  • A single target expression is evaluated and returned as-is (passthru).
  • Multiple target expressions are a compile error — use assert_ir! directly if you need multi-target assertions in release mode.

§Examples

use ir_assert::debug_assert_ir;

fn add(a: u64, b: u64) -> u64 { a + b }

#[test]
fn test_add_optimized_in_debug() {
    // In debug builds this checks IR; in release builds it's a no-op passthru.
    let f = debug_assert_ir!(basic_blocks.len().eq(1) & calls.len().eq(0), add);
    assert_eq!(f(1, 2), 3);
}