about summary refs log tree commit diff
path: root/compiler/rustc_expand/src
diff options
context:
space:
mode:
authorTrevor Gross <tmgross@umich.edu>2025-06-21 02:59:14 -0400
committerTrevor Gross <tmgross@umich.edu>2025-07-09 21:11:09 -0400
commit87e981996fe47826a8f3a69e3d3cc73ec68dbf8d (patch)
treedccb6b1b6b7222dc42fc2c42669b659ef1a41c2c /compiler/rustc_expand/src
parente7ef31d651be6aa8809933fabb793b98300b970f (diff)
downloadrust-87e981996fe47826a8f3a69e3d3cc73ec68dbf8d.tar.gz
rust-87e981996fe47826a8f3a69e3d3cc73ec68dbf8d.zip
mbe: Refactor the diagnostic for unrecognized metavariable expressions
Change to a structural diagnostic, update the valid list, and move the
valid list to a note.
Diffstat (limited to 'compiler/rustc_expand/src')
-rw-r--r--compiler/rustc_expand/src/errors.rs10
-rw-r--r--compiler/rustc_expand/src/mbe/metavar_expr.rs14
2 files changed, 15 insertions, 9 deletions
diff --git a/compiler/rustc_expand/src/errors.rs b/compiler/rustc_expand/src/errors.rs
index b56a2b043e7..3ac5d213053 100644
--- a/compiler/rustc_expand/src/errors.rs
+++ b/compiler/rustc_expand/src/errors.rs
@@ -531,6 +531,16 @@ mod metavar_exprs {
     }
 
     #[derive(Diagnostic)]
+    #[note]
+    #[diag(expand_mve_unrecognized_expr)]
+    pub(crate) struct MveUnrecognizedExpr {
+        #[primary_span]
+        #[label]
+        pub span: Span,
+        pub valid_expr_list: &'static str,
+    }
+
+    #[derive(Diagnostic)]
     #[diag(expand_mve_unrecognized_var)]
     pub(crate) struct MveUnrecognizedVar {
         #[primary_span]
diff --git a/compiler/rustc_expand/src/mbe/metavar_expr.rs b/compiler/rustc_expand/src/mbe/metavar_expr.rs
index 8f15b5794c7..d2b275ad20a 100644
--- a/compiler/rustc_expand/src/mbe/metavar_expr.rs
+++ b/compiler/rustc_expand/src/mbe/metavar_expr.rs
@@ -79,15 +79,11 @@ impl MetaVarExpr {
             "index" => MetaVarExpr::Index(parse_depth(&mut iter, psess, ident.span)?),
             "len" => MetaVarExpr::Len(parse_depth(&mut iter, psess, ident.span)?),
             _ => {
-                let err_msg = "unrecognized meta-variable expression";
-                let mut err = psess.dcx().struct_span_err(ident.span, err_msg);
-                err.span_suggestion(
-                    ident.span,
-                    "supported expressions are count, ignore, index and len",
-                    "",
-                    Applicability::MachineApplicable,
-                );
-                return Err(err);
+                let err = errors::MveUnrecognizedExpr {
+                    span: ident.span,
+                    valid_expr_list: "`count`, `ignore`, `index`, `len`, and `concat`",
+                };
+                return Err(psess.dcx().create_err(err));
             }
         };
         check_trailing_tokens(&mut iter, psess, ident)?;