Skip to content

Commit

Permalink
Merge pull request rust-lang#50 from pcwalton/assert
Browse files Browse the repository at this point in the history
Add RFC for disablable assertions
  • Loading branch information
pcwalton committed May 2, 2014
2 parents 8ec267f + c986337 commit 0b35cc0
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions active/0000-assert.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
- Start Date: 2014-04-18
- RFC PR #: (leave this empty)
- Rust Issue #: (leave this empty)

# Summary

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.

# Motivation

Asserts are too expensive in release builds.

# Detailed design

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) }`

# Alternatives

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.

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.

# Unresolved questions

None.

0 comments on commit 0b35cc0

Please sign in to comment.