@@ -8,6 +8,7 @@ use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, Level, MultiSpan};
88use rustc_feature:: { AttributeTemplate , Features } ;
99use rustc_hir:: attrs:: AttributeKind ;
1010use rustc_hir:: { AttrArgs , AttrItem , AttrPath , Attribute , HashIgnoredAttrId , Target } ;
11+ use rustc_lint_defs:: RegisteredTools ;
1112use rustc_session:: Session ;
1213use rustc_session:: lint:: LintId ;
1314use rustc_span:: { DUMMY_SP , ErrorGuaranteed , Span , Symbol , sym} ;
@@ -33,7 +34,7 @@ pub struct EmitAttribute(
3334/// Context created once, for example as part of the ast lowering
3435/// context, through which all attributes can be lowered.
3536pub struct AttributeParser < ' sess > {
36- pub ( crate ) tools : Vec < Symbol > ,
37+ pub ( crate ) tools : Option < & ' sess RegisteredTools > ,
3738 pub ( crate ) features : Option < & ' sess Features > ,
3839 pub ( crate ) sess : & ' sess Session ,
3940 pub ( crate ) should_emit : ShouldEmit ,
@@ -59,6 +60,8 @@ impl<'sess> AttributeParser<'sess> {
5960 /// No diagnostics will be emitted when parsing limited. Lints are not emitted at all, while
6061 /// errors will be emitted as a delayed bugs. in other words, we *expect* attributes parsed
6162 /// with `parse_limited` to be reparsed later during ast lowering where we *do* emit the errors
63+ ///
64+ /// Due to this function not taking in RegisteredTools, *do not* use this for parsing any lint attributes
6265 pub fn parse_limited (
6366 sess : & ' sess Session ,
6467 attrs : & [ ast:: Attribute ] ,
@@ -79,6 +82,8 @@ impl<'sess> AttributeParser<'sess> {
7982
8083 /// This does the same as `parse_limited`, except it has a `should_emit` parameter which allows it to emit errors.
8184 /// Usually you want `parse_limited`, which emits no errors.
85+ ///
86+ /// Due to this function not taking in RegisteredTools, *do not* use this for parsing any lint attributes
8287 pub fn parse_limited_should_emit (
8388 sess : & ' sess Session ,
8489 attrs : & [ ast:: Attribute ] ,
@@ -98,6 +103,7 @@ impl<'sess> AttributeParser<'sess> {
98103 target_node_id,
99104 features,
100105 should_emit,
106+ None ,
101107 ) ;
102108 assert ! ( parsed. len( ) <= 1 ) ;
103109 parsed. pop ( )
@@ -119,8 +125,9 @@ impl<'sess> AttributeParser<'sess> {
119125 target_node_id : NodeId ,
120126 features : Option < & ' sess Features > ,
121127 should_emit : ShouldEmit ,
128+ tools : Option < & ' sess RegisteredTools > ,
122129 ) -> Vec < Attribute > {
123- let mut p = Self { features, tools : Vec :: new ( ) , parse_only, sess, should_emit } ;
130+ let mut p = Self { features, tools, parse_only, sess, should_emit } ;
124131 p. parse_attribute_list (
125132 attrs,
126133 target_span,
@@ -202,7 +209,7 @@ impl<'sess> AttributeParser<'sess> {
202209 parse_fn : fn ( cx : & mut AcceptContext < ' _ , ' _ > , item : & I ) -> T ,
203210 template : & AttributeTemplate ,
204211 ) -> T {
205- let mut parser = Self { features, tools : Vec :: new ( ) , parse_only : None , sess, should_emit } ;
212+ let mut parser = Self { features, tools : None , parse_only : None , sess, should_emit } ;
206213 let mut emit_lint = |lint_id : LintId , span : MultiSpan , kind : EmitAttribute | {
207214 sess. psess . dyn_buffer_lint_sess ( lint_id. lint , span, target_node_id, kind. 0 )
208215 } ;
@@ -237,10 +244,10 @@ impl<'sess> AttributeParser<'sess> {
237244 pub fn new (
238245 sess : & ' sess Session ,
239246 features : & ' sess Features ,
240- tools : Vec < Symbol > ,
247+ tools : & ' sess RegisteredTools ,
241248 should_emit : ShouldEmit ,
242249 ) -> Self {
243- Self { features : Some ( features) , tools, parse_only : None , sess, should_emit }
250+ Self { features : Some ( features) , tools : Some ( tools ) , parse_only : None , sess, should_emit }
244251 }
245252
246253 pub ( crate ) fn sess ( & self ) -> & ' sess Session {
@@ -432,12 +439,13 @@ impl<'sess> AttributeParser<'sess> {
432439
433440 let attr = Attribute :: Unparsed ( Box :: new ( attr) ) ;
434441
435- if self . tools . contains ( & parts[ 0 ] )
442+ if self . tools . is_some_and ( |tools| {
443+ tools. iter ( ) . any ( |tool| tool. name == parts[ 0 ] )
436444 // FIXME: this can be removed once #152369 has been merged.
437445 // https://github.com/rust-lang/rust/pull/152369
438446 || [ sym:: allow, sym:: deny, sym:: expect, sym:: forbid, sym:: warn]
439447 . contains ( & parts[ 0 ] )
440- {
448+ } ) {
441449 attributes. push ( attr) ;
442450 } else {
443451 dropped_attributes. push ( attr) ;
0 commit comments