Skip to content

Commit 3e8ff90

Browse files
committed
make "expected paren or brace" error translatable
1 parent b7dcabe commit 3e8ff90

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

compiler/rustc_expand/messages.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ expand_duplicate_matcher_binding = duplicate matcher binding
3333
expand_expected_comma_in_list =
3434
expected token: `,`
3535
36+
expand_expected_paren_or_brace =
37+
expected `(` or `{"{"}`, found `{$token}`
38+
3639
expand_explain_doc_comment_inner =
3740
inner doc comments expand to `#![doc = "..."]`, which is what this macro attempted to match
3841

compiler/rustc_expand/src/errors.rs

+8
Original file line numberDiff line numberDiff line change
@@ -448,3 +448,11 @@ pub struct InvalidFragmentSpecifier {
448448
pub fragment: Ident,
449449
pub help: String,
450450
}
451+
452+
#[derive(Diagnostic)]
453+
#[diag(expand_expected_paren_or_brace)]
454+
pub struct ExpectedParenOrBrace<'a> {
455+
#[primary_span]
456+
pub span: Span,
457+
pub token: Cow<'a, str>,
458+
}

compiler/rustc_expand/src/mbe/quoted.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,11 @@ fn parse_tree<'a>(
194194
}
195195
Delimiter::Parenthesis => {}
196196
_ => {
197-
let tok = pprust::token_kind_to_string(&token::OpenDelim(delim));
198-
let msg = format!("expected `(` or `{{`, found `{tok}`");
199-
sess.dcx().span_err(delim_span.entire(), msg);
197+
let token = pprust::token_kind_to_string(&token::OpenDelim(delim));
198+
sess.dcx().emit_err(errors::ExpectedParenOrBrace {
199+
span: delim_span.entire(),
200+
token,
201+
});
200202
}
201203
}
202204
}

0 commit comments

Comments
 (0)