Skip to content

Terse diagnostic "unexpected end of macro invocation" when misusing assert_eq! #103238

Open

Description

@jruderman

Given the following code (playground):

fn main() {
    assert_eq!(1 + 2 == 3);
}

Current output: terse

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.)

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Oct 19, 2022
  2. lyming2007 commented on Oct 19, 2022

    @lyming2007

    @rustbot claim

  3. lyming2007 commented on Oct 19, 2022

    @lyming2007

    I'm afraid we can't suggest some thing like:

    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)

  4. removed their assignment
    on Oct 19, 2022
  5. jruderman commented on Oct 19, 2022

    @jruderman
    ContributorAuthor

    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.

  6. jruderman commented on Oct 24, 2022

    @jruderman
    ContributorAuthor

    #103439 will improve diagnostics for macro use by showing what token or ast node was expected :)

  7. Noratrieb commented on Oct 30, 2022

    @Noratrieb
    Member

    With that PR, the new error is

    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
    

    which is better but still not great

  8. estebank commented on Mar 20, 2026

    @estebank
    Contributor

    Current output:

    error: unexpected end of macro invocation
      --> src/main.rs:2:26
       |
     2 |     assert_eq!(1 + 2 == 3);
       |                          ^ missing tokens in macro arguments
       |
    note: while trying to match `,`
      --> /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/macros/mod.rs:43:16
       |
    43 |     ($left:expr, $right:expr $(,)?) => {
       |                ^
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions