]> git.lizzy.rs Git - rust.git/commit - src/tools/miri
Rollup merge of #82169 - not-an-aardvark:assert-lazy-format-expressions, r=sfackler
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Wed, 17 Feb 2021 19:38:00 +0000 (20:38 +0100)
committerGitHub <noreply@github.com>
Wed, 17 Feb 2021 19:38:00 +0000 (20:38 +0100)
commit16481a285733f004ab9c5573c1e7fd5b602b3ddd
tree9e71eb79ade91c6e7633b163b389450246a830fd
parent13730e90bde2e55efa31b127e2175d5e90772044
parent15197cbc61450bd19328387ad9a04500e35d7086
Rollup merge of #82169 - not-an-aardvark:assert-lazy-format-expressions, r=sfackler

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.
library/core/src/macros/mod.rs