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

Code before:
            }
        },
        _ => annotate_err_with_kind(&mut e, kind, site_span),
    };

    let matched_rule_bindings_names: Vec<_> =
        matched_rule_bindings.iter().map(|bind| bind.name).collect();
    let bindings_name: Vec<_> = bindings.iter().map(|bind| bind.name).collect();
    if parser.token.kind == token::Dollar {
        parser.bump();
        if let token::Ident(name, _) = parser.token.kind {
            if let Some(matched_name) = rustc_span::edit_distance::find_best_match_for_name(
                &matched_rule_bindings_names[..],
                name,
                None,
            ) {
                e.span_suggestion_verbose(
                    parser.token.span,
                    "this could be a typo, there is a macro argument with similar name",
                    format!("{matched_name}"),
                    Applicability::MaybeIncorrect,
                );
            } else if bindings_name.contains(&name) {
                e.span_label(
                    parser.token.span,
                    format!("there is an exact macro argument in the other matcher"),
                );
            } else if let Some(matched_name) =
                rustc_span::edit_distance::find_best_match_for_name(&bindings_name[..], name, None)
            {
                e.span_suggestion_verbose(
                    parser.token.span,
                    "this could be a typo, there is a macro argument with similar name in the other matcher",
                    format!("{matched_name}"),
                    Applicability::MaybeIncorrect,
                );
            } else {
                let msg = matched_rule_bindings_names
                    .iter()
                    .map(|sym| format!("${}", sym))
                    .collect::<Vec<_>>()
                    .join(", ");

                e.span_label(
                    parser.token.span,
                    format!("this could be a typo, there is no macro argument with similar name, available macro arguments are: {msg}"),
                );
            }
        }
    }
    e.emit()

Review comment (suggestion):
```suggestion
                    format!("there is an macro metavariable with this name in another macro matcher"),
```

Code after:
            }
        },
        _ => annotate_err_with_kind(&mut e, kind, site_span),
    };

    let matched_rule_bindings_names: Vec<_> =
        matched_rule_bindings.iter().map(|bind| bind.name).collect();
    let bindings_name: Vec<_> = bindings.iter().map(|bind| bind.name).collect();
    if parser.token.kind == token::Dollar {
        parser.bump();
        if let token::Ident(name, _) = parser.token.kind {
            if let Some(matched_name) = rustc_span::edit_distance::find_best_match_for_name(
                &matched_rule_bindings_names[..],
                name,
                None,
            ) {
                e.span_suggestion_verbose(
                    parser.token.span,
                    "there is a macro metavariable with similar name",
                    format!("{matched_name}"),
                    Applicability::MaybeIncorrect,
                );
            } else if bindings_name.contains(&name) {
                e.span_label(
                    parser.token.span,
                    format!(
                        "there is an macro metavariable with this name in another macro matcher"
                    ),
                );
            } else if let Some(matched_name) =
                rustc_span::edit_distance::find_best_match_for_name(&bindings_name[..], name, None)
            {
                e.span_suggestion_verbose(
                    parser.token.span,
                    "there is a macro metavariable with a similar name in another macro matcher",
                    format!("{matched_name}"),
                    Applicability::MaybeIncorrect,
                );
            } else {
                let msg = matched_rule_bindings_names
                    .iter()
                    .map(|sym| format!("${}", sym))
                    .collect::<Vec<_>>()
                    .join(", ");

                e.span_label(parser.token.span, format!("macro metavariable not found"));
                if !matched_rule_bindings_names.is_empty() {
                    e.note(format!("available metavariable names are: {msg}"));
                }
            }
        }