Document that assert!
format arguments are evaluated lazily
It can be useful to do some computation in `assert!` format arguments, in order to get better error messages. For example: ```rust assert!( some_condition, "The state is invalid. Details: {}", expensive_call_to_get_debugging_info(), ); ``` It seems like `assert!` only evaluates the format arguments if the assertion fails, which is useful but doesn't appear to be documented anywhere. This PR documents the behavior and adds some tests.
This commit is contained in:
parent
d1206f950f
commit
cb653b100c
2 changed files with 13 additions and 1 deletions
|
@ -1208,7 +1208,8 @@ pub(crate) mod builtin {
|
|||
///
|
||||
/// This macro has a second form, where a custom panic message can
|
||||
/// be provided with or without arguments for formatting. See [`std::fmt`]
|
||||
/// for syntax for this form.
|
||||
/// for syntax for this form. Expressions used as format arguments will only
|
||||
/// be evaluated if the assertion fails.
|
||||
///
|
||||
/// [`std::fmt`]: ../std/fmt/index.html
|
||||
///
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue