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

Code before:
                );
            } 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()
}

pub(crate) fn annotate_err_with_kind(err: &mut Diag<'_>, kind: AstFragmentKind, span: Span) {
    match kind {
        AstFragmentKind::Ty => {
            err.span_label(span, "this macro call doesn't expand to a type");
        }
        AstFragmentKind::Pat => {
            err.span_label(span, "this macro call doesn't expand to a pattern");
        }
        _ => {}
    };
}

#[derive(Subdiagnostic)]
enum ExplainDocComment {
    #[label(
        "inner doc comments expand to `#![doc = \"...\"]`, which is what this macro attempted to match"
    )]
    Inner {
        #[primary_span]

Review comment (suggestion):
```suggestion
                );
                if !matched_rule_bindings_names.is_empty() {
                    err.note(format!("available metavariable names are: {msg}"));
                }
```

Code after:
                );
            } 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}"));
                }
            }
        }
    }
    e.emit()
}

pub(crate) fn annotate_err_with_kind(err: &mut Diag<'_>, kind: AstFragmentKind, span: Span) {
    match kind {
        AstFragmentKind::Ty => {
            err.span_label(span, "this macro call doesn't expand to a type");
        }
        AstFragmentKind::Pat => {
            err.span_label(span, "this macro call doesn't expand to a pattern");
        }
        _ => {}
    };
}

#[derive(Subdiagnostic)]
enum ExplainDocComment {
    #[label(
        "inner doc comments expand to `#![doc = \"...\"]`, which is what this macro attempted to match"
    )]