Skip to content

Commit 6264ffb

Browse files
committedJun 21, 2022
Migrate builtin-macros-requires-cfg-pattern to SessionDiagnostic
1 parent d6072e5 commit 6264ffb

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed
 

‎Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3669,6 +3669,7 @@ dependencies = [
36693669
"rustc_feature",
36703670
"rustc_lexer",
36713671
"rustc_lint_defs",
3672+
"rustc_macros",
36723673
"rustc_parse",
36733674
"rustc_parse_format",
36743675
"rustc_session",

‎compiler/rustc_builtin_macros/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ rustc_errors = { path = "../rustc_errors" }
1616
rustc_feature = { path = "../rustc_feature" }
1717
rustc_lexer = { path = "../rustc_lexer" }
1818
rustc_lint_defs = { path = "../rustc_lint_defs" }
19+
rustc_macros = { path = "../rustc_macros" }
1920
rustc_parse = { path = "../rustc_parse" }
2021
rustc_target = { path = "../rustc_target" }
2122
rustc_session = { path = "../rustc_session" }

‎compiler/rustc_builtin_macros/src/cfg.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc_ast::tokenstream::TokenStream;
88
use rustc_attr as attr;
99
use rustc_errors::PResult;
1010
use rustc_expand::base::{self, *};
11+
use rustc_macros::SessionDiagnostic;
1112
use rustc_span::Span;
1213

1314
pub fn expand_cfg(
@@ -34,21 +35,27 @@ pub fn expand_cfg(
3435
}
3536
}
3637

37-
fn parse_cfg<'a>(cx: &mut ExtCtxt<'a>, sp: Span, tts: TokenStream) -> PResult<'a, ast::MetaItem> {
38+
#[derive(SessionDiagnostic)]
39+
#[error(slug = "builtin-macros-requires-cfg-pattern")]
40+
struct RequiresCfgPattern {
41+
#[primary_span]
42+
#[label]
43+
span: Span,
44+
}
45+
46+
fn parse_cfg<'a>(cx: &mut ExtCtxt<'a>, span: Span, tts: TokenStream) -> PResult<'a, ast::MetaItem> {
3847
let mut p = cx.new_parser_from_tts(tts);
3948

4049
if p.token == token::Eof {
41-
let mut err = cx.struct_span_err(sp, "macro requires a cfg-pattern as an argument");
42-
err.span_label(sp, "cfg-pattern required");
43-
return Err(err);
50+
return Err(cx.create_err(RequiresCfgPattern { span }));
4451
}
4552

4653
let cfg = p.parse_meta_item()?;
4754

4855
let _ = p.eat(&token::Comma);
4956

5057
if !p.eat(&token::Eof) {
51-
return Err(cx.struct_span_err(sp, "expected 1 cfg-pattern"));
58+
return Err(cx.struct_span_err(span, "expected 1 cfg-pattern"));
5259
}
5360

5461
Ok(cfg)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
builtin-macros-requires-cfg-pattern =
2+
macro requires a cfg-pattern as an argument
3+
.label = cfg-pattern required

‎compiler/rustc_error_messages/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub use unic_langid::{langid, LanguageIdentifier};
3333
fluent_messages! {
3434
parser => "../locales/en-US/parser.ftl",
3535
typeck => "../locales/en-US/typeck.ftl",
36+
builtin_macros => "../locales/en-US/builtin_macros.ftl",
3637
}
3738

3839
pub use fluent_generated::{self as fluent, DEFAULT_LOCALE_RESOURCES};

0 commit comments

Comments
 (0)