External Publication
Visit Post

Change error message of a failing `assert_eq!`

Rust Internals [Unofficial] March 31, 2026
Source

I'd find it much more valuable if the output would highlight the actual difference. When asserting equality between structs (especially large or nested ones) you often get two blobs of std::fmt::Debug outputs you have to look through to find a (sometimes) one character difference.

Not sure on the feasability of that though [1], but even diff on the output text + color highlighting would be very useful in that situation. Example (inspired by Wordle):

  • Red for sections that don't occur in the Debug output of the other side
  • Optional: Orange for (larger) sections that are in the other side but not in the same place
  • White for matching sections (same place/order)

  1. Especially when order does not matter for equality like with HashMap. ↩︎

Discussion in the ATmosphere

Loading comments...