Skip to content

Commit 0b35cc0

Browse files
committed
Merge pull request rust-lang#50 from pcwalton/assert
Add RFC for disablable assertions
2 parents 8ec267f + c986337 commit 0b35cc0

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

active/0000-assert.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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 `debug_assert!` and `assert!`. For test cases, `assert!` 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, `debug_assert!(EXPR)` and `assert!(EXPR)`. In debug builds (without `--cfg ndebug`), `debug_assert!()` is the same as `assert!()`. In release builds (with `--cfg ndebug`), `debug_assert!()` compiles away to nothing. The definition of `assert!()` is `if (!EXPR) { fail!("assertion failed ({}, {}): {}", file!(), line!(), stringify!(expr) }`
16+
17+
# Alternatives
18+
19+
Other designs that have been considered are using `debug_assert!` in test cases and not providing `assert!`, but this doesn't work with separate compilation.
20+
21+
The impact of not doing this is that `assert!` will be expensive, prompting people will write their own local `debug_assert!` macros, duplicating functionality that should have been in the standard library.
22+
23+
# Unresolved questions
24+
25+
None.

0 commit comments

Comments
 (0)