I use this code and it compiles and runs in debug mode. If thing_initialized is true, it executes. If false, this is gets a runtime error.
fn main() {
#[cfg(debug_assertions)]
let thing_initialized = false;
if cfg!(debug_assertions) {
assert!(thing_initialized);
}
}