Skip to content

Commit 170a219

Browse files
committed
Auto merge of rust-lang#111071 - nyurik:simpler-issue-94005, r=m-ou-se
Cleaner assert_eq! & assert_ne! panic messages This PR finishes refactoring of the assert messages per rust-lang#94005. The panic message format change rust-lang#112849 used to be part of this PR, but has been factored out and just merged. It might be better to keep both changes in the same release once FCP vote completes. 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); ``` #### Old messages ```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! ``` #### New messages ```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 ``` History of fixing rust-lang#94005 * rust-lang#94016 was a lengthy PR that was abandoned * rust-lang#111030 was similar, but it stringified left and right arguments, and thus caused compile time performance issues, thus closed * rust-lang#112849 factored out the two-line formatting of all panic messages Fixes rust-lang#94005 r? `@m-ou-se`
2 parents 1e8a976 + 043e113 commit 170a219

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)