@@ -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 ( ) ) ;
@@ -306,6 +309,10 @@ impl<'a> FileNoqaDirectives<'a> {
306309 pub ( crate ) fn lines ( & self ) -> & [ FileNoqaDirectiveLine ] {
307310 & self . 0
308311 }
312+
313+ pub ( crate ) fn is_empty ( & self ) -> bool {
314+ self . 0 . is_empty ( )
315+ }
309316}
310317
311318/// Output of lexing a `noqa` directive.
@@ -854,7 +861,7 @@ fn find_noqa_comments<'a>(
854861 continue ;
855862 } ;
856863
857- if exemption. contains ( code) {
864+ if exemption. contains_secondary_code ( code) {
858865 comments_by_line. push ( None ) ;
859866 continue ;
860867 }
@@ -1010,7 +1017,7 @@ pub(crate) struct NoqaDirectiveLine<'a> {
10101017 /// The noqa directive.
10111018 pub ( crate ) directive : Directive < ' a > ,
10121019 /// The codes that are ignored by the directive.
1013- pub ( crate ) matches : Vec < SecondaryCode > ,
1020+ pub ( crate ) matches : Vec < Rule > ,
10141021 /// Whether the directive applies to `range.end`.
10151022 pub ( crate ) includes_end : bool ,
10161023}
@@ -1135,6 +1142,10 @@ impl<'a> NoqaDirectives<'a> {
11351142 pub ( crate ) fn lines ( & self ) -> & [ NoqaDirectiveLine ] {
11361143 & self . inner
11371144 }
1145+
1146+ pub ( crate ) fn is_empty ( & self ) -> bool {
1147+ self . inner . is_empty ( )
1148+ }
11381149}
11391150
11401151/// Remaps offsets falling into one of the ranges to instead check for a noqa comment on the
0 commit comments