Skip to content

Expanding macro gives wrong result when trying to "specialize" metavariables #12603

Open
@andylizi

Description

@andylizi

Consider the following macro:

macro_rules! what_number {
    ($num:literal) => {
        what_number!(@inner $num)
    };
    (@inner 42) => {
        "the answer to everything"
    };
    (@inner $num:literal) => {
        stringify!($num)
    };
}

fn main() {
    let result = what_number!(42);
    println!("{result}");
}

The compiler expands what_number!(42) to "42", but RA shows "the answer to everything".

See here for an explanation of why "42" should be the correct result.


rust-analyzer version: rust-analyzer version: 0.0.0 (427061d 2022-06-19)

rustc version: rustc 1.63.0-nightly (ca122c7eb 2022-06-13)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macromacro expansionC-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions