@@ -5,7 +5,7 @@ use std::sync::LazyLock;
55
66use itertools:: Itertools ;
77use private:: Sealed ;
8- use rustc_ast:: { self as ast, LitKind , MetaItemLit , NodeId } ;
8+ use rustc_ast:: { self as ast, AttrStyle , LitKind , MetaItemLit , NodeId } ;
99use rustc_errors:: { DiagCtxtHandle , Diagnostic } ;
1010use rustc_feature:: { AttributeTemplate , Features } ;
1111use rustc_hir:: attrs:: AttributeKind ;
@@ -46,6 +46,7 @@ use crate::attributes::path::PathParser as PathAttributeParser;
4646use crate :: attributes:: proc_macro_attrs:: {
4747 ProcMacroAttributeParser , ProcMacroDeriveParser , ProcMacroParser , RustcBuiltinMacroParser ,
4848} ;
49+ use crate :: attributes:: prototype:: CustomMirParser ;
4950use crate :: attributes:: repr:: { AlignParser , ReprParser } ;
5051use crate :: attributes:: rustc_internal:: {
5152 RustcLayoutScalarValidRangeEnd , RustcLayoutScalarValidRangeStart ,
@@ -167,6 +168,7 @@ attribute_parsers!(
167168
168169 // tidy-alphabetical-start
169170 Single <CoverageParser >,
171+ Single <CustomMirParser >,
170172 Single <DeprecationParser >,
171173 Single <DummyParser >,
172174 Single <ExportNameParser >,
@@ -313,6 +315,7 @@ pub struct AcceptContext<'f, 'sess, S: Stage> {
313315 /// The span of the attribute currently being parsed
314316 pub ( crate ) attr_span : Span ,
315317
318+ pub ( crate ) attr_style : AttrStyle ,
316319 /// The expected structure of the attribute.
317320 ///
318321 /// 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> {
394397 i. kind . is_bytestr ( ) . then ( || self . sess ( ) . source_map ( ) . start_point ( i. span ) )
395398 } ) ,
396399 } ,
400+ attr_style : self . attr_style ,
397401 } )
398402 }
399403
@@ -404,6 +408,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
404408 template : self . template . clone ( ) ,
405409 attribute : self . attr_path . clone ( ) ,
406410 reason : AttributeParseErrorReason :: ExpectedIntegerLiteral ,
411+ attr_style : self . attr_style ,
407412 } )
408413 }
409414
@@ -414,6 +419,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
414419 template : self . template . clone ( ) ,
415420 attribute : self . attr_path . clone ( ) ,
416421 reason : AttributeParseErrorReason :: ExpectedList ,
422+ attr_style : self . attr_style ,
417423 } )
418424 }
419425
@@ -424,6 +430,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
424430 template : self . template . clone ( ) ,
425431 attribute : self . attr_path . clone ( ) ,
426432 reason : AttributeParseErrorReason :: ExpectedNoArgs ,
433+ attr_style : self . attr_style ,
427434 } )
428435 }
429436
@@ -435,6 +442,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
435442 template : self . template . clone ( ) ,
436443 attribute : self . attr_path . clone ( ) ,
437444 reason : AttributeParseErrorReason :: ExpectedIdentifier ,
445+ attr_style : self . attr_style ,
438446 } )
439447 }
440448
@@ -447,6 +455,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
447455 template : self . template . clone ( ) ,
448456 attribute : self . attr_path . clone ( ) ,
449457 reason : AttributeParseErrorReason :: ExpectedNameValue ( name) ,
458+ attr_style : self . attr_style ,
450459 } )
451460 }
452461
@@ -458,6 +467,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
458467 template : self . template . clone ( ) ,
459468 attribute : self . attr_path . clone ( ) ,
460469 reason : AttributeParseErrorReason :: DuplicateKey ( key) ,
470+ attr_style : self . attr_style ,
461471 } )
462472 }
463473
@@ -470,6 +480,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
470480 template : self . template . clone ( ) ,
471481 attribute : self . attr_path . clone ( ) ,
472482 reason : AttributeParseErrorReason :: UnexpectedLiteral ,
483+ attr_style : self . attr_style ,
473484 } )
474485 }
475486
@@ -480,6 +491,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
480491 template : self . template . clone ( ) ,
481492 attribute : self . attr_path . clone ( ) ,
482493 reason : AttributeParseErrorReason :: ExpectedSingleArgument ,
494+ attr_style : self . attr_style ,
483495 } )
484496 }
485497
@@ -490,6 +502,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
490502 template : self . template . clone ( ) ,
491503 attribute : self . attr_path . clone ( ) ,
492504 reason : AttributeParseErrorReason :: ExpectedAtLeastOneArgument ,
505+ attr_style : self . attr_style ,
493506 } )
494507 }
495508
@@ -508,6 +521,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
508521 strings : false ,
509522 list : false ,
510523 } ,
524+ attr_style : self . attr_style ,
511525 } )
512526 }
513527
@@ -526,6 +540,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
526540 strings : false ,
527541 list : true ,
528542 } ,
543+ attr_style : self . attr_style ,
529544 } )
530545 }
531546
@@ -544,6 +559,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
544559 strings : true ,
545560 list : false ,
546561 } ,
562+ attr_style : self . attr_style ,
547563 } )
548564 }
549565
@@ -802,6 +818,7 @@ impl<'sess> AttributeParser<'sess, Early> {
802818 } ,
803819 } ,
804820 attr_span : attr. span ,
821+ attr_style : attr. style ,
805822 template,
806823 attr_path : path. get_attribute_path ( ) ,
807824 } ;
@@ -912,6 +929,7 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
912929 emit_lint : & mut emit_lint,
913930 } ,
914931 attr_span : lower_span ( attr. span ) ,
932+ attr_style : attr. style ,
915933 template : & accept. template ,
916934 attr_path : path. get_attribute_path ( ) ,
917935 } ;
@@ -1060,6 +1078,9 @@ pub(crate) fn allowed_targets_applied(
10601078 if !features. stmt_expr_attributes ( ) {
10611079 allowed_targets. retain ( |t| !matches ! ( t, Target :: Expression | Target :: Statement ) ) ;
10621080 }
1081+ if !features. extern_types ( ) {
1082+ allowed_targets. retain ( |t| !matches ! ( t, Target :: ForeignTy ) ) ;
1083+ }
10631084 }
10641085
10651086 // We define groups of "similar" targets.
0 commit comments