From 14df8447445440794d363f6dc3fbb5220bb0a775 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 19 Mar 2013 14:05:20 -0400 Subject: [PATCH] Allow custom messages on assert statements --- src/libsyntax/ext/expand.rs | 5 +++++ src/test/run-fail/issue-2761.rs | 15 +++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/test/run-fail/issue-2761.rs diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index ec693fa1f08..ad05e2f21e6 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -456,6 +456,11 @@ pub fn core_macros() -> ~str { if !$cond { ::core::sys::fail_assert(stringify!($cond), file!(), line!()) } + }; + ($cond:expr, $msg:expr) => { + if !$cond { + ::core::sys::fail_assert($msg, file!(), line!()) + } } ) diff --git a/src/test/run-fail/issue-2761.rs b/src/test/run-fail/issue-2761.rs new file mode 100644 index 00000000000..cf35d9624f3 --- /dev/null +++ b/src/test/run-fail/issue-2761.rs @@ -0,0 +1,15 @@ +// 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. + +// error-pattern:custom message + +fn main() { + fail_unless!(false, "custom message"); +}