/// This will invoke the `panic!` macro if the provided expression cannot be
/// evaluated to `true` at runtime.
///
- /// Unlike `assert!`, `debug_assert!` statements can be disabled by passing
- /// `--cfg ndebug` to the compiler. This makes `debug_assert!` useful for
- /// checks that are too expensive to be present in a release build but may be
- /// helpful during development.
+ /// Unlike `assert!`, `debug_assert!` statements are only enabled in non
+ /// optimized builds by default. An optimized build will omit all
+ /// `debug_assert!` statements unless `-C debug-assertions` is passed to the
+ /// compiler. This makes `debug_assert!` useful for checks that are too
+ /// expensive to be present in a release build but may be helpful during
+ /// development.
///
/// # Example
///
#[macro_export]
#[stable(feature = "rust1", since = "1.0.0")]
macro_rules! debug_assert {
- ($($arg:tt)*) => (if cfg!(not(ndebug)) { assert!($($arg)*); })
+ ($($arg:tt)*) => (if cfg!(debug_assertions) { assert!($($arg)*); })
}
/// Asserts that two expressions are equal to each other, testing equality in
///
/// On panic, this macro will print the values of the expressions.
///
- /// Unlike `assert_eq!`, `debug_assert_eq!` statements can be disabled by
- /// passing `--cfg ndebug` to the compiler. This makes `debug_assert_eq!`
- /// useful for checks that are too expensive to be present in a release build
- /// but may be helpful during development.
+ /// Unlike `assert_eq!`, `debug_assert_eq!` statements are only enabled in non
+ /// optimized builds by default. An optimized build will omit all
+ /// `debug_assert_eq!` statements unless `-C debug-assertions` is passed to the
+ /// compiler. This makes `debug_assert_eq!` useful for checks that are too
+ /// expensive to be present in a release build but may be helpful during
+ /// development.
///
/// # Example
///
/// ```
#[macro_export]
macro_rules! debug_assert_eq {
- ($($arg:tt)*) => (if cfg!(not(ndebug)) { assert_eq!($($arg)*); })
+ ($($arg:tt)*) => (if cfg!(debug_assertions) { assert_eq!($($arg)*); })
}
/// Short circuiting evaluation on Err
///
/// ```rust
/// fn divide_by_three(x: u32) -> u32 { // one of the poorest implementations of x/3
-/// for i in std::iter::count(0_u32, 1) {
+/// for i in std::iter::count(0, 1) {
/// if 3*i < i { panic!("u32 overflow"); }
/// if x < 3*i { return i-1; }
/// }
let (is_zero, is_signed) = match rhs_t.sty {
ty::ty_int(t) => {
- let zero = C_integral(Type::int_from_ty(cx.ccx(), t), 0u64, false);
+ let zero = C_integral(Type::int_from_ty(cx.ccx(), t), 0, false);
(ICmp(cx, llvm::IntEQ, rhs, zero, debug_loc), true)
}
ty::ty_uint(t) => {
- let zero = C_integral(Type::uint_from_ty(cx.ccx(), t), 0u64, false);
+ let zero = C_integral(Type::uint_from_ty(cx.ccx(), t), 0, false);
(ICmp(cx, llvm::IntEQ, rhs, zero, debug_loc), false)
}
_ => {
let check_overflow = if let Some(v) = tcx.sess.opts.debugging_opts.force_overflow_checks {
v
} else {
- !attr::contains_name(&krate.config, "ndebug")
+ tcx.sess.opts.debug_assertions
};
// Before we touch LLVM, make sure that multithreading is enabled.