@@ -65,7 +65,7 @@ use crate::session_diagnostics::{AttributeParseError, AttributeParseErrorReason,
65
65
type GroupType < S > = LazyLock < GroupTypeInner < S > > ;
66
66
67
67
struct GroupTypeInner < S : Stage > {
68
- accepters : BTreeMap < & ' static [ Symbol ] , Vec < GroupTypeInnerAccept < S > > > ,
68
+ accepters : BTreeMap < & ' static [ Symbol ] , GroupTypeInnerAccept < S > > ,
69
69
finalizers : Vec < FinalizeFn < S > > ,
70
70
}
71
71
@@ -104,7 +104,7 @@ macro_rules! attribute_parsers {
104
104
@[ $stage: ty] pub ( crate ) static $name: ident = [ $( $names: ty) ,* $( , ) ?] ;
105
105
) => {
106
106
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( ) ;
108
108
let mut finalizes = Vec :: <FinalizeFn <$stage>>:: new( ) ;
109
109
$(
110
110
{
@@ -113,14 +113,16 @@ macro_rules! attribute_parsers {
113
113
} ;
114
114
115
115
for ( path, template, accept_fn) in <$names>:: ATTRIBUTES {
116
- accepts. entry ( * path) . or_default ( ) . push ( GroupTypeInnerAccept {
116
+ if accepts. insert ( * path, GroupTypeInnerAccept {
117
117
template: * template,
118
118
accept_fn: Box :: new( |cx, args| {
119
119
STATE_OBJECT . with_borrow_mut( |s| {
120
120
accept_fn( s, cx, args)
121
121
} )
122
122
} )
123
- } ) ;
123
+ } ) . is_some( ) {
124
+ panic!( "Found two attribute parsers for attribute {path:?}" ) ;
125
+ }
124
126
}
125
127
126
128
finalizes. push( Box :: new( |cx| {
@@ -830,22 +832,20 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
830
832
let args = parser. args ( ) ;
831
833
let parts = path. segments ( ) . map ( |i| i. name ) . collect :: < Vec < _ > > ( ) ;
832
834
833
- if let Some ( accepts) = S :: parsers ( ) . accepters . get ( parts. as_slice ( ) ) {
834
- for accept in accepts {
835
- let mut cx: AcceptContext < ' _ , ' sess , S > = AcceptContext {
836
- shared : SharedContext {
837
- cx : self ,
838
- target_span,
839
- target_id,
840
- emit_lint : & mut emit_lint,
841
- } ,
842
- attr_span : lower_span ( attr. span ) ,
843
- template : & accept. template ,
844
- attr_path : path. get_attribute_path ( ) ,
845
- } ;
846
-
847
- ( accept. accept_fn ) ( & mut cx, args)
848
- }
835
+ if let Some ( accept) = S :: parsers ( ) . accepters . get ( parts. as_slice ( ) ) {
836
+ let mut cx: AcceptContext < ' _ , ' sess , S > = AcceptContext {
837
+ shared : SharedContext {
838
+ cx : self ,
839
+ target_span,
840
+ target_id,
841
+ emit_lint : & mut emit_lint,
842
+ } ,
843
+ attr_span : lower_span ( attr. span ) ,
844
+ template : & accept. template ,
845
+ attr_path : path. get_attribute_path ( ) ,
846
+ } ;
847
+
848
+ ( accept. accept_fn ) ( & mut cx, args)
849
849
} else {
850
850
// If we're here, we must be compiling a tool attribute... Or someone
851
851
// forgot to parse their fancy new attribute. Let's warn them in any case.
0 commit comments