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.
This commit is contained in:
parent
5fa97c35da
commit
96eed862a0
2 changed files with 18 additions and 2 deletions
|
|
@ -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)*)
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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!()))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue