Skip to content

Conversation

@Delta17920
Copy link
Contributor

@Delta17920 Delta17920 commented Dec 15, 2025

The Bug: The ${concat(...)} expression was using the wrong loop index when inside nested repetitions (like optional groups), causing it to get "stuck" on the first element and generate duplicate code.

The Fix: Updated metavar_expr_concat in transcribe.rs to correctly search the repetition stack (tscx.repeats) for the target variable instead of blindly using the last index.

Tests:
Added tests/ui/macros/concat-nested-repetition.rs.

Fixes #150002

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 15, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 15, 2025

r? @jieyouxu

rustbot has assigned @jieyouxu.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rust-log-analyzer

This comment has been minimized.

@Delta17920 Delta17920 force-pushed the fix/150002-macro-concat-bug branch from d913071 to 0f793cc Compare December 15, 2025 17:02
@jieyouxu
Copy link
Member

@rustbot reroll

@rustbot rustbot assigned davidtwco and unassigned jieyouxu Dec 16, 2025
@Delta17920
Copy link
Contributor Author

r? compiler

@rustbot rustbot assigned jdonszelmann and unassigned davidtwco Dec 18, 2025
let mut matched = matched_from_ident(dcx, *ident, tscx.interp)?;
let mut repeats_iter = tscx.repeats.iter();

loop {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of loop seems to be similar to what's already implemented in lookup_cur_matched. I don't quite understand why we need to do this logic again here. Maybe that function is not applicable, but I expect there already being code for getting the right variable to repetition conversion somewhere else. That's (to my admittedly slightly limited understanding) what lookup_cur_matched tries to do. Can you explain why this logic needs to be redone here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. You are right my implementation handles the descent manually, but since I'm just looking for the specific match at the current depth (and erroring otherwise), lookup_cur_matched covers this exact use case. I'll update it to use that existing function to avoid duplication

@jdonszelmann
Copy link
Contributor

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 18, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 18, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@Delta17920 Delta17920 force-pushed the fix/150002-macro-concat-bug branch from 0f793cc to 3566b67 Compare December 18, 2025 15:54
@rustbot
Copy link
Collaborator

rustbot commented Dec 18, 2025

This PR was rebased onto a different main 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.

@Delta17920
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 18, 2025
@Delta17920
Copy link
Contributor Author

@jdonszelmann any other changes?

@jdonszelmann
Copy link
Contributor

I'll get to it. My throughput is a bit lower atm because of holidays

@jdonszelmann
Copy link
Contributor

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Jan 6, 2026

📌 Commit 3566b67 has been approved by jdonszelmann

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 6, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jan 6, 2026
…-bug, r=jdonszelmann

Fix macro_metavar_expr_concat behavior with nested repetitions

**The Bug**: The `${concat(...)}` expression was using the wrong loop index when inside nested repetitions (like optional groups), causing it to get "stuck" on the first element and generate duplicate code.

**The Fix**: Updated `metavar_expr_concat` in `transcribe.rs` to correctly search the repetition stack (`tscx.repeats`) for the target variable instead of blindly using the last index.

**Tests**:
    Added `tests/ui/macros/concat-nested-repetition.rs.`

Fixes rust-lang#150002
bors added a commit that referenced this pull request Jan 6, 2026
Rollup of 4 pull requests

Successful merges:

 - #150026 (Fix macro_metavar_expr_concat behavior with nested repetitions)
 - #150521 (resolve: Rename "name bindings" to "name declarations")
 - #150704 (MGCA: Const constructors support)
 - #150728 (Cleanup some ui tests for const-traits)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Jan 6, 2026
Rollup of 4 pull requests

Successful merges:

 - #150026 (Fix macro_metavar_expr_concat behavior with nested repetitions)
 - #150521 (resolve: Rename "name bindings" to "name declarations")
 - #150704 (MGCA: Const constructors support)
 - #150728 (Cleanup some ui tests for const-traits)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 8add20b into rust-lang:main Jan 6, 2026
11 checks passed
@rustbot rustbot added this to the 1.94.0 milestone Jan 6, 2026
rust-timer added a commit that referenced this pull request Jan 6, 2026
Rollup merge of #150026 - Delta17920:fix/150002-macro-concat-bug, r=jdonszelmann

Fix macro_metavar_expr_concat behavior with nested repetitions

**The Bug**: The `${concat(...)}` expression was using the wrong loop index when inside nested repetitions (like optional groups), causing it to get "stuck" on the first element and generate duplicate code.

**The Fix**: Updated `metavar_expr_concat` in `transcribe.rs` to correctly search the repetition stack (`tscx.repeats`) for the target variable instead of blindly using the last index.

**Tests**:
    Added `tests/ui/macros/concat-nested-repetition.rs.`

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

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

macro_metavar_expr_concat broken when combining repeats and optionals

7 participants