rust-lang / rust-lang/rust-analyzer

Structural Search and Replace (SSR): nothing happens when replacement includes macro

Open
#16,903 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

rust-analyzer version: rust-analyzer version: 0.3.1885-standalone (b6d1887bc 2024-03-17)
rustc version: rustc 1.75.0 (82e1608df 2023-12-21)
IDE: VSCode

NOT A CONTRIBUTION

Code
// println!($a, $b) ==>> eprintln!($a, $b)

fn main() {
    println!("foo: {}", 123);
}
Steps to reproduce
  1. cargo new foo
  2. Open new project with IDE and paste the code snippet to src/main.rs
  3. Run code action for commented line with an SSR request
Expected behavior

The println!(…) should become an eprintln!(…)

Observed behavior

Nothing happens

Additional context

If I trace the language server, it responds to the SSR request saying that there are no document changes. No errors are printed anywhere.

If I use a different replacement pattern, such as ($a, $b), it works just fine, so it's handling the match, it only fails on the replacement.

If I use a code snippet where I'm replacing a non-macro with a macro, that also fails:

fn foo(s: &str, x: isize) {}

// foo($a, $b) ==>> println!($a, $b)

fn main() {
    foo("foo: {}", 123);
}

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

No source file or test is named. Start by reproducing the SSR request in rust-analyzer with the provided macro replacement examples, then trace replacement handling after the match is found. Done means replacing println! with eprintln! and supporting the non-macro-to-macro example without returning an empty document change.

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
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.