External Publication
Visit Post

Change error message of a failing `assert_eq!`

Rust Internals [Unofficial] April 1, 2026
Source

Perhaps it is down to coding style, but actual is usually a variable whereas expected is either hand-typed or also pulling a local variable (e.g., to make sure a configuration value gets through). Could be that the borrow checker tends to nudge towards having a local variable for computed results? It also avoids "cross-over" when doing let cases = [(input, answer), …]; into a for (a, e) in cases { assert_eq!(i.some_method(), e); } loop.

Discussion in the ATmosphere

Loading comments...