Skip to content

No expansion backtrace for macro where contents does not parse #23243

Closed
@huonw

Description

@huonw
macro_rules! foo {
    (item) => { fn not_a_pattern() {} };
    (pattern) => { ref _x }
}
fn main() {
    foo!(pattern);
    let foo!(item) = ();
}
<anon>:3:20: 3:23 error: expected identifier, found keyword `ref`
<anon>:3     (pattern) => { ref _x }
                            ^~~
<anon>:3:24: 3:26 error: macro expansion ignores token `_x` and any following
<anon>:3     (pattern) => { ref _x }
                                ^~
<anon>:2:17: 2:19 error: expected identifier, found keyword `fn`
<anon>:2     (item) => { fn not_a_pattern() {} };
                         ^~
<anon>:2:20: 2:33 error: macro expansion ignores token `not_a_pattern` and any following
<anon>:2     (item) => { fn not_a_pattern() {} };
                            ^~~~~~~~~~~~~
error: aborting due to 4 previous errors

The error messages should point to the respective foo! invocations, not just the contents of the macro, like

<anon>:3:20: 3:23 error: expected identifier, found keyword `ref`
<anon>:3     (pattern) => { ref _x }
                            ^~~
<anon>:1:1: 4:2 note: in expansion of foo!
<anon>:6:5: 6:19 note: expansion site

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-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions