@@ -18,11 +18,8 @@ use rustc_session::errors::report_lit_error;
1818use rustc_session:: parse:: ParseSess ;
1919use rustc_span:: { ErrorGuaranteed , Ident , Span , Symbol } ;
2020use thin_vec:: ThinVec ;
21-
2221use crate :: ShouldEmit ;
23- use crate :: session_diagnostics:: {
24- InvalidMetaItem , InvalidMetaItemQuoteIdentSugg , SuffixedLiteralInAttribute ,
25- } ;
22+ use crate :: session_diagnostics:: { InvalidMetaItem , InvalidMetaItemQuoteIdentSugg , InvalidMetaItemRemoveNegSugg , SuffixedLiteralInAttribute } ;
2623
2724#[ derive( Clone , Debug ) ]
2825pub struct PathParser < ' a > ( pub Cow < ' a , Path > ) ;
@@ -313,15 +310,7 @@ fn expr_to_lit(
313310 match res {
314311 Ok ( lit) => {
315312 if token_lit. suffix . is_some ( ) {
316- let mut err = psess. dcx ( ) . struct_span_err (
317- expr. span ,
318- "suffixed literals are not allowed in attributes" ,
319- ) ;
320- err. help (
321- "instead of using a suffixed literal (`1u8`, `1.0f32`, etc.), \
322- use an unsuffixed version (`1`, `1.0`, etc.)",
323- ) ;
324- err. emit_unless_delay ( !should_emit. should_emit ( ) ) ;
313+ psess. dcx ( ) . create_err ( SuffixedLiteralInAttribute { span : lit. span } ) . emit_unless_delay ( !should_emit. should_emit ( ) ) ;
325314 None
326315 } else {
327316 if should_emit. should_emit ( ) && !lit. kind . is_unsuffixed ( ) {
@@ -355,6 +344,9 @@ fn expr_to_lit(
355344 if let ExprKind :: Err ( _) = expr. kind {
356345 err. downgrade_to_delayed_bug ( ) ;
357346 }
347+
348+ // If this literal is a macro call and we're not currently emitting errors, don't emit a big
349+ // This macro call might still be expanded later and become a literal
358350 if matches ! ( expr. kind, ExprKind :: MacCall ( ..) ) && !should_emit. should_emit ( ) {
359351 err. cancel ( ) ;
360352 } else {
@@ -415,6 +407,8 @@ impl<'a, 'sess> MetaItemListParserContext<'a, 'sess> {
415407 }
416408
417409 let path = self . parser . parse_path ( PathStyle :: Mod ) ?;
410+
411+ // Check style of arguments that this meta item has
418412 let args = if self . parser . check ( exp ! ( OpenParen ) ) {
419413 let start = self . parser . token . span ;
420414 let ( sub_parsers, _) = self . parser . parse_paren_comma_seq ( |parser| {
@@ -450,6 +444,7 @@ impl<'a, 'sess> MetaItemListParserContext<'a, 'sess> {
450444 span : self . parser . token . span ,
451445 descr : token_descr ( & self . parser . token ) ,
452446 quote_ident_sugg : None ,
447+ remove_neg_sugg : None
453448 } ;
454449
455450 // Suggest quoting idents, e.g. in `#[cfg(key = value)]`. We don't use `Token::ident` and
@@ -468,6 +463,14 @@ impl<'a, 'sess> MetaItemListParserContext<'a, 'sess> {
468463 } ) ;
469464 }
470465
466+ if self . parser . token == token:: Minus && self . parser . look_ahead ( 1 , |t| matches ! ( t. kind, rustc_ast:: token:: TokenKind :: Literal { ..} ) ) {
467+ err. remove_neg_sugg = Some ( InvalidMetaItemRemoveNegSugg {
468+ negative_sign : self . parser . token . span ,
469+ } ) ;
470+ self . parser . bump ( ) ;
471+ self . parser . bump ( ) ;
472+ }
473+
471474 Err ( self . parser . dcx ( ) . create_err ( err) )
472475 }
473476
0 commit comments