Skip to content

Confusing error message from missing semicolon after macro invocation #26288

Closed
@wthrowe

Description

@wthrowe

This code

macro_rules! foo {
    () => {
        assert_eq!("A", "A");
        assert_eq!("B", "B");
    }
}

fn main() {
    foo!()
}

gives the error:

foo.rs:4:9: 4:18 error: macro expansion ignores token `assert_eq` and any following
foo.rs:4         assert_eq!("B", "B");
                 ^~~~~~~~~
foo.rs:9:5: 9:11 note: caused by the macro expansion here; the usage of `foo` is likely invalid in this context
foo.rs:9     foo!()
             ^~~~~~
error: aborting due to previous error

The problem is actually a missing semicolon after foo!(), but the message wasn't really helpful in figuring that out. (I initially left out the semicolon out of habit from C, where including it would result in an extra empty statement after expansion.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.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