Migrate builtin-macros-expected-one-cfg-pattern to SessionDiagnostic

This commit is contained in:
beetrees 2022-06-21 20:20:00 +01:00
parent 6264ffbfef
commit be5337cde5
No known key found for this signature in database
GPG key ID: 8791BD754191EBD6
2 changed files with 10 additions and 1 deletions

View file

@ -43,6 +43,13 @@ struct RequiresCfgPattern {
span: Span,
}
#[derive(SessionDiagnostic)]
#[error(slug = "builtin-macros-expected-one-cfg-pattern")]
struct OneCfgPattern {
#[primary_span]
span: Span,
}
fn parse_cfg<'a>(cx: &mut ExtCtxt<'a>, span: Span, tts: TokenStream) -> PResult<'a, ast::MetaItem> {
let mut p = cx.new_parser_from_tts(tts);
@ -55,7 +62,7 @@ fn parse_cfg<'a>(cx: &mut ExtCtxt<'a>, span: Span, tts: TokenStream) -> PResult<
let _ = p.eat(&token::Comma);
if !p.eat(&token::Eof) {
return Err(cx.struct_span_err(span, "expected 1 cfg-pattern"));
return Err(cx.create_err(OneCfgPattern { span }));
}
Ok(cfg)

View file

@ -1,3 +1,5 @@
builtin-macros-requires-cfg-pattern =
macro requires a cfg-pattern as an argument
.label = cfg-pattern required
builtin-macros-expected-one-cfg-pattern = expected 1 cfg-pattern