@@ -70,7 +70,9 @@ use crate::attributes::traits::{
7070use crate :: attributes:: transparency:: TransparencyParser ;
7171use crate :: attributes:: { AttributeParser as _, Combine , Single , WithoutArgs } ;
7272use crate :: parser:: { ArgParser , PathParser } ;
73- use crate :: session_diagnostics:: { AttributeParseError , AttributeParseErrorReason , UnknownMetaItem } ;
73+ use crate :: session_diagnostics:: {
74+ AttributeParseError , AttributeParseErrorReason , ParsedDescription , UnknownMetaItem ,
75+ } ;
7476use crate :: target_checking:: AllowedTargets ;
7577
7678type GroupType < S > = LazyLock < GroupTypeInner < S > > ;
@@ -351,6 +353,10 @@ pub struct AcceptContext<'f, 'sess, S: Stage> {
351353 /// Whether it is an inner or outer attribute
352354 pub ( crate ) attr_style : AttrStyle ,
353355
356+ /// A description of the thing we are parsing using this attribute parser
357+ /// We are not only using these parsers for attributes, but also for macros such as the `cfg!()` macro.
358+ pub ( crate ) parsed_description : ParsedDescription ,
359+
354360 /// The expected structure of the attribute.
355361 ///
356362 /// Used in reporting errors to give a hint to users what the attribute *should* look like.
@@ -429,7 +435,8 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
429435 span,
430436 attr_span : self . attr_span ,
431437 template : self . template . clone ( ) ,
432- attribute : self . attr_path . clone ( ) ,
438+ path : self . attr_path . clone ( ) ,
439+ description : self . parsed_description ,
433440 reason : AttributeParseErrorReason :: ExpectedStringLiteral {
434441 byte_string : actual_literal. and_then ( |i| {
435442 i. kind . is_bytestr ( ) . then ( || self . sess ( ) . source_map ( ) . start_point ( i. span ) )
@@ -444,7 +451,8 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
444451 span,
445452 attr_span : self . attr_span ,
446453 template : self . template . clone ( ) ,
447- attribute : self . attr_path . clone ( ) ,
454+ path : self . attr_path . clone ( ) ,
455+ description : self . parsed_description ,
448456 reason : AttributeParseErrorReason :: ExpectedIntegerLiteral ,
449457 suggestions : self . suggestions ( ) ,
450458 } )
@@ -455,7 +463,8 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
455463 span,
456464 attr_span : self . attr_span ,
457465 template : self . template . clone ( ) ,
458- attribute : self . attr_path . clone ( ) ,
466+ path : self . attr_path . clone ( ) ,
467+ description : self . parsed_description ,
459468 reason : AttributeParseErrorReason :: ExpectedList ,
460469 suggestions : self . suggestions ( ) ,
461470 } )
@@ -466,7 +475,8 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
466475 span : args_span,
467476 attr_span : self . attr_span ,
468477 template : self . template . clone ( ) ,
469- attribute : self . attr_path . clone ( ) ,
478+ path : self . attr_path . clone ( ) ,
479+ description : self . parsed_description ,
470480 reason : AttributeParseErrorReason :: ExpectedNoArgs ,
471481 suggestions : self . suggestions ( ) ,
472482 } )
@@ -478,7 +488,8 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
478488 span,
479489 attr_span : self . attr_span ,
480490 template : self . template . clone ( ) ,
481- attribute : self . attr_path . clone ( ) ,
491+ path : self . attr_path . clone ( ) ,
492+ description : self . parsed_description ,
482493 reason : AttributeParseErrorReason :: ExpectedIdentifier ,
483494 suggestions : self . suggestions ( ) ,
484495 } )
@@ -491,7 +502,8 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
491502 span,
492503 attr_span : self . attr_span ,
493504 template : self . template . clone ( ) ,
494- attribute : self . attr_path . clone ( ) ,
505+ path : self . attr_path . clone ( ) ,
506+ description : self . parsed_description ,
495507 reason : AttributeParseErrorReason :: ExpectedNameValue ( name) ,
496508 suggestions : self . suggestions ( ) ,
497509 } )
@@ -503,7 +515,8 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
503515 span,
504516 attr_span : self . attr_span ,
505517 template : self . template . clone ( ) ,
506- attribute : self . attr_path . clone ( ) ,
518+ path : self . attr_path . clone ( ) ,
519+ description : self . parsed_description ,
507520 reason : AttributeParseErrorReason :: DuplicateKey ( key) ,
508521 suggestions : self . suggestions ( ) ,
509522 } )
@@ -516,7 +529,8 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
516529 span,
517530 attr_span : self . attr_span ,
518531 template : self . template . clone ( ) ,
519- attribute : self . attr_path . clone ( ) ,
532+ path : self . attr_path . clone ( ) ,
533+ description : self . parsed_description ,
520534 reason : AttributeParseErrorReason :: UnexpectedLiteral ,
521535 suggestions : self . suggestions ( ) ,
522536 } )
@@ -527,7 +541,8 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
527541 span,
528542 attr_span : self . attr_span ,
529543 template : self . template . clone ( ) ,
530- attribute : self . attr_path . clone ( ) ,
544+ path : self . attr_path . clone ( ) ,
545+ description : self . parsed_description ,
531546 reason : AttributeParseErrorReason :: ExpectedSingleArgument ,
532547 suggestions : self . suggestions ( ) ,
533548 } )
@@ -538,7 +553,8 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
538553 span,
539554 attr_span : self . attr_span ,
540555 template : self . template . clone ( ) ,
541- attribute : self . attr_path . clone ( ) ,
556+ path : self . attr_path . clone ( ) ,
557+ description : self . parsed_description ,
542558 reason : AttributeParseErrorReason :: ExpectedAtLeastOneArgument ,
543559 suggestions : self . suggestions ( ) ,
544560 } )
@@ -554,7 +570,8 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
554570 span,
555571 attr_span : self . attr_span ,
556572 template : self . template . clone ( ) ,
557- attribute : self . attr_path . clone ( ) ,
573+ path : self . attr_path . clone ( ) ,
574+ description : self . parsed_description ,
558575 reason : AttributeParseErrorReason :: ExpectedSpecificArgument {
559576 possibilities,
560577 strings : false ,
@@ -575,7 +592,8 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
575592 span,
576593 attr_span : self . attr_span ,
577594 template : self . template . clone ( ) ,
578- attribute : self . attr_path . clone ( ) ,
595+ path : self . attr_path . clone ( ) ,
596+ description : self . parsed_description ,
579597 reason : AttributeParseErrorReason :: ExpectedSpecificArgument {
580598 possibilities,
581599 strings : false ,
@@ -595,7 +613,8 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
595613 span,
596614 attr_span : self . attr_span ,
597615 template : self . template . clone ( ) ,
598- attribute : self . attr_path . clone ( ) ,
616+ path : self . attr_path . clone ( ) ,
617+ description : self . parsed_description ,
599618 reason : AttributeParseErrorReason :: ExpectedSpecificArgument {
600619 possibilities,
601620 strings : true ,
0 commit comments