summary refs log tree commit diff
path: root/src/libsyntax/ext
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2012-11-27 18:05:20 -0800
committerPatrick Walton <pcwalton@mimiga.net>2012-11-28 11:28:56 -0800
commit07f4031bb40967f9c5c0ee61b71e1d9cffd34b58 (patch)
treea7c7077c1d6e298f151b328ac727a5ef534e288f /src/libsyntax/ext
parent61cfec3c52d3ac316b627c4b20c9c6e81e7521f2 (diff)
downloadrust-07f4031bb40967f9c5c0ee61b71e1d9cffd34b58.tar.gz
rust-07f4031bb40967f9c5c0ee61b71e1d9cffd34b58.zip
libsyntax: Implement a macro `die!` to replace the `fail` expression. r=brson
Diffstat (limited to 'src/libsyntax/ext')
-rw-r--r--src/libsyntax/ext/expand.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs
index 443a937d4eb..c09655d73d3 100644
--- a/src/libsyntax/ext/expand.rs
+++ b/src/libsyntax/ext/expand.rs
@@ -248,6 +248,26 @@ fn core_macros() -> ~str {
     #macro[[#warn[f, ...], log(core::warn, #fmt[f, ...])]];
     #macro[[#info[f, ...], log(core::info, #fmt[f, ...])]];
     #macro[[#debug[f, ...], log(core::debug, #fmt[f, ...])]];
+
+    macro_rules! die(
+        ($msg: expr) => (
+            {
+                do core::str::as_buf($msg) |msg_buf, _msg_len| {
+                    do core::str::as_buf(file!()) |file_buf, _file_len| {
+                        unsafe {
+                            let msg_buf = core::cast::transmute(msg_buf);
+                            let file_buf = core::cast::transmute(file_buf);
+                            let line = line!() as core::libc::size_t;
+                            core::rt::rt_fail_(msg_buf, file_buf, line)
+                        }
+                    }
+                }
+            }
+        );
+        () => (
+            die!(\"explicit failure\")
+        )
+    )
 }";
 }