You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Terse diagnostic "unexpected end of macro invocation" when misusing assert_eq! #103238
error: unexpected end of macro invocation
--> src/main.rs:2:26
|
2 | assert_eq!(1 + 2 == 3);
| ^ missing tokens in macro arguments
Better output: show macro correspondence
note: This expression was treated as the $left argument to assert_eq!
|
2 | assert_eq!(1 + 2 == 3);
| ^^^^^^^^^^
note: Following $left, assert_eq! expects ","
(See also #97108, which also asks for more verbose "missing tokens in macro arguments" errors.)
Ideal output: fix my mistake
help: To assert equality, separate the two expressions with a comma:
|
2 | assert_eq!(1 + 2, 3);
| ^
(See also #57507, which asks for specific diagnostics when making a similar mistake with the assert! macro.)
help: To assert equality, separate the two expressions with a comma:
|
2 | assert_eq!(1 + 2, 3);
| ^
Because 1 + 2 == 3 is a legal expression for RUST so we don't know if the programmer really wanted to write code like: assert_eq!(1+2 == 3, true); or assert_eq!(1+2 , 3)
error: unexpected end of macro invocation
--> aaa.rs:2:26
|
2 | assert_eq!(1 + 2 == 3);
| ^ missing tokens in macro arguments
|
note: while trying to match `,`
error: aborting due to previous error
Activity
lyming2007 commentedon Oct 19, 2022
@rustbot claim
lyming2007 commentedon Oct 19, 2022
I'm afraid we can't suggest some thing like:
Because
1 + 2 == 3is a legal expression for RUST so we don't know if the programmer really wanted to write code like:assert_eq!(1+2 == 3, true);orassert_eq!(1+2 , 3)jruderman commentedon Oct 19, 2022
I think it would be okay to suggest the more likely intended code.
Otoh, Clippy has disabled lints suggesting to replace assert with assert_eq in anticipation of Rust changes. Perhaps it would be better to hold off for now on suggestions that commit to preferring a particular assert syntax.
jruderman commentedon Oct 24, 2022
#103439 will improve diagnostics for macro use by showing what token or ast node was expected :)
Noratrieb commentedon Oct 30, 2022
With that PR, the new error is
which is better but still not great
estebank commentedon Mar 20, 2026
Current output: