diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index c421da067951c..93c585c9b1363 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -544,6 +544,20 @@ pub fn std_macros() -> @str { } ) + // A assert that is only enabled with --cfg debug, but like with + // debug! itself, it still expands to something similar without + // that cfg, to stop the asserts bitrotting. + #[cfg(debug)] + #[macro_escape] + mod debug_assert_macro { + macro_rules! debug_assert { ($($x:expr),*) => { assert!($($x),*) } } + } + #[cfg(not(debug))] + #[macro_escape] + mod debug_assert_macro { + macro_rules! debug_assert { ($($x:expr),*) => { if false { assert!($($x),*) } } } + } + macro_rules! assert_eq ( ($given:expr , $expected:expr) => ( { diff --git a/src/test/run-fail/debug-assert-fail.rs b/src/test/run-fail/debug-assert-fail.rs new file mode 100644 index 0000000000000..c2097423340bb --- /dev/null +++ b/src/test/run-fail/debug-assert-fail.rs @@ -0,0 +1,17 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// xfail-fast compile-flags directive doesn't work for check-fast +// compile-flags: --cfg debug +// error-pattern:assertion failed + +fn main() { + debug_assert!(false); +} diff --git a/src/test/run-pass/debug-assert-pass.rs b/src/test/run-pass/debug-assert-pass.rs new file mode 100644 index 0000000000000..e88d0c6fc45ae --- /dev/null +++ b/src/test/run-pass/debug-assert-pass.rs @@ -0,0 +1,13 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + debug_assert!(false); +}