Skip to content

rustc_expand: improve diagnostics for non-repeatable metavars in repetition#152558

Open
Unique-Usman wants to merge 1 commit intorust-lang:mainfrom
Unique-Usman:ua/decmacrorepeatable
Open

rustc_expand: improve diagnostics for non-repeatable metavars in repetition#152558
Unique-Usman wants to merge 1 commit intorust-lang:mainfrom
Unique-Usman:ua/decmacrorepeatable

Conversation

@Unique-Usman
Copy link
Contributor

@Unique-Usman Unique-Usman commented Feb 13, 2026

Enhance NoSyntaxVarsExprRepeat by suggesting similarly named metavariables, distinguishing repeatable vs non-repeatable bindings, and listing available repeatable variables when no match exists.

@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 Feb 13, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 13, 2026

r? @nnethercote

rustbot has assigned @nnethercote.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 68 candidates
  • Random selection from 17 candidates

@Unique-Usman
Copy link
Contributor Author

r? @estebank

@rustbot rustbot assigned estebank and unassigned nnethercote Feb 13, 2026
@Unique-Usman
Copy link
Contributor Author

address typo with repetition part of this issue -> #47452

@Unique-Usman
Copy link
Contributor Author

macro_rules! m {
    (begin $($ard:ident),* end) => {
        [$($arg),*]
    };
}

macro_rules! mn {
    (begin $($arg:ident),* end) => {
        [$($typo),*]
    };
}

macro_rules! mnr {
    (begin $arg:ident end) => {
        [$($ard),*]
    };
}

macro_rules! err {
    (begin $arg:ident end) => {
        [$($typo),*]
    };
}

fn main() {
    let x = 1;
    let _ = m![begin x end];
    let _ = mn![begin x end];
    let _ = mnr![begin x end];
    let _ = err![begin x  end];
}

will give this

error: attempted to repeat an expression containing no syntax variables matched as repeating at this depth
 --> foo.rs:3:11
  |
3 |         [$($arg),*] 
  |           ^^^^^^

error: attempted to repeat an expression containing no syntax variables matched as repeating at this depth
 --> foo.rs:9:11
  |
9 |         [$($typo),*] 
  |           ^^^^^^^

error: attempted to repeat an expression containing no syntax variables matched as repeating at this depth
  --> foo.rs:15:11
   |
15 |         [$($ard),*]
   |           ^^^^^^

error: attempted to repeat an expression containing no syntax variables matched as repeating at this depth
  --> foo.rs:21:11
   |
21 |         [$($typo),*]
   |           ^^^^^^^

error: aborting due to 4 previous errors

with this pr it will give this

[uniqueusman@archlinux rust]$ rustc +stage1 foo.rs 
error: attempted to repeat an expression containing no syntax variables matched as repeating at this depth
 --> foo.rs:3:11
  |
3 |         [$($arg),*] 
  |           ^^^^^^
  |
help: there's a macro argument with a similar name
  |
3 -         [$($arg),*] 
3 +         [$($ard),*] 
  |

error: attempted to repeat an expression containing no syntax variables matched as repeating at this depth
 --> foo.rs:9:11
  |
9 |         [$($typo),*] 
  |           ^^----^
  |             |
  |             expected one of repeatable variables arguments: $arg

error: attempted to repeat an expression containing no syntax variables matched as repeating at this depth
  --> foo.rs:15:11
   |
14 |     (begin $arg:ident end) => { 
   |             --- this macro argument is unrepeatable
15 |         [$($ard),*]
   |           ^^^^^^
   |
help: there's a macro argument with a similar name that is unrepeatable
   |
15 -         [$($ard),*]
15 +         [$($arg),*]
   |

error: attempted to repeat an expression containing no syntax variables matched as repeating at this depth
  --> foo.rs:21:11
   |
21 |         [$($typo),*]
   |           ^^----^
   |             |
   |             variable is not repeatable and there is no repeatable variable arguments

error: aborting due to 4 previous errors

@rustbot
Copy link
Collaborator

rustbot commented Feb 15, 2026

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.

…tition

Enhance `NoSyntaxVarsExprRepeat` by suggesting similarly named
metavariables, distinguishing repeatable vs non-repeatable bindings,
and listing available repeatable variables when no match exists.

Co-authored-by: Esteban Küber <esteban@kuber.com.ar>
Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants