@@ -5,7 +5,7 @@ use std::sync::LazyLock;
5
5
6
6
use itertools:: Itertools ;
7
7
use private:: Sealed ;
8
- use rustc_ast:: { self as ast, LitKind , MetaItemLit , NodeId } ;
8
+ use rustc_ast:: { self as ast, AttrStyle , LitKind , MetaItemLit , NodeId } ;
9
9
use rustc_errors:: { DiagCtxtHandle , Diagnostic } ;
10
10
use rustc_feature:: { AttributeTemplate , Features } ;
11
11
use rustc_hir:: attrs:: AttributeKind ;
@@ -46,6 +46,7 @@ use crate::attributes::path::PathParser as PathAttributeParser;
46
46
use crate :: attributes:: proc_macro_attrs:: {
47
47
ProcMacroAttributeParser , ProcMacroDeriveParser , ProcMacroParser , RustcBuiltinMacroParser ,
48
48
} ;
49
+ use crate :: attributes:: prototype:: CustomMirParser ;
49
50
use crate :: attributes:: repr:: { AlignParser , ReprParser } ;
50
51
use crate :: attributes:: rustc_internal:: {
51
52
RustcLayoutScalarValidRangeEnd , RustcLayoutScalarValidRangeStart ,
@@ -167,6 +168,7 @@ attribute_parsers!(
167
168
168
169
// tidy-alphabetical-start
169
170
Single <CoverageParser >,
171
+ Single <CustomMirParser >,
170
172
Single <DeprecationParser >,
171
173
Single <DummyParser >,
172
174
Single <ExportNameParser >,
@@ -313,6 +315,7 @@ pub struct AcceptContext<'f, 'sess, S: Stage> {
313
315
/// The span of the attribute currently being parsed
314
316
pub ( crate ) attr_span : Span ,
315
317
318
+ pub ( crate ) attr_style : AttrStyle ,
316
319
/// The expected structure of the attribute.
317
320
///
318
321
/// Used in reporting errors to give a hint to users what the attribute *should* look like.
@@ -394,6 +397,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
394
397
i. kind . is_bytestr ( ) . then ( || self . sess ( ) . source_map ( ) . start_point ( i. span ) )
395
398
} ) ,
396
399
} ,
400
+ attr_style : self . attr_style ,
397
401
} )
398
402
}
399
403
@@ -404,6 +408,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
404
408
template : self . template . clone ( ) ,
405
409
attribute : self . attr_path . clone ( ) ,
406
410
reason : AttributeParseErrorReason :: ExpectedIntegerLiteral ,
411
+ attr_style : self . attr_style ,
407
412
} )
408
413
}
409
414
@@ -414,6 +419,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
414
419
template : self . template . clone ( ) ,
415
420
attribute : self . attr_path . clone ( ) ,
416
421
reason : AttributeParseErrorReason :: ExpectedList ,
422
+ attr_style : self . attr_style ,
417
423
} )
418
424
}
419
425
@@ -424,6 +430,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
424
430
template : self . template . clone ( ) ,
425
431
attribute : self . attr_path . clone ( ) ,
426
432
reason : AttributeParseErrorReason :: ExpectedNoArgs ,
433
+ attr_style : self . attr_style ,
427
434
} )
428
435
}
429
436
@@ -435,6 +442,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
435
442
template : self . template . clone ( ) ,
436
443
attribute : self . attr_path . clone ( ) ,
437
444
reason : AttributeParseErrorReason :: ExpectedIdentifier ,
445
+ attr_style : self . attr_style ,
438
446
} )
439
447
}
440
448
@@ -447,6 +455,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
447
455
template : self . template . clone ( ) ,
448
456
attribute : self . attr_path . clone ( ) ,
449
457
reason : AttributeParseErrorReason :: ExpectedNameValue ( name) ,
458
+ attr_style : self . attr_style ,
450
459
} )
451
460
}
452
461
@@ -458,6 +467,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
458
467
template : self . template . clone ( ) ,
459
468
attribute : self . attr_path . clone ( ) ,
460
469
reason : AttributeParseErrorReason :: DuplicateKey ( key) ,
470
+ attr_style : self . attr_style ,
461
471
} )
462
472
}
463
473
@@ -470,6 +480,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
470
480
template : self . template . clone ( ) ,
471
481
attribute : self . attr_path . clone ( ) ,
472
482
reason : AttributeParseErrorReason :: UnexpectedLiteral ,
483
+ attr_style : self . attr_style ,
473
484
} )
474
485
}
475
486
@@ -480,6 +491,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
480
491
template : self . template . clone ( ) ,
481
492
attribute : self . attr_path . clone ( ) ,
482
493
reason : AttributeParseErrorReason :: ExpectedSingleArgument ,
494
+ attr_style : self . attr_style ,
483
495
} )
484
496
}
485
497
@@ -490,6 +502,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
490
502
template : self . template . clone ( ) ,
491
503
attribute : self . attr_path . clone ( ) ,
492
504
reason : AttributeParseErrorReason :: ExpectedAtLeastOneArgument ,
505
+ attr_style : self . attr_style ,
493
506
} )
494
507
}
495
508
@@ -508,6 +521,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
508
521
strings : false ,
509
522
list : false ,
510
523
} ,
524
+ attr_style : self . attr_style ,
511
525
} )
512
526
}
513
527
@@ -526,6 +540,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
526
540
strings : false ,
527
541
list : true ,
528
542
} ,
543
+ attr_style : self . attr_style ,
529
544
} )
530
545
}
531
546
@@ -544,6 +559,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
544
559
strings : true ,
545
560
list : false ,
546
561
} ,
562
+ attr_style : self . attr_style ,
547
563
} )
548
564
}
549
565
@@ -802,6 +818,7 @@ impl<'sess> AttributeParser<'sess, Early> {
802
818
} ,
803
819
} ,
804
820
attr_span : attr. span ,
821
+ attr_style : attr. style ,
805
822
template,
806
823
attr_path : path. get_attribute_path ( ) ,
807
824
} ;
@@ -912,6 +929,7 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
912
929
emit_lint : & mut emit_lint,
913
930
} ,
914
931
attr_span : lower_span ( attr. span ) ,
932
+ attr_style : attr. style ,
915
933
template : & accept. template ,
916
934
attr_path : path. get_attribute_path ( ) ,
917
935
} ;
@@ -1060,6 +1078,9 @@ pub(crate) fn allowed_targets_applied(
1060
1078
if !features. stmt_expr_attributes ( ) {
1061
1079
allowed_targets. retain ( |t| !matches ! ( t, Target :: Expression | Target :: Statement ) ) ;
1062
1080
}
1081
+ if !features. extern_types ( ) {
1082
+ allowed_targets. retain ( |t| !matches ! ( t, Target :: ForeignTy ) ) ;
1083
+ }
1063
1084
}
1064
1085
1065
1086
// We define groups of "similar" targets.
0 commit comments