libsyntax: Implement a macro die! to replace the fail expression. r=brson

This commit is contained in:
Patrick Walton
2012-11-27 18:05:20 -08:00
parent 61cfec3c52
commit 07f4031bb4
2 changed files with 26 additions and 3 deletions

View File

@@ -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\")
)
)
}";
}