Repository: rust-lang/rust
File: compiler/rustc_expand/src/mbe/transcribe.rs (Rust)

Code before:
            for ident in meta_vars {
                if let Some(name) = rustc_span::edit_distance::find_best_match_for_name(
                    &repeatable_names[..],
                    ident.name,
                    None,
                ) {
                    typo_repeatable = Some(VarTypoSuggestionRepeatable { span: ident.span, name });
                } else if let Some(name) = rustc_span::edit_distance::find_best_match_for_name(
                    &non_repeatable_names[..],
                    ident.name,
                    None,
                ) {
                    typo_unrepeatable = Some(VarTypoSuggestionUnrepeatable { span: ident.span });
                    if let Some(&orig_ident) = non_repeatables.iter().find(|n| n.symbol() == name) {
                        typo_unrepeatable_label = Some(VarTypoSuggestionUnrepeatableLabel {
                            span: orig_ident.ident().span,
                        });
                    }
                } else {
                    if !repeatable_names.is_empty() {
                        let msg = repeatable_names
                            .iter()
                            .map(|sym| format!("${}", sym))
                            .collect::<Vec<_>>()
                            .join(", ");
                        var_no_typo = Some(VarNoTypo { span: ident.span, msg });
                    } else {
                        no_repeatable_var = Some(NoRepeatableVar { span: ident.span });
                    }
                }
            }
            return Err(dcx.create_err(NoSyntaxVarsExprRepeat {
                span: seq.span(),
                typo_unrepeatable,
                typo_repeatable,
                typo_unrepeatable_label,
                var_no_typo,
                no_repeatable_var,
            }));
        }

        LockstepIterSize::Contradiction(msg) => {
            // FIXME: this really ought to be caught at macro definition time... It
            // happens when two meta-variables are used in the same repetition in a
            // sequence, but they come from different sequence matchers and repeat
            // different amounts.
            return Err(dcx.create_err(MetaVarsDifSeqMatchers { span: seq.span(), msg }));
        }

        LockstepIterSize::Constraint(len, _) => {
            // We do this to avoid an extra clone above. We know that this is a

Review comment (suggestion):
Using `rustc_errors::listify`

```suggestion
                    if !repeatable_names.is_empty()
                        && let Some(msg) = listify(&repeatable_names, |s| format!("`${s}`))
                    {
                        var_no_typo = Some(VarNoTypo { span: ident.span, msg });
```

Code after:
            for ident in meta_vars {
                if let Some(name) = rustc_span::edit_distance::find_best_match_for_name(
                    &repeatable_names[..],
                    ident.name,
                    None,
                ) {
                    typo_repeatable = Some(VarTypoSuggestionRepeatable { span: ident.span, name });
                } else if let Some(name) = rustc_span::edit_distance::find_best_match_for_name(
                    &non_repeatable_names[..],
                    ident.name,
                    None,
                ) {
                    typo_unrepeatable = Some(VarTypoSuggestionUnrepeatable { span: ident.span });
                    if let Some(&orig_ident) = non_repeatables.iter().find(|n| n.symbol() == name) {
                        typo_unrepeatable_label = Some(VarTypoSuggestionUnrepeatableLabel {
                            span: orig_ident.ident().span,
                        });
                    }
                } else {
                    if !repeatable_names.is_empty()
                        && let Some(msg) = listify(&repeatable_names, |s| format!("`${s}`"))
                    {
                        var_no_typo = Some(VarNoTypo { span: ident.span, msg });
                    } else {
                        no_repeatable_var = Some(NoRepeatableVar { span: ident.span });
                    }
                }
            }
            return Err(dcx.create_err(NoSyntaxVarsExprRepeat {
                span: seq.span(),
                typo_unrepeatable,
                typo_repeatable,
                typo_unrepeatable_label,
                var_no_typo,
                no_repeatable_var,
            }));
        }

        LockstepIterSize::Contradiction(msg) => {
            // FIXME: this really ought to be caught at macro definition time... It
            // happens when two meta-variables are used in the same repetition in a
            // sequence, but they come from different sequence matchers and repeat
            // different amounts.
            return Err(dcx.create_err(MetaVarsDifSeqMatchers { span: seq.span(), msg }));
        }

        LockstepIterSize::Constraint(len, _) => {
            // We do this to avoid an extra clone above. We know that this is a
            // sequence already.
            let mbe::TokenTree::Sequence(sp, seq) = seq else { unreachable!() };