diff options
| author | clubby789 <jamie@hill-daniel.co.uk> | 2023-04-08 20:37:41 +0100 |
|---|---|---|
| committer | clubby789 <jamie@hill-daniel.co.uk> | 2023-04-10 21:16:53 +0100 |
| commit | 64f75977764439f500f58ed6f2ac6db4873b250a (patch) | |
| tree | 774109c31b41752d791d0ceba7609d23e7a71601 /compiler/rustc_builtin_macros/src/assert.rs | |
| parent | b6f6104a1f62a0eec7d2e2ccdc07709fcc4c83f0 (diff) | |
| download | rust-64f75977764439f500f58ed6f2ac6db4873b250a.tar.gz rust-64f75977764439f500f58ed6f2ac6db4873b250a.zip | |
Migrate most of `rustc_builtin_macros` to diagnostic impls
Co-authored-by: Joe ST <joe@fbstj.net> Co-authored-by: Michael Goulet <michael@errs.io>
Diffstat (limited to 'compiler/rustc_builtin_macros/src/assert.rs')
| -rw-r--r-- | compiler/rustc_builtin_macros/src/assert.rs | 28 |
1 files changed, 6 insertions, 22 deletions
diff --git a/compiler/rustc_builtin_macros/src/assert.rs b/compiler/rustc_builtin_macros/src/assert.rs index 75af5e2b1fa..0de424be2f1 100644 --- a/compiler/rustc_builtin_macros/src/assert.rs +++ b/compiler/rustc_builtin_macros/src/assert.rs @@ -1,12 +1,13 @@ mod context; use crate::edition_panic::use_panic_2021; +use crate::errors; use rustc_ast::ptr::P; use rustc_ast::token; use rustc_ast::tokenstream::{DelimSpan, TokenStream}; use rustc_ast::{DelimArgs, Expr, ExprKind, MacCall, MacDelimiter, Path, PathSegment, UnOp}; use rustc_ast_pretty::pprust; -use rustc_errors::{Applicability, PResult}; +use rustc_errors::PResult; use rustc_expand::base::{DummyResult, ExtCtxt, MacEager, MacResult}; use rustc_parse::parser::Parser; use rustc_span::symbol::{sym, Ident, Symbol}; @@ -114,9 +115,7 @@ fn parse_assert<'a>(cx: &mut ExtCtxt<'a>, sp: Span, stream: TokenStream) -> PRes let mut parser = cx.new_parser_from_tts(stream); if parser.token == token::Eof { - let mut err = cx.struct_span_err(sp, "macro requires a boolean expression as an argument"); - err.span_label(sp, "boolean expression required"); - return Err(err); + return Err(cx.create_err(errors::AssertRequiresBoolean { span: sp })); } let cond_expr = parser.parse_expr()?; @@ -129,15 +128,7 @@ fn parse_assert<'a>(cx: &mut ExtCtxt<'a>, sp: Span, stream: TokenStream) -> PRes // // Emit an error about semicolon and suggest removing it. if parser.token == token::Semi { - let mut err = cx.struct_span_err(sp, "macro requires an expression as an argument"); - err.span_suggestion( - parser.token.span, - "try removing semicolon", - "", - Applicability::MaybeIncorrect, - ); - err.emit(); - + cx.emit_err(errors::AssertRequiresExpression { span: sp, token: parser.token.span }); parser.bump(); } @@ -149,15 +140,8 @@ fn parse_assert<'a>(cx: &mut ExtCtxt<'a>, sp: Span, stream: TokenStream) -> PRes // Emit an error and suggest inserting a comma. let custom_message = if let token::Literal(token::Lit { kind: token::Str, .. }) = parser.token.kind { - let mut err = cx.struct_span_err(parser.token.span, "unexpected string literal"); - let comma_span = parser.prev_token.span.shrink_to_hi(); - err.span_suggestion_short( - comma_span, - "try adding a comma", - ", ", - Applicability::MaybeIncorrect, - ); - err.emit(); + let comma = parser.prev_token.span.shrink_to_hi(); + cx.emit_err(errors::AssertMissingComma { span: parser.token.span, comma }); parse_custom_message(&mut parser) } else if parser.eat(&token::Comma) { |
