Skip to content

Commit

Permalink
Rollup merge of rust-lang#83081 - hyd-dev:assert-message, r=m-ou-se
Browse files Browse the repository at this point in the history
Fix panic message of `assert_failed_inner`

cc rust-lang#79100 (comment)

r? ``@m-ou-se``
  • Loading branch information
JohnTitor authored Mar 14, 2021
2 parents bc79367 + 7ecb5d8 commit f8206ac
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion library/core/src/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ fn assert_failed_inner(
Some(args) => panic!(
r#"assertion failed: `(left {} right)`
left: `{:?}`,
right: `{:?}: {}`"#,
right: `{:?}`: {}"#,
op, left, right, args
),
None => panic!(
Expand Down
9 changes: 9 additions & 0 deletions src/test/ui/macros/assert-eq-macro-msg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// run-fail
// error-pattern:panicked at 'assertion failed: `(left == right)`
// error-pattern: left: `2`
// error-pattern:right: `3`: 1 + 1 definitely should be 3'
// ignore-emscripten no processes

fn main() {
assert_eq!(1 + 1, 3, "1 + 1 definitely should be 3");
}
11 changes: 11 additions & 0 deletions src/test/ui/macros/assert-matches-macro-msg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// run-fail
// error-pattern:panicked at 'assertion failed: `(left matches right)`
// error-pattern: left: `2`
// error-pattern:right: `3`: 1 + 1 definitely should be 3'
// ignore-emscripten no processes

#![feature(assert_matches)]

fn main() {
assert_matches!(1 + 1, 3, "1 + 1 definitely should be 3");
}
9 changes: 9 additions & 0 deletions src/test/ui/macros/assert-ne-macro-msg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// run-fail
// error-pattern:panicked at 'assertion failed: `(left != right)`
// error-pattern: left: `2`
// error-pattern:right: `2`: 1 + 1 definitely should not be 2'
// ignore-emscripten no processes

fn main() {
assert_ne!(1 + 1, 2, "1 + 1 definitely should not be 2");
}

0 comments on commit f8206ac

Please sign in to comment.