rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.09k stars 1.57k forks source link

multi macro_rules with the same name, rename failed #17855

Open A4-Tacks opened 1 month ago

A4-Tacks commented 1 month ago

rust-analyzer version: rust-analyzer 1.82.0-nightly (7c2012d0 2024-07-26)

rustc version: rustc 1.82.0-nightly (7c2012d0e 2024-07-26)

editor or extension: Vim9.1 coc-rust-analyzer

code snippet to reproduce:

fn main() {
    macro_rules! foo {
        () => {
            1
        };
    }
    assert_eq!(foo!(), 1);
    macro_rules! foo {
        () => {
            2
        };
    }
    assert_eq!(foo!(), 2); // in this line rename `foo`
}

rename foo into bar

fn main() {
    macro_rules! foo {
        () => {
            1
        };
    }
    assert_eq!(bar!(), 1);
    macro_rules! bar {
        () => {
            2
        };
    }
    assert_eq!(bar!(), 2); // in this line rename `foo`
}

expect output:

fn main() {
    macro_rules! foo {
        () => {
            1
        };
    }
    assert_eq!(foo!(), 1);
    macro_rules! bar {
        () => {
            2
        };
    }
    assert_eq!(bar!(), 2); // in this line rename `foo`
}
ChayimFriedman2 commented 2 weeks ago

Let's see if I can do this (I guess this will involve some fundamental changes to namres)...

@rustbot claim

Veykril commented 2 weeks ago

There is a couple of related issues to this https://github.com/rust-lang/rust-analyzer/issues/7084 https://github.com/rust-lang/rust-analyzer/issues/14862 https://github.com/rust-lang/rust-analyzer/issues/15749

The gist of the issue is that we don't handle the textual macro_rules scoping correctly (as well as the macro definition hierarchy https://rustc-dev-guide.rust-lang.org/macro-expansion.html#the-macro-definition-hierarchy)

ChayimFriedman2 commented 4 days ago

@rustbot release-assignment

Occupied with other things currently.