rust-lang / rust-lang/rust-analyzer

Renaming input identifier used in paste macro doesn't rename identifiers resulting from pasting

Open
#17,204 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

rust-analyzer version: 0.3.1940-standalone (f216be4a0 2024-04-27)

rustc version: 1.76.0

editor or extension: VSCode - extension v0.3.1940

code snippet to reproduce:

macro_rules! bugdemo {
    ($newtype_name:ident, $elem_name:ident) => {
        #[derive(Debug, Clone, Copy)]
        struct $newtype_name(bool);

        paste::paste! {
        impl $newtype_name {
            fn $elem_name(&self) -> bool {
                self.0
            }

            fn [<$elem_name _mut>](&mut self) -> &mut bool {
                &mut self.0
            }
        }}
    };
}

bugdemo!(MyType, myelem);

fn foo2()
{
    let mut x = MyType(false);
    *x.myelem_mut() = true;
    assert!(x.myelem());
}

To reproduce: try to rename myelem in the bugdemo invocation to myelem2. It fails to rename myelem_mut to myelem2_mut.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided Rust reproducer and trace rust-analyzer's rename handling for the macro invocation and paste-generated identifier. Done means renaming myelem to myelem2 also updates myelem_mut to myelem2_mut in the resulting code.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.