External Publication
Visit Post

Change error message of a failing `assert_eq!`

Rust Internals [Unofficial] March 30, 2026
Source

When an assert_eq! fails, you get a very generic "left VS right" message:

assertion `left == right` failed
  left: "a"
 right: "b"

This makes it hard to read output of failing tests if you're unsure whether the "expected" value is the "left" or the "right".

I frequently come across Rust codebases that have a different order (actual VS expected OR expected VS actual), even in the same test module!

A quick GitHub search shows:

  • assert_eq!(expected, actual) is used 17,600 times
  • assert_eq!(actual, expected) is used 32,800 times

I think there's a lot of value to gain in eliminating this inconsistency from the ecosystem, to have an actual idiom of the order of "actual VS expected" or "expected VS actual" in assertions.

Because the "actual VS expected" case reads more naturally, and because it is also the most common, I propose changing the error message of a failing assert_eq! to "actual VS expected":

assertion `actual == expected` failed
   actual: "a"
 expected: "b"

Discussion in the ATmosphere

Loading comments...