Skip to content

fix: avoid panic in struct/tuple assists when macro expands usage twice#22586

Open
Albab-Hasan wants to merge 1 commit into
rust-lang:masterfrom
Albab-Hasan:fix-assists-macro-double-expand
Open

fix: avoid panic in struct/tuple assists when macro expands usage twice#22586
Albab-Hasan wants to merge 1 commit into
rust-lang:masterfrom
Albab-Hasan:fix-assists-macro-double-expand

Conversation

@Albab-Hasan

@Albab-Hasan Albab-Hasan commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

FindUsages descends into macro expansions and emits a FileReference per expansion site. when a macro_rules! macro expands $e twice, destructure_tuple_binding, destructure_struct_binding, convert_named_struct_to_tuple_struct, and convert_tuple_struct_to_named_struct all processed each ref independently. registering two replace_all calls for the same source range. edit_algo asserts non-intersecting changes and panics in debug/test builds. silently no-ops in release. fixed by deduplicating refs by source range before processing.

Fixes #22555
Fixes #22556
Fixes #22557
Fixes #22558

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 14, 2026
`FindUsages` descends into macro expansions and emits a `FileReference` per expansion site. when a `macro_rules!` macro
expands `$e` twice, `destructure_tuple_binding`, `destructure_struct_binding`, `convert_named_struct_to_tuple_struct`,
and `convert_tuple_struct_to_named_struct` all processed each ref independently, registering two `replace_all` calls for
the same source range. `edit_algo` asserts non-intersecting changes and panics in debug/test builds, silently no-ops in
release. fixed by deduplicating refs by source range before processing.

fixes rust-lang#22555
fixes rust-lang#22556
fixes rust-lang#22557
fixes rust-lang#22558
@Albab-Hasan Albab-Hasan force-pushed the fix-assists-macro-double-expand branch from 76bad11 to 644cba6 Compare June 14, 2026 08:24
@rustbot

rustbot commented Jun 14, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment