@@ -65,7 +65,7 @@ use crate::session_diagnostics::{AttributeParseError, AttributeParseErrorReason,
6565type GroupType < S > = LazyLock < GroupTypeInner < S > > ;
6666
6767struct GroupTypeInner < S : Stage > {
68- accepters : BTreeMap < & ' static [ Symbol ] , Vec < GroupTypeInnerAccept < S > > > ,
68+ accepters : BTreeMap < & ' static [ Symbol ] , GroupTypeInnerAccept < S > > ,
6969 finalizers : Vec < FinalizeFn < S > > ,
7070}
7171
@@ -104,7 +104,7 @@ macro_rules! attribute_parsers {
104104 @[ $stage: ty] pub ( crate ) static $name: ident = [ $( $names: ty) ,* $( , ) ?] ;
105105 ) => {
106106 pub ( crate ) static $name: GroupType <$stage> = LazyLock :: new( || {
107- let mut accepts = BTreeMap :: <_, Vec < GroupTypeInnerAccept <$stage> >>:: new( ) ;
107+ let mut accepts = BTreeMap :: <_, GroupTypeInnerAccept <$stage>>:: new( ) ;
108108 let mut finalizes = Vec :: <FinalizeFn <$stage>>:: new( ) ;
109109 $(
110110 {
@@ -113,14 +113,16 @@ macro_rules! attribute_parsers {
113113 } ;
114114
115115 for ( path, template, accept_fn) in <$names>:: ATTRIBUTES {
116- accepts. entry ( * path) . or_default ( ) . push ( GroupTypeInnerAccept {
116+ if accepts. insert ( * path, GroupTypeInnerAccept {
117117 template: * template,
118118 accept_fn: Box :: new( |cx, args| {
119119 STATE_OBJECT . with_borrow_mut( |s| {
120120 accept_fn( s, cx, args)
121121 } )
122122 } )
123- } ) ;
123+ } ) . is_some( ) {
124+ panic!( "Found two attribute parsers for attribute {path:?}" ) ;
125+ }
124126 }
125127
126128 finalizes. push( Box :: new( |cx| {
@@ -822,22 +824,20 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
822824 let args = parser. args ( ) ;
823825 let parts = path. segments ( ) . map ( |i| i. name ) . collect :: < Vec < _ > > ( ) ;
824826
825- if let Some ( accepts) = S :: parsers ( ) . accepters . get ( parts. as_slice ( ) ) {
826- for accept in accepts {
827- let mut cx: AcceptContext < ' _ , ' sess , S > = AcceptContext {
828- shared : SharedContext {
829- cx : self ,
830- target_span,
831- target_id,
832- emit_lint : & mut emit_lint,
833- } ,
834- attr_span : lower_span ( attr. span ) ,
835- template : & accept. template ,
836- attr_path : path. get_attribute_path ( ) ,
837- } ;
838-
839- ( accept. accept_fn ) ( & mut cx, args)
840- }
827+ if let Some ( accept) = S :: parsers ( ) . accepters . get ( parts. as_slice ( ) ) {
828+ let mut cx: AcceptContext < ' _ , ' sess , S > = AcceptContext {
829+ shared : SharedContext {
830+ cx : self ,
831+ target_span,
832+ target_id,
833+ emit_lint : & mut emit_lint,
834+ } ,
835+ attr_span : lower_span ( attr. span ) ,
836+ template : & accept. template ,
837+ attr_path : path. get_attribute_path ( ) ,
838+ } ;
839+
840+ ( accept. accept_fn ) ( & mut cx, args)
841841 } else {
842842 // If we're here, we must be compiling a tool attribute... Or someone
843843 // forgot to parse their fancy new attribute. Let's warn them in any case.
0 commit comments