Skip to content

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

@lilyball

Description

@lilyball

rust-analyzer version: rust-analyzer version: 0.3.1885-standalone (b6d1887 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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ssrstructural search & replaceC-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions