Skip to content

Commit 0580a69

Browse files
committed
Add RFC for disablable assertions
1 parent 711f533 commit 0580a69

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

active/0000-assert.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
- Start Date: 2014-04-18
2+
- RFC PR #: (leave this empty)
3+
- Rust Issue #: (leave this empty)
4+
5+
# Summary
6+
7+
Asserts are too expensive for release builds and mess up inlining. There must be a way to turn them off. I propose macros `assert!` and `enforce!`. For test cases, `enforce!` should be used.
8+
9+
# Motivation
10+
11+
Asserts are too expensive in release builds.
12+
13+
# Detailed design
14+
15+
There should be two macros, `assert!(EXPR)` and `enforce!(EXPR)`. In debug builds (without `--cfg ndebug`), `assert!()` is the same as `enforce!()`. In release builds (with `--cfg ndebug`), `assert!()` compiles away to nothing. The definition of `enforce!()` is `if (!EXPR) { fail!("assertion failed ({}, {}): {}", file!(), line!(), stringify!(expr) }`
16+
17+
# Alternatives
18+
19+
Other designs that have been considered are using `assert!` in test cases and not providing `enforce!`, but this doesn't work with separate compilation.
20+
21+
There has been an issue raised that `enforce!` is unintuitive for test cases, but I think all workarounds for this are worse because they add complexity.
22+
23+
The impact of not doing this is that `assert!` will become expensive, prompting people will write their own local `assert!` macros, duplicating functionality that should have been in the standard library.
24+
25+
# Unresolved questions
26+
27+
None.

0 commit comments

Comments
 (0)