Skip to content

Adjust the die macro to only accept ~str and to work in statement positi... #4153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,11 @@ fn core_macros() -> ~str {
macro_rules! die(
($msg: expr) => (
{
do core::str::as_buf($msg) |msg_buf, _msg_len| {
// ensure that the argument is an owned string
let msgptr: &~str = &{$msg};
// rt_fail_ returns ! so we need to constrain the type
// parameter on as_buf by assigning to something
let _: () = do core::str::as_buf(*msgptr) |msg_buf, _msg_len| {
do core::str::as_buf(file!()) |file_buf, _file_len| {
unsafe {
let msg_buf = core::cast::transmute(msg_buf);
Expand All @@ -388,11 +392,11 @@ fn core_macros() -> ~str {
core::rt::rt_fail_(msg_buf, file_buf, line)
}
}
}
};
}
);
() => (
die!(\"explicit failure\")
die!(~\"explicit failure\")
)
)
}";
Expand Down
5 changes: 5 additions & 0 deletions src/test/compile-fail/die-not-unique.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// error-pattern:mismatched types

fn main() {
die!("test");
}
9 changes: 9 additions & 0 deletions src/test/run-pass/die-macro.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Just testing that die!() type checks in statement position

fn f() {
die!();
}

fn main() {

}