Skip to content

"Smart assert" that prints the values involved in simple cases #2100

Open
@eira-fransham

Description

@eira-fransham

It's pretty annoying for a new Rust programmer to have a pretty unhelpful error message when using the default assert! macro in tests or suchlike. They have to know that the "correct" way to do it is to use assert_eq! or assert_ne!, which do print the value of their arguments. I suggest that we extend the default assert! macro to print operands in simple cases, and then fall back to the current behaviour if an explicit message is provided or if the expression is complex.

I actually thought that Python did this already and I was going to use it as precedent, but its default assertion message is even worse than Rust's.

I have a simple implementation of this here, with the message modelled on assert_eq/assert_ne's message.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-libs-apiRelevant to the library API team, which will review and decide on the RFC.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions