Skip to content

Commit 07f4031

Browse files
committed
libsyntax: Implement a macro die! to replace the fail expression. r=brson
1 parent 61cfec3 commit 07f4031

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/libcore/rt.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@ extern mod rustrt {
3434
// 'rt_', otherwise the compiler won't find it. To fix this, see
3535
// gather_rust_rtcalls.
3636
#[rt(fail_)]
37-
pub fn rt_fail_(expr: *c_char, file: *c_char, line: size_t) {
38-
cleanup_stack_for_failure();
39-
rustrt::rust_upcall_fail(expr, file, line);
37+
pub fn rt_fail_(expr: *c_char, file: *c_char, line: size_t) -> ! {
38+
unsafe {
39+
cleanup_stack_for_failure();
40+
rustrt::rust_upcall_fail(expr, file, line);
41+
cast::transmute(())
42+
}
4043
}
4144

4245
#[rt(fail_bounds_check)]

src/libsyntax/ext/expand.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,26 @@ fn core_macros() -> ~str {
248248
#macro[[#warn[f, ...], log(core::warn, #fmt[f, ...])]];
249249
#macro[[#info[f, ...], log(core::info, #fmt[f, ...])]];
250250
#macro[[#debug[f, ...], log(core::debug, #fmt[f, ...])]];
251+
252+
macro_rules! die(
253+
($msg: expr) => (
254+
{
255+
do core::str::as_buf($msg) |msg_buf, _msg_len| {
256+
do core::str::as_buf(file!()) |file_buf, _file_len| {
257+
unsafe {
258+
let msg_buf = core::cast::transmute(msg_buf);
259+
let file_buf = core::cast::transmute(file_buf);
260+
let line = line!() as core::libc::size_t;
261+
core::rt::rt_fail_(msg_buf, file_buf, line)
262+
}
263+
}
264+
}
265+
}
266+
);
267+
() => (
268+
die!(\"explicit failure\")
269+
)
270+
)
251271
}";
252272
}
253273

0 commit comments

Comments
 (0)