Skip to content

Broken pattern span for identifier parameters in macros #32072

Closed
@panicbit

Description

@panicbit

This kind of macro pattern seems to mess up the span:

macro_rules! bad {
    ($s:ident whatever) => {
        {
            let $s = 0;
            *&mut $s = 0;
        }
    }
}

fn main() {
    bad!(foo whatever);
}

Playpen

Compiling it results in a messed up error message:

<anon>:11:14: 11:22 error: cannot borrow immutable local variable `foo` as mutable
<anon>:11     bad!(foo whatever);
                       ^~~~~~~~
<anon>:11:5: 11:24 note: in this expansion of bad! (defined in <anon>)
<anon>:11:14: 11:22 help: to make the local variable mutable, use `mut` as shown:
<anon>:       bad!(foo mut whatever);
<anon>:11:5: 11:24 note: in this expansion of bad! (defined in <anon>)
error: aborting due to previous error

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