about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTshepang Mbambo <tshepang@gmail.com>2024-03-20 14:31:05 +0200
committerTshepang Mbambo <tshepang@gmail.com>2024-03-20 14:31:05 +0200
commit3e8ff90935df46ed24a073a1ac2d79c600da2b45 (patch)
tree8fa2c5bd58806e74b30523449104ee87c97ea718
parentb7dcabe55e3b915ba9488dc374f752404c2c8945 (diff)
downloadrust-3e8ff90935df46ed24a073a1ac2d79c600da2b45.tar.gz
rust-3e8ff90935df46ed24a073a1ac2d79c600da2b45.zip
make "expected paren or brace" error translatable
-rw-r--r--compiler/rustc_expand/messages.ftl3
-rw-r--r--compiler/rustc_expand/src/errors.rs8
-rw-r--r--compiler/rustc_expand/src/mbe/quoted.rs8
3 files changed, 16 insertions, 3 deletions
diff --git a/compiler/rustc_expand/messages.ftl b/compiler/rustc_expand/messages.ftl
index 1f0488130b2..fdd1a87cae8 100644
--- a/compiler/rustc_expand/messages.ftl
+++ b/compiler/rustc_expand/messages.ftl
@@ -33,6 +33,9 @@ expand_duplicate_matcher_binding = duplicate matcher binding
 expand_expected_comma_in_list =
     expected token: `,`
 
+expand_expected_paren_or_brace =
+    expected `(` or `{"{"}`, found `{$token}`
+
 expand_explain_doc_comment_inner =
     inner doc comments expand to `#![doc = "..."]`, which is what this macro attempted to match
 
diff --git a/compiler/rustc_expand/src/errors.rs b/compiler/rustc_expand/src/errors.rs
index fe901603c73..21ce5e1d81e 100644
--- a/compiler/rustc_expand/src/errors.rs
+++ b/compiler/rustc_expand/src/errors.rs
@@ -448,3 +448,11 @@ pub struct InvalidFragmentSpecifier {
     pub fragment: Ident,
     pub help: String,
 }
+
+#[derive(Diagnostic)]
+#[diag(expand_expected_paren_or_brace)]
+pub struct ExpectedParenOrBrace<'a> {
+    #[primary_span]
+    pub span: Span,
+    pub token: Cow<'a, str>,
+}
diff --git a/compiler/rustc_expand/src/mbe/quoted.rs b/compiler/rustc_expand/src/mbe/quoted.rs
index 5fd3716743b..06c1612ddba 100644
--- a/compiler/rustc_expand/src/mbe/quoted.rs
+++ b/compiler/rustc_expand/src/mbe/quoted.rs
@@ -194,9 +194,11 @@ fn parse_tree<'a>(
                             }
                             Delimiter::Parenthesis => {}
                             _ => {
-                                let tok = pprust::token_kind_to_string(&token::OpenDelim(delim));
-                                let msg = format!("expected `(` or `{{`, found `{tok}`");
-                                sess.dcx().span_err(delim_span.entire(), msg);
+                                let token = pprust::token_kind_to_string(&token::OpenDelim(delim));
+                                sess.dcx().emit_err(errors::ExpectedParenOrBrace {
+                                    span: delim_span.entire(),
+                                    token,
+                                });
                             }
                         }
                     }