Will this get optimized away during [release] mode?

debug_assert!(self.store.insert(id, PacketRouteSubstore { exp, no_exp }).is_none());

To play it safe, I could just do:

let res = self.store.insert(id, PacketRouteSubstore { exp, no_exp }).is_none();
debug_assert!(res);

However, the first snippet of code looks nicer. Unfortunately, i do not know if it will get omitted during release mode. Don't all debug_asserts! get ignored for release mode?

https://doc.rust-lang.org/stable/src/core/macros.rs.html#183-185

#[macro_export]
#[stable(feature = "rust1", since = "1.0.0")]
macro_rules! debug_assert {
    ($($arg:tt)*) => (if cfg!(debug_assertions) { assert!($($arg)*); })
}

Compiler will happily optimize out the if false {...} block.

1 Like

Oh, everything disappears then

So snippet 2 is what I should aim for then

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.