@@ -146,45 +146,48 @@ pub(crate) fn rule_is_ignored(
146146
147147/// A summary of the file-level exemption as extracted from [`FileNoqaDirectives`].
148148#[ derive( Debug ) ]
149- pub ( crate ) enum FileExemption < ' a > {
149+ pub ( crate ) enum FileExemption {
150150 /// The file is exempt from all rules.
151- All ( Vec < & ' a SecondaryCode > ) ,
151+ All ( Vec < Rule > ) ,
152152 /// The file is exempt from the given rules.
153- Codes ( Vec < & ' a SecondaryCode > ) ,
153+ Codes ( Vec < Rule > ) ,
154154}
155155
156- impl FileExemption < ' _ > {
156+ impl FileExemption {
157157 /// Returns `true` if the file is exempt from the given rule, as identified by its noqa code.
158- pub ( crate ) fn contains < T : for < ' a > PartialEq < & ' a str > > ( & self , needle : & T ) -> bool {
158+ pub ( crate ) fn contains_secondary_code ( & self , needle : & SecondaryCode ) -> bool {
159159 match self {
160160 FileExemption :: All ( _) => true ,
161- FileExemption :: Codes ( codes) => codes. iter ( ) . any ( |code| * needle == code) ,
161+ FileExemption :: Codes ( codes) => codes. iter ( ) . any ( |code| * needle == code. noqa_code ( ) ) ,
162162 }
163163 }
164164
165165 /// Returns `true` if the file is exempt from the given rule.
166166 pub ( crate ) fn includes ( & self , needle : Rule ) -> bool {
167- self . contains ( & needle. noqa_code ( ) )
167+ match self {
168+ FileExemption :: All ( _) => true ,
169+ FileExemption :: Codes ( codes) => codes. contains ( & needle) ,
170+ }
168171 }
169172
170173 /// Returns `true` if the file exemption lists the rule directly, rather than via a blanket
171174 /// exemption.
172175 pub ( crate ) fn enumerates ( & self , needle : Rule ) -> bool {
173- let needle = needle. noqa_code ( ) ;
174176 let codes = match self {
175177 FileExemption :: All ( codes) => codes,
176178 FileExemption :: Codes ( codes) => codes,
177179 } ;
178- codes. iter ( ) . any ( |code| needle == * * code )
180+ codes. contains ( & needle)
179181 }
180182}
181183
182- impl < ' a > From < & ' a FileNoqaDirectives < ' a > > for FileExemption < ' a > {
184+ impl < ' a > From < & ' a FileNoqaDirectives < ' a > > for FileExemption {
183185 fn from ( directives : & ' a FileNoqaDirectives ) -> Self {
184186 let codes = directives
185187 . lines ( )
186188 . iter ( )
187189 . flat_map ( |line| & line. matches )
190+ . copied ( )
188191 . collect ( ) ;
189192 if directives
190193 . lines ( )
@@ -206,7 +209,7 @@ pub(crate) struct FileNoqaDirectiveLine<'a> {
206209 /// The blanket noqa directive.
207210 pub ( crate ) parsed_file_exemption : Directive < ' a > ,
208211 /// The codes that are ignored by the parsed exemptions.
209- pub ( crate ) matches : Vec < SecondaryCode > ,
212+ pub ( crate ) matches : Vec < Rule > ,
210213}
211214
212215impl Ranged for FileNoqaDirectiveLine < ' _ > {
@@ -271,9 +274,9 @@ impl<'a> FileNoqaDirectives<'a> {
271274 return None ;
272275 }
273276
274- if Rule :: from_code ( get_redirect_target ( code) . unwrap_or ( code) ) . is_ok ( )
277+ if let Ok ( rule ) = Rule :: from_code ( get_redirect_target ( code) . unwrap_or ( code) )
275278 {
276- Some ( SecondaryCode :: new ( code . to_string ( ) ) )
279+ Some ( rule )
277280 } else {
278281 #[ expect( deprecated) ]
279282 let line = locator. compute_line_index ( range. start ( ) ) ;
@@ -854,7 +857,7 @@ fn find_noqa_comments<'a>(
854857 continue ;
855858 } ;
856859
857- if exemption. contains ( code) {
860+ if exemption. contains_secondary_code ( code) {
858861 comments_by_line. push ( None ) ;
859862 continue ;
860863 }
@@ -1010,7 +1013,7 @@ pub(crate) struct NoqaDirectiveLine<'a> {
10101013 /// The noqa directive.
10111014 pub ( crate ) directive : Directive < ' a > ,
10121015 /// The codes that are ignored by the directive.
1013- pub ( crate ) matches : Vec < SecondaryCode > ,
1016+ pub ( crate ) matches : Vec < Rule > ,
10141017 /// Whether the directive applies to `range.end`.
10151018 pub ( crate ) includes_end : bool ,
10161019}
0 commit comments