Skip to content

Confusing error message in macro expansion: “error: expected expression, found 1 + 1 #71039

Closed
@steffahn

Description

@steffahn

I’ll admit, the whole error message is not too bad if you ignore the first line.

If only it wouldn’t suggest that 1 + 1 is not an expression...

macro_rules! test {
    (let $p:pat = $e:expr) => {test!(($p,$e))};
    // actual mistake: this should be expr
    //           vvv
    (($p:pat, $e:pat)) => {let $p = $e;};
}

fn foo() {
    test!(let x = 1+1);
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error: expected expression, found `1 + 1`
  --> src/lib.rs:6:37
   |
6  |     (($p:pat, $e:pat)) => {let $p = $e;};
   |                                     ^^ expected expression
...
10 |     test!(let x = 1+1);
   |     ------------------- in this macro invocation

error: aborting due to previous error

error: could not compile `playground`.

To learn more, run the command again with --verbose.

@rustbot modify labels to T-compiler, A-macros, C-enhancement, D-papercut, A-diagnostics

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-enhancementCategory: An issue proposing an enhancement or a PR with one.D-papercutDiagnostics: An error or lint that needs small tweaks.T-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