@@ -71,7 +71,9 @@ use crate::attributes::traits::{
7171use crate :: attributes:: transparency:: TransparencyParser ;
7272use crate :: attributes:: { AttributeParser as _, Combine , Single , WithoutArgs } ;
7373use crate :: parser:: { ArgParser , PathParser } ;
74- use crate :: session_diagnostics:: { AttributeParseError , AttributeParseErrorReason , UnknownMetaItem } ;
74+ use crate :: session_diagnostics:: {
75+ AttributeParseError , AttributeParseErrorReason , ParsedDescription , UnknownMetaItem ,
76+ } ;
7577use crate :: target_checking:: AllowedTargets ;
7678
7779type GroupType < S > = LazyLock < GroupTypeInner < S > > ;
@@ -353,6 +355,10 @@ pub struct AcceptContext<'f, 'sess, S: Stage> {
353355 /// Whether it is an inner or outer attribute
354356 pub ( crate ) attr_style : AttrStyle ,
355357
358+ /// A description of the thing we are parsing using this attribute parser
359+ /// We are not only using these parsers for attributes, but also for macros such as the `cfg!()` macro.
360+ pub ( crate ) parsed_description : ParsedDescription ,
361+
356362 /// The expected structure of the attribute.
357363 ///
358364 /// Used in reporting errors to give a hint to users what the attribute *should* look like.
@@ -431,7 +437,8 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
431437 span,
432438 attr_span : self . attr_span ,
433439 template : self . template . clone ( ) ,
434- attribute : self . attr_path . clone ( ) ,
440+ path : self . attr_path . clone ( ) ,
441+ description : self . parsed_description ,
435442 reason : AttributeParseErrorReason :: ExpectedStringLiteral {
436443 byte_string : actual_literal. and_then ( |i| {
437444 i. kind . is_bytestr ( ) . then ( || self . sess ( ) . source_map ( ) . start_point ( i. span ) )
@@ -446,7 +453,8 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
446453 span,
447454 attr_span : self . attr_span ,
448455 template : self . template . clone ( ) ,
449- attribute : self . attr_path . clone ( ) ,
456+ path : self . attr_path . clone ( ) ,
457+ description : self . parsed_description ,
450458 reason : AttributeParseErrorReason :: ExpectedIntegerLiteral ,
451459 suggestions : self . suggestions ( ) ,
452460 } )
@@ -457,7 +465,8 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
457465 span,
458466 attr_span : self . attr_span ,
459467 template : self . template . clone ( ) ,
460- attribute : self . attr_path . clone ( ) ,
468+ path : self . attr_path . clone ( ) ,
469+ description : self . parsed_description ,
461470 reason : AttributeParseErrorReason :: ExpectedList ,
462471 suggestions : self . suggestions ( ) ,
463472 } )
@@ -468,7 +477,8 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
468477 span : args_span,
469478 attr_span : self . attr_span ,
470479 template : self . template . clone ( ) ,
471- attribute : self . attr_path . clone ( ) ,
480+ path : self . attr_path . clone ( ) ,
481+ description : self . parsed_description ,
472482 reason : AttributeParseErrorReason :: ExpectedNoArgs ,
473483 suggestions : self . suggestions ( ) ,
474484 } )
@@ -480,7 +490,8 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
480490 span,
481491 attr_span : self . attr_span ,
482492 template : self . template . clone ( ) ,
483- attribute : self . attr_path . clone ( ) ,
493+ path : self . attr_path . clone ( ) ,
494+ description : self . parsed_description ,
484495 reason : AttributeParseErrorReason :: ExpectedIdentifier ,
485496 suggestions : self . suggestions ( ) ,
486497 } )
@@ -493,7 +504,8 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
493504 span,
494505 attr_span : self . attr_span ,
495506 template : self . template . clone ( ) ,
496- attribute : self . attr_path . clone ( ) ,
507+ path : self . attr_path . clone ( ) ,
508+ description : self . parsed_description ,
497509 reason : AttributeParseErrorReason :: ExpectedNameValue ( name) ,
498510 suggestions : self . suggestions ( ) ,
499511 } )
@@ -505,7 +517,8 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
505517 span,
506518 attr_span : self . attr_span ,
507519 template : self . template . clone ( ) ,
508- attribute : self . attr_path . clone ( ) ,
520+ path : self . attr_path . clone ( ) ,
521+ description : self . parsed_description ,
509522 reason : AttributeParseErrorReason :: DuplicateKey ( key) ,
510523 suggestions : self . suggestions ( ) ,
511524 } )
@@ -518,7 +531,8 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
518531 span,
519532 attr_span : self . attr_span ,
520533 template : self . template . clone ( ) ,
521- attribute : self . attr_path . clone ( ) ,
534+ path : self . attr_path . clone ( ) ,
535+ description : self . parsed_description ,
522536 reason : AttributeParseErrorReason :: UnexpectedLiteral ,
523537 suggestions : self . suggestions ( ) ,
524538 } )
@@ -529,7 +543,8 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
529543 span,
530544 attr_span : self . attr_span ,
531545 template : self . template . clone ( ) ,
532- attribute : self . attr_path . clone ( ) ,
546+ path : self . attr_path . clone ( ) ,
547+ description : self . parsed_description ,
533548 reason : AttributeParseErrorReason :: ExpectedSingleArgument ,
534549 suggestions : self . suggestions ( ) ,
535550 } )
@@ -540,7 +555,8 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
540555 span,
541556 attr_span : self . attr_span ,
542557 template : self . template . clone ( ) ,
543- attribute : self . attr_path . clone ( ) ,
558+ path : self . attr_path . clone ( ) ,
559+ description : self . parsed_description ,
544560 reason : AttributeParseErrorReason :: ExpectedAtLeastOneArgument ,
545561 suggestions : self . suggestions ( ) ,
546562 } )
@@ -556,7 +572,8 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
556572 span,
557573 attr_span : self . attr_span ,
558574 template : self . template . clone ( ) ,
559- attribute : self . attr_path . clone ( ) ,
575+ path : self . attr_path . clone ( ) ,
576+ description : self . parsed_description ,
560577 reason : AttributeParseErrorReason :: ExpectedSpecificArgument {
561578 possibilities,
562579 strings : false ,
@@ -577,7 +594,8 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
577594 span,
578595 attr_span : self . attr_span ,
579596 template : self . template . clone ( ) ,
580- attribute : self . attr_path . clone ( ) ,
597+ path : self . attr_path . clone ( ) ,
598+ description : self . parsed_description ,
581599 reason : AttributeParseErrorReason :: ExpectedSpecificArgument {
582600 possibilities,
583601 strings : false ,
@@ -597,7 +615,8 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
597615 span,
598616 attr_span : self . attr_span ,
599617 template : self . template . clone ( ) ,
600- attribute : self . attr_path . clone ( ) ,
618+ path : self . attr_path . clone ( ) ,
619+ description : self . parsed_description ,
601620 reason : AttributeParseErrorReason :: ExpectedSpecificArgument {
602621 possibilities,
603622 strings : true ,
0 commit comments