Skip to content

Hard to read assert_eq!() custom message output #94005

Closed
@nyurik

Description

@nyurik

The custom message in assert_eq!(...) macro is shown right after the right:. This is hard to read because the value strings could be very long. I think it is better to print the custom message (if available) on a separate line.

fn main() {
    let a = 10;
    let b = 20;
    assert_eq!(a, b, "Values {a} and {b}");
}

The above code (playground) prints this:

thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `10`,
 right: `20`: Values 10 and 20', src/main.rs:4:5

Suggested output

thread 'main' panicked at 'assertion failed: `(left == right)`
   left: `10`,
  right: `20`,
context: Values 10 and 20', src/main.rs:4:5

Note that custom message and the location in source are still on the same line

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsE-help-wantedCall for participation: Help is requested to fix this issue.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.T-libsRelevant to the library team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions