diff options
| author | Trevor Gross <tmgross@umich.edu> | 2025-06-21 01:01:20 -0400 |
|---|---|---|
| committer | Trevor Gross <tmgross@umich.edu> | 2025-07-09 21:11:09 -0400 |
| commit | e7ef31d651be6aa8809933fabb793b98300b970f (patch) | |
| tree | 99957c9e4c0559f3e7895583f729c8a37fa1ff45 /compiler/rustc_expand/src/errors.rs | |
| parent | e43d139a82620a268d3828a73e12a8679339e8f8 (diff) | |
| download | rust-e7ef31d651be6aa8809933fabb793b98300b970f.tar.gz rust-e7ef31d651be6aa8809933fabb793b98300b970f.zip | |
mbe: Refactor diagnostics for invalid metavar expression syntax
Give a more user-friendly diagnostic about the following:
* Trailing tokens within braces, e.g. `${foo() extra}`
* Missing parentheses, e.g. `${foo}`
* Incorrect number of arguments, with a hint about correct usage.
Diffstat (limited to 'compiler/rustc_expand/src/errors.rs')
| -rw-r--r-- | compiler/rustc_expand/src/errors.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/compiler/rustc_expand/src/errors.rs b/compiler/rustc_expand/src/errors.rs index fdbc65aff68..b56a2b043e7 100644 --- a/compiler/rustc_expand/src/errors.rs +++ b/compiler/rustc_expand/src/errors.rs @@ -496,6 +496,40 @@ pub(crate) use metavar_exprs::*; mod metavar_exprs { use super::*; + #[derive(Diagnostic, Default)] + #[diag(expand_mve_extra_tokens)] + pub(crate) struct MveExtraTokens { + #[primary_span] + #[suggestion(code = "", applicability = "machine-applicable")] + pub span: Span, + #[label] + pub ident_span: Span, + pub extra_count: usize, + + // The rest is only used for specific diagnostics and can be default if neither + // `note` is `Some`. + #[note(expand_exact)] + pub exact_args_note: Option<()>, + #[note(expand_range)] + pub range_args_note: Option<()>, + pub min_or_exact_args: usize, + pub max_args: usize, + pub name: String, + } + + #[derive(Diagnostic)] + #[note] + #[diag(expand_mve_missing_paren)] + pub(crate) struct MveMissingParen { + #[primary_span] + #[label] + pub ident_span: Span, + #[label(expand_unexpected)] + pub unexpected_span: Option<Span>, + #[suggestion(code = "( /* ... */ )", applicability = "has-placeholders")] + pub insert_span: Option<Span>, + } + #[derive(Diagnostic)] #[diag(expand_mve_unrecognized_var)] pub(crate) struct MveUnrecognizedVar { |
