Rollup merge of #45887 - xfix:assert-eq-trailling-comma, r=dtolnay

Allow a trailling comma in assert_eq/ne macro

From Rust beginners IRC:

<???> It sure does annoy me that assert_eq!() does not accept a trailing comma after the last argument.
<???> ???: File an issue against https://github.com/rust-lang/rust and CC @rust-lang/libs

Figured that might as well submit it. Will become insta-stable after merging (danger zone).

cc @rust-lang/libs
This commit is contained in:
kennytm 2017-11-10 17:07:10 +08:00 committed by GitHub
commit 253d18e3f9
5 changed files with 6 additions and 16 deletions

View file

@ -120,6 +120,9 @@ macro_rules! assert_eq {
}
}
});
($left:expr, $right:expr,) => ({
assert_eq!($left, $right)
});
($left:expr, $right:expr, $($arg:tt)+) => ({
match (&($left), &($right)) {
(left_val, right_val) => {
@ -168,6 +171,9 @@ macro_rules! assert_ne {
}
}
});
($left:expr, $right:expr,) => {
assert_ne!($left, $right)
};
($left:expr, $right:expr, $($arg:tt)+) => ({
match (&($left), &($right)) {
(left_val, right_val) => {

View file

@ -1,8 +0,0 @@
error: unexpected end of macro invocation
--> $DIR/assert_eq_trailing_comma.rs:12:20
|
12 | assert_eq!(1, 1,);
| ^
error: aborting due to previous error

View file

@ -1,8 +0,0 @@
error: unexpected end of macro invocation
--> $DIR/assert_ne_trailing_comma.rs:12:20
|
12 | assert_ne!(1, 2,);
| ^
error: aborting due to previous error