Skip to content

Commit 043e113

Browse files
committed
Cleaner assert_eq! & assert_ne! panic messages
Modify panic message for `assert_eq!`, `assert_ne!`, the currently unstable `assert_matches!`, as well as the corresponding `debug_assert_*` macros. ```rust assert_eq!(1 + 1, 3); assert_eq!(1 + 1, 3, "my custom message value={}!", 42); ``` ```plain thread 'main' panicked at $DIR/main.rs:6:5: assertion failed: `(left == right)` left: `2`, right: `3` ``` ```plain thread 'main' panicked at $DIR/main.rs:6:5: assertion failed: `(left == right)` left: `2`, right: `3`: my custom message value=42! ``` ```plain thread 'main' panicked at $DIR/main.rs:6:5: assertion `left == right` failed left: 2 right: 3 ``` ```plain thread 'main' panicked at $DIR/main.rs:6:5: assertion `left == right` failed: my custom message value=42! left: 2 right: 3 ``` This PR is a simpler subset of the rust-lang#111030, but it does NOT stringify the original left and right source code assert expressions, thus should be faster to compile.
1 parent 7844e81 commit 043e113

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

core/src/panicking.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -267,16 +267,14 @@ fn assert_failed_inner(
267267

268268
match args {
269269
Some(args) => panic!(
270-
r#"assertion failed: `(left {} right)`
271-
left: `{:?}`,
272-
right: `{:?}`: {}"#,
273-
op, left, right, args
270+
r#"assertion `left {op} right` failed: {args}
271+
left: {left:?}
272+
right: {right:?}"#
274273
),
275274
None => panic!(
276-
r#"assertion failed: `(left {} right)`
277-
left: `{:?}`,
278-
right: `{:?}`"#,
279-
op, left, right,
275+
r#"assertion `left {op} right` failed
276+
left: {left:?}
277+
right: {right:?}"#
280278
),
281279
}
282280
}

0 commit comments

Comments
 (0)