Debug_assert! type check

I can't find useful information what this:

The result of expanding debug_assert! is always type checked.

means. (source)

As I understand, macro expansion is a process of conversion macro code into actual Rust code.
I looked into the source code of this macro and it just checks if executes as debug build and then calls assert! macro, but unfortunately I can't see any more useful information in this macro's docs, too.

It means that, if debug assertions are disabled, the code in debug_assert! is still checked in all the ways it would normally be, even though it won't be run.

That is, debug_assert!(foo()) is not equivalent to

#[cfg(debug_assertions)]
assert!(foo());

which would remove the call to foo() entirely and allow the program to compile even if foo() wasn't a defined function.

6 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.