rust-lang / rust-lang/rfcs

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

Open
#2,100 4 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

T-libs
Dominant language
Markdown
Stars
6.6k
Forks
1.7k
Avg merge
16h 14m
Merged PRs (30d)
1

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with RFC #2100 and its Rust Playground implementation, then inspect the existing assert!, assert_eq!, and assert_ne! macro behavior. Done would require a resolved decision on which expressions count as simple, how explicit messages behave, and an accepted RFC or implementation path; no repository file or test is named.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.