about summary refs log tree commit diff
path: root/src/libsyntax/ext
diff options
context:
space:
mode:
authorMarvin Löbel <loebel.marvin@gmail.com>2013-04-23 22:30:58 +0200
committerMarvin Löbel <loebel.marvin@gmail.com>2013-04-25 17:32:25 +0200
commite1be9ae22468e19d66daaebbceeeeaea2e75f903 (patch)
treedc442111f15ccd656e6ea9598307f57a3bd78b73 /src/libsyntax/ext
parent1d53babd2f23439975518fda94d9122b15e779c9 (diff)
downloadrust-e1be9ae22468e19d66daaebbceeeeaea2e75f903.tar.gz
rust-e1be9ae22468e19d66daaebbceeeeaea2e75f903.zip
Made fail! and assert! accept both &'static str and ~str, as well as a fmt! like format list.
Unwinding through macros now happens as a call to the trait function `FailWithCause::fail_with()`, which consumes self, allowing to use a more generic failure object in the future.
Diffstat (limited to 'src/libsyntax/ext')
-rw-r--r--src/libsyntax/ext/auto_encode.rs2
-rw-r--r--src/libsyntax/ext/build.rs7
-rw-r--r--src/libsyntax/ext/expand.rs42
3 files changed, 34 insertions, 17 deletions
diff --git a/src/libsyntax/ext/auto_encode.rs b/src/libsyntax/ext/auto_encode.rs
index 67c09c00733..8263fce2356 100644
--- a/src/libsyntax/ext/auto_encode.rs
+++ b/src/libsyntax/ext/auto_encode.rs
@@ -1101,7 +1101,7 @@ fn mk_enum_deser_body(
     };
 
     let quoted_expr = copy quote_expr!(
-      ::core::sys::begin_unwind(~"explicit failure", ~"empty", 1);
+      ::core::sys::FailWithCause::fail_with("explicit failure", "empty", 1);
     ).node;
 
     let impossible_case = ast::arm {
diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs
index ff78ddb803c..db4929854b3 100644
--- a/src/libsyntax/ext/build.rs
+++ b/src/libsyntax/ext/build.rs
@@ -474,11 +474,12 @@ pub fn mk_unreachable(cx: @ext_ctxt, span: span) -> @ast::expr {
         ~[
             cx.ident_of(~"core"),
             cx.ident_of(~"sys"),
-            cx.ident_of(~"begin_unwind"),
+            cx.ident_of(~"FailWithCause"),
+            cx.ident_of(~"fail_with"),
         ],
         ~[
-            mk_uniq_str(cx, span, ~"internal error: entered unreachable code"),
-            mk_uniq_str(cx, span, loc.file.name),
+            mk_base_str(cx, span, ~"internal error: entered unreachable code"),
+            mk_base_str(cx, span, loc.file.name),
             mk_uint(cx, span, loc.line),
         ]
     )
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs
index 61032429c93..53ebb946114 100644
--- a/src/libsyntax/ext/expand.rs
+++ b/src/libsyntax/ext/expand.rs
@@ -415,6 +415,7 @@ pub fn core_macros() -> ~str {
             __log(1u32, fmt!( $($arg),+ ))
         )
     )
+
     macro_rules! warn (
         ($arg:expr) => (
             __log(2u32, fmt!( \"%?\", $arg ))
@@ -423,6 +424,7 @@ pub fn core_macros() -> ~str {
             __log(2u32, fmt!( $($arg),+ ))
         )
     )
+
     macro_rules! info (
         ($arg:expr) => (
             __log(3u32, fmt!( \"%?\", $arg ))
@@ -431,6 +433,7 @@ pub fn core_macros() -> ~str {
             __log(3u32, fmt!( $($arg),+ ))
         )
     )
+
     macro_rules! debug (
         ($arg:expr) => (
             __log(4u32, fmt!( \"%?\", $arg ))
@@ -441,35 +444,48 @@ pub fn core_macros() -> ~str {
     )
 
     macro_rules! fail(
-        ($msg: expr) => (
-            ::core::sys::begin_unwind($msg, file!().to_owned(), line!())
-        );
         () => (
-            fail!(~\"explicit failure\")
+            fail!(\"explicit failure\")
+        );
+        ($msg:expr) => (
+            ::core::sys::FailWithCause::fail_with($msg, file!(), line!())
+        );
+        ($( $arg:expr ),+) => (
+            ::core::sys::FailWithCause::fail_with(fmt!( $($arg),+ ), file!(), line!())
         )
     )
 
     macro_rules! assert(
         ($cond:expr) => {
             if !$cond {
-                ::core::sys::fail_assert(stringify!($cond), file!(), line!())
+                ::core::sys::FailWithCause::fail_with(
+                    ~\"assertion failed: \" + stringify!($cond), file!(), line!())
             }
         };
         ($cond:expr, $msg:expr) => {
             if !$cond {
-                ::core::sys::fail_assert($msg, file!(), line!())
+                ::core::sys::FailWithCause::fail_with($msg, file!(), line!())
+            }
+        };
+        ($cond:expr, $( $arg:expr ),+) => {
+            if !$cond {
+                ::core::sys::FailWithCause::fail_with(fmt!( $($arg),+ ), file!(), line!())
             }
         }
     )
 
     macro_rules! assert_eq (
-        ($given:expr , $expected:expr) =>
-        ({let given_val = $given;
-          let expected_val = $expected;
-          // check both directions of equality....
-          if !((given_val == expected_val) && (expected_val == given_val)) {
-            fail!(fmt!(\"expected: %?, given: %?\",expected_val,given_val));
-        }}))
+        ($given:expr , $expected:expr) => (
+            {
+                let given_val = $given;
+                let expected_val = $expected;
+                // check both directions of equality....
+                if !((given_val == expected_val) && (expected_val == given_val)) {
+                    fail!(fmt!(\"left: %? != right: %?\", given_val, expected_val));
+                }
+            }
+        )
+    )
 
     macro_rules! condition (