@@ -18,11 +18,8 @@ use rustc_session::errors::report_lit_error;
18
18
use rustc_session:: parse:: ParseSess ;
19
19
use rustc_span:: { ErrorGuaranteed , Ident , Span , Symbol } ;
20
20
use thin_vec:: ThinVec ;
21
-
22
21
use crate :: ShouldEmit ;
23
- use crate :: session_diagnostics:: {
24
- InvalidMetaItem , InvalidMetaItemQuoteIdentSugg , SuffixedLiteralInAttribute ,
25
- } ;
22
+ use crate :: session_diagnostics:: { InvalidMetaItem , InvalidMetaItemQuoteIdentSugg , InvalidMetaItemRemoveNegSugg , SuffixedLiteralInAttribute } ;
26
23
27
24
#[ derive( Clone , Debug ) ]
28
25
pub struct PathParser < ' a > ( pub Cow < ' a , Path > ) ;
@@ -313,15 +310,7 @@ fn expr_to_lit(
313
310
match res {
314
311
Ok ( lit) => {
315
312
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 ( ) ) ;
325
314
None
326
315
} else {
327
316
if should_emit. should_emit ( ) && !lit. kind . is_unsuffixed ( ) {
@@ -355,6 +344,9 @@ fn expr_to_lit(
355
344
if let ExprKind :: Err ( _) = expr. kind {
356
345
err. downgrade_to_delayed_bug ( ) ;
357
346
}
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
358
350
if matches ! ( expr. kind, ExprKind :: MacCall ( ..) ) && !should_emit. should_emit ( ) {
359
351
err. cancel ( ) ;
360
352
} else {
@@ -415,6 +407,8 @@ impl<'a, 'sess> MetaItemListParserContext<'a, 'sess> {
415
407
}
416
408
417
409
let path = self . parser . parse_path ( PathStyle :: Mod ) ?;
410
+
411
+ // Check style of arguments that this meta item has
418
412
let args = if self . parser . check ( exp ! ( OpenParen ) ) {
419
413
let start = self . parser . token . span ;
420
414
let ( sub_parsers, _) = self . parser . parse_paren_comma_seq ( |parser| {
@@ -450,6 +444,7 @@ impl<'a, 'sess> MetaItemListParserContext<'a, 'sess> {
450
444
span : self . parser . token . span ,
451
445
descr : token_descr ( & self . parser . token ) ,
452
446
quote_ident_sugg : None ,
447
+ remove_neg_sugg : None
453
448
} ;
454
449
455
450
// 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> {
468
463
} ) ;
469
464
}
470
465
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
+
471
474
Err ( self . parser . dcx ( ) . create_err ( err) )
472
475
}
473
476
0 commit comments