1
Fork 0

make "expected paren or brace" error translatable

This commit is contained in:
Tshepang Mbambo 2024-03-20 14:31:05 +02:00
parent b7dcabe55e
commit 3e8ff90935
3 changed files with 16 additions and 3 deletions

View file

@ -33,6 +33,9 @@ expand_duplicate_matcher_binding = duplicate matcher binding
expand_expected_comma_in_list = expand_expected_comma_in_list =
expected token: `,` expected token: `,`
expand_expected_paren_or_brace =
expected `(` or `{"{"}`, found `{$token}`
expand_explain_doc_comment_inner = expand_explain_doc_comment_inner =
inner doc comments expand to `#![doc = "..."]`, which is what this macro attempted to match inner doc comments expand to `#![doc = "..."]`, which is what this macro attempted to match

View file

@ -448,3 +448,11 @@ pub struct InvalidFragmentSpecifier {
pub fragment: Ident, pub fragment: Ident,
pub help: String, 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>,
}

View file

@ -194,9 +194,11 @@ fn parse_tree<'a>(
} }
Delimiter::Parenthesis => {} Delimiter::Parenthesis => {}
_ => { _ => {
let tok = pprust::token_kind_to_string(&token::OpenDelim(delim)); let token = pprust::token_kind_to_string(&token::OpenDelim(delim));
let msg = format!("expected `(` or `{{`, found `{tok}`"); sess.dcx().emit_err(errors::ExpectedParenOrBrace {
sess.dcx().span_err(delim_span.entire(), msg); span: delim_span.entire(),
token,
});
} }
} }
} }