about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbeetrees <b@beetr.ee>2022-06-21 20:20:00 +0100
committerbeetrees <b@beetr.ee>2022-06-21 20:20:00 +0100
commitbe5337cde53eabca8a242d7de11f6702a40a1237 (patch)
tree2299efffddaa26d2ad1398f7ffc1c8ccbbb0a0d4
parent6264ffbfef035448661222ec9baf4648b1d9cb77 (diff)
downloadrust-be5337cde53eabca8a242d7de11f6702a40a1237.tar.gz
rust-be5337cde53eabca8a242d7de11f6702a40a1237.zip
Migrate `builtin-macros-expected-one-cfg-pattern` to `SessionDiagnostic`
-rw-r--r--compiler/rustc_builtin_macros/src/cfg.rs9
-rw-r--r--compiler/rustc_error_messages/locales/en-US/builtin_macros.ftl2
2 files changed, 10 insertions, 1 deletions
diff --git a/compiler/rustc_builtin_macros/src/cfg.rs b/compiler/rustc_builtin_macros/src/cfg.rs
index 2a6adc21664..c75d83bd0a0 100644
--- a/compiler/rustc_builtin_macros/src/cfg.rs
+++ b/compiler/rustc_builtin_macros/src/cfg.rs
@@ -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)
diff --git a/compiler/rustc_error_messages/locales/en-US/builtin_macros.ftl b/compiler/rustc_error_messages/locales/en-US/builtin_macros.ftl
index 89cd9fe579d..1d3e33c8185 100644
--- a/compiler/rustc_error_messages/locales/en-US/builtin_macros.ftl
+++ b/compiler/rustc_error_messages/locales/en-US/builtin_macros.ftl
@@ -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