Skip to content

Commit

Permalink
Migrate builtin-macros-expected-one-cfg-pattern to SessionDiagnostic
Browse files Browse the repository at this point in the history
  • Loading branch information
beetrees committed Jun 21, 2022
1 parent 6264ffb commit be5337c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 8 additions & 1 deletion compiler/rustc_builtin_macros/src/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit be5337c

Please sign in to comment.