-
Notifications
You must be signed in to change notification settings - Fork 13.3k
improve error message when two-arg assert_eq! receives a trailing comma #39554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
improve error message when two-arg assert_eq! receives a trailing comma #39554
Conversation
r? @BurntSushi (rust_highfive has picked a reviewer for you, use r? to override) |
@zackmdavis Thanks! Is there a way to write a compile-fail test for this? |
This would be a UI test, I imagine (see the |
Previously, `assert_eq!(left, right,)` (respectively, `assert_ne!(left, right,)`; note the trailing comma) would result in a confusing "requires at least a format string argument" error. In reality, a format string is optional, but the trailing comma puts us into the "match a token tree of zero or more tokens" branch of the macro (in order to support the optional format string), and passing the empty token tree into `format_args!` results in the confusing error. If instead we match a token tree of one or more tokens, we get a much more sensible "unexpected end of macro invocation" error. While we're here, fix up a stray space before a comma in the match guards. Resolves rust-lang#39369.
8ebbe16
to
65435e1
Compare
(force-pushed) |
@BurntSushi ping? |
@bors r+ |
📌 Commit 65435e1 has been approved by |
@zackmdavis Sorry about that! Thank you! :-) |
…age_when_given_a_trailing_comma, r=BurntSushi improve error message when two-arg assert_eq! receives a trailing comma Previously, `assert_eq!(left, right,)` (respectively, `assert_ne!(left, right,)`; note the trailing comma) would result in a confusing "requires at least a format string argument" error. In reality, a format string is optional, but the trailing comma puts us into the "match a token tree of zero or more tokens" branch of the macro (in order to support the optional format string), and passing the empty token tree into `format_args!` results in the confusing error. If instead we match a token tree of one or more tokens, we get a much more sensible "unexpected end of macro invocation" error. While we're here, fix up a stray space before a comma in the match guards. Resolves #39369. ----- **Before:** ``` $ rustc scratch.rs error: requires at least a format string argument --> scratch.rs:2:5 | 2 | assert_eq!(1, 2,); | ^^^^^^^^^^^^^^^^^^ | = note: this error originates in a macro outside of the current crate error: aborting due to previous error ``` **After:** ``` $ ./build/x86_64-unknown-linux-gnu/stage1/bin/rustc scratch.rs error: unexpected end of macro invocation --> scratch.rs:2:20 | 2 | assert_eq!(1, 2,); | ^ ```
☀️ Test successful - status-appveyor, status-travis |
Previously,
assert_eq!(left, right,)
(respectively,assert_ne!(left, right,)
; note the trailing comma) would result in a confusing "requiresat least a format string argument" error. In reality, a format string is
optional, but the trailing comma puts us into the "match a token tree of
zero or more tokens" branch of the macro (in order to support the
optional format string), and passing the empty token tree into
format_args!
results in the confusing error. If instead we match atoken tree of one or more tokens, we get a much more sensible
"unexpected end of macro invocation" error.
While we're here, fix up a stray space before a comma in the match
guards.
Resolves #39369.
Before:
After: