Skip to content

Add help for missing ( / { or incorrect overload delimiter in decl macros #101618

@Rageking8

Description

@Rageking8

Given the following code: link

macro_rules! out1 {
    $input:expr => {
        println!("{}", $input);
    };
}

macro_rules! out2 {
    ($input:expr) => println!("{}", $input);
}

macro_rules! out3 {
    ($input:expr) => {
        println!("{}", $input);
    },

    ($input:expr, $input2:expr) => {
        println!("{}", $input);
        println!("{}", $input2);
    }
}

fn main() {
    out1!(1);
    out2!(2);
    out3!(3, 4);
}

The current output is:

   Compiling playground v0.0.1 (/playground)
error: no rules expected the token `input`
 --> src/main.rs:2:6
  |
2 |     $input:expr => {
  |      ^^^^^ no rules expected this token in macro call

error: no rules expected the token `!`
 --> src/main.rs:8:29
  |
8 |     ($input:expr) => println!("{}", $input);
  |                             ^ no rules expected this token in macro call

error: no rules expected the token `,`
  --> src/main.rs:14:6
   |
14 |     },
   |      ^ no rules expected this token in macro call

error: could not compile `playground` due to 3 previous errors

Out1: Ideally the output should include a help suggestion to wrap the macro lhs with parentheses or braces (not sure which is more idiomatic, or it depends on use case)(don't think [] should be suggested in any use case though)

Out2: Ideally the output should include a help suggestion to wrap the macro rhs with parentheses or braces

Out3: Since the macro overload syntax is somewhat similar to that of match, when the delimiter between overloads is written incorrectly using , the output should ideally include a help suggestion to change , to ;

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, ..)A-parserArea: The lexing & parsing of Rust source code to an ASTD-verboseDiagnostics: Too much output caused by a single piece of incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions