about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Lamparski <diagonaldevice@gmail.com>2018-02-07 09:31:22 -0500
committerMichael Lamparski <diagonaldevice@gmail.com>2018-02-07 09:36:20 -0500
commit96eed862a08f0ee1d234f4f83419dd46fe58ccef (patch)
tree9cf1209903f98f6a590bd44d7e089d15c767436f
parent5fa97c35da2f0eeda4321da7fb5933490b798d79 (diff)
downloadrust-96eed862a08f0ee1d234f4f83419dd46fe58ccef.tar.gz
rust-96eed862a08f0ee1d234f4f83419dd46fe58ccef.zip
libcore/libstd: fix commas in macro_rules! macros
BREAKING CHANGE: (or perhaps, *bugfix*)

In #![no_std] applications, the following calls to `panic!` used
to behave differently; they now behave the same.

Old behavior:

    panic!("{{");   // panics with "{{"
    panic!("{{",);  // panics with "{"

New behavior:

    panic!("{{");   // panics with "{{"
    panic!("{{",);  // panics with "{{"

This only affects calls to `panic!` (and by proxy `assert`
and `debug_assert`) with a single string literal followed by
a trailing comma, and only in `#![no_std]` applications.
-rw-r--r--src/libcore/macros.rs17
-rw-r--r--src/libstd/macros.rs3
2 files changed, 18 insertions, 2 deletions
diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs
index f00128a8147..c12edaf0b29 100644
--- a/src/libcore/macros.rs
+++ b/src/libcore/macros.rs
@@ -19,7 +19,10 @@ macro_rules! panic {
     ($msg:expr) => ({
         $crate::panicking::panic(&($msg, file!(), line!(), __rust_unstable_column!()))
     });
-    ($fmt:expr, $($arg:tt)*) => ({
+    ($msg:expr,) => (
+        panic!($msg)
+    );
+    ($fmt:expr, $($arg:tt)+) => ({
         $crate::panicking::panic_fmt(format_args!($fmt, $($arg)*),
                                      &(file!(), line!(), __rust_unstable_column!()))
     });
@@ -79,6 +82,9 @@ macro_rules! assert {
             panic!(concat!("assertion failed: ", stringify!($cond)))
         }
     );
+    ($cond:expr,) => (
+        assert!($cond)
+    );
     ($cond:expr, $($arg:tt)+) => (
         if !$cond {
             panic!($($arg)+)
@@ -359,7 +365,8 @@ macro_rules! try {
         $crate::result::Result::Err(err) => {
             return $crate::result::Result::Err($crate::convert::From::from(err))
         }
-    })
+    });
+    ($expr:expr,) => (try!($expr));
 }
 
 /// Write formatted data into a buffer.
@@ -456,6 +463,9 @@ macro_rules! writeln {
     ($dst:expr) => (
         write!($dst, "\n")
     );
+    ($dst:expr,) => (
+        writeln!($dst)
+    );
     ($dst:expr, $fmt:expr) => (
         write!($dst, concat!($fmt, "\n"))
     );
@@ -524,6 +534,9 @@ macro_rules! unreachable {
     ($msg:expr) => ({
         unreachable!("{}", $msg)
     });
+    ($msg:expr,) => ({
+        unreachable!($msg)
+    });
     ($fmt:expr, $($arg:tt)*) => ({
         panic!(concat!("internal error: entered unreachable code: ", $fmt), $($arg)*)
     });
diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs
index f058b1caef5..5a01674a3d0 100644
--- a/src/libstd/macros.rs
+++ b/src/libstd/macros.rs
@@ -68,6 +68,9 @@ macro_rules! panic {
     ($msg:expr) => ({
         $crate::rt::begin_panic($msg, &(file!(), line!(), __rust_unstable_column!()))
     });
+    ($msg:expr,) => ({
+        panic!($msg)
+    });
     ($fmt:expr, $($arg:tt)+) => ({
         $crate::rt::begin_panic_fmt(&format_args!($fmt, $($arg)+),
                                     &(file!(), line!(), __rust_unstable_column!()))