about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2016-07-29 11:57:54 +0200
committerGitHub <noreply@github.com>2016-07-29 11:57:54 +0200
commit3f06bf9afbf87ef4dca7ac09e438b67f5fa622af (patch)
tree0fde9b3aeb556e399a7a567ab5ef140c17ace6d6 /src
parent01505a3311005fff8e3ef71e2cf4753ecbe31088 (diff)
parent9a7367b96035ab1ff7593f929c852181de1bcbfb (diff)
downloadrust-3f06bf9afbf87ef4dca7ac09e438b67f5fa622af.tar.gz
rust-3f06bf9afbf87ef4dca7ac09e438b67f5fa622af.zip
Rollup merge of #35072 - munyari:assert_debug, r=steveklabnik
Update docs for assert! and debug_assert!

Refer to #34455
Diffstat (limited to 'src')
-rw-r--r--src/libcore/macros.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs
index 43868d124a2..b0c79a3a885 100644
--- a/src/libcore/macros.rs
+++ b/src/libcore/macros.rs
@@ -35,6 +35,17 @@ macro_rules! panic {
 /// This will invoke the `panic!` macro if the provided expression cannot be
 /// evaluated to `true` at runtime.
 ///
+/// Assertions are always checked in both debug and release builds, and cannot
+/// be disabled. See `debug_assert!` for assertions that are not enabled in
+/// release builds by default.
+///
+/// Unsafe code relies on `assert!` to enforce run-time invariants that, if
+/// violated could lead to unsafety.
+///
+/// Other use-cases of `assert!` include
+/// [testing](https://doc.rust-lang.org/book/testing.html) and enforcing
+/// run-time invariants in safe code (whose violation cannot result in unsafety).
+///
 /// This macro has a second version, where a custom panic message can be provided.
 ///
 /// # Examples
@@ -123,6 +134,13 @@ macro_rules! assert_eq {
 /// expensive to be present in a release build but may be helpful during
 /// development.
 ///
+/// An unchecked assertion allows a program in an inconsistent state to keep
+/// running, which might have unexpected consequences but does not introduce
+/// unsafety as long as this only happens in safe code. The performance cost
+/// of assertions, is however, not measurable in general. Replacing `assert!`
+/// with `debug_assert!` is thus only encouraged after thorough profiling, and
+/// more importantly, only in safe code!
+///
 /// # Examples
 ///
 /// ```