Skip to content

Commit

Permalink
Add RFC for disablable assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
pcwalton committed Apr 18, 2014
1 parent 711f533 commit 0580a69
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions active/0000-assert.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
- 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 `assert!` and `enforce!`. For test cases, `enforce!` should be used.

# Motivation

Asserts are too expensive in release builds.

# Detailed design

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

# Alternatives

Other designs that have been considered are using `assert!` in test cases and not providing `enforce!`, but this doesn't work with separate compilation.

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.

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.

# Unresolved questions

None.

0 comments on commit 0580a69

Please sign in to comment.