rust-lang / rust-lang/rust-analyzer

`destructure_tuple_binding` produces intersecting edits when a macro expands the usage twice

Open
#22,555 1 comment 0 reactions 1 assignee View on GitHub

@Albab-Hasan is already working on this.

Since Jun 10, 2026.

A-assists 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.2929-standalone (panic message below is from a source build of master with force-always-assert; on the release build the assist silently does nothing and only logs the error)

rustc version: rustc 1.97.0-nightly (ca9a134e0 2026-04-26)

editor or extension: VSCode, rust-analyzer extension 0.3.2929

relevant settings: none

repository link (if public, optional): n/a

code snippet to reproduce:

macro_rules! m { ($e:expr) => { ($e, $e) }; }

fn main() {
    let t = (1,);
    m!(t.0);
}

reproduce:
cursor on t in let t = (1,);
Destructure tuple

expected:
let (_0,) = (1,); and m!(_0);, or the assist bails on the macro usage. either way no crash.

actual:
on the release build the assist is offered, applies nothing, and logs the error. on a build with debug assertions the request handler panics:

request handler panicked: some replace change ranges intersect!
left change:  ReplaceAll(Token(IDENT@194..195 "t")..=Token(INT_NUMBER@196..197 "0"), [Node(PATH_EXPR@0..2)]) (t.0_0)
equals
right change: ReplaceAll(Token(IDENT@194..195 "t")..=Token(INT_NUMBER@196..197 "0"), [Node(PATH_EXPR@0..2)]) (t.0_0)
panicked at crates/syntax/src/syntax_editor/edit_algo.rs:478:5:
some replace change ranges intersect!

cause:
the macro expands $e twice, so FindUsages descends into the expansion and returns two FileReferences for the single t token in the source. the handler maps each one back with original_range_opt + cover_edit_range and calls SyntaxEditor::replace_all for both, registering two identical ReplaceAll changes. the disjointness check in edit_algo.rs then trips stdx::always!(false, "some replace change ranges intersect!") and the whole edit is discarded.

env:

  • rustc: 1.97.0-nightly
  • rust-analyzer: 0.3.2929
  • OS: Ubuntu
  • Editor: VS Code

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.