@@ -25,6 +25,7 @@ use crate::checkers::tokens::check_tokens;
2525use crate :: directives:: Directives ;
2626use crate :: doc_lines:: { doc_lines_from_ast, doc_lines_from_tokens} ;
2727use crate :: fix:: { FixResult , fix_file} ;
28+ use crate :: message:: SecondaryCode ;
2829use crate :: noqa:: add_noqa;
2930use crate :: package:: PackageRoot ;
3031use crate :: preview:: is_py314_support_enabled;
@@ -93,25 +94,25 @@ struct FixCount {
9394
9495/// A mapping from a noqa code to the corresponding lint name and a count of applied fixes.
9596#[ derive( Debug , Default , PartialEq ) ]
96- pub struct FixTable ( hashbrown:: HashMap < String , FixCount , rustc_hash:: FxBuildHasher > ) ;
97+ pub struct FixTable ( hashbrown:: HashMap < SecondaryCode , FixCount , rustc_hash:: FxBuildHasher > ) ;
9798
9899impl FixTable {
99100 pub fn counts ( & self ) -> impl Iterator < Item = usize > {
100101 self . 0 . values ( ) . map ( |fc| fc. count )
101102 }
102103
103- pub fn entry < ' a > ( & ' a mut self , code : & ' a str ) -> FixTableEntry < ' a > {
104+ pub fn entry < ' a > ( & ' a mut self , code : & ' a SecondaryCode ) -> FixTableEntry < ' a > {
104105 FixTableEntry ( self . 0 . entry_ref ( code) )
105106 }
106107
107- pub fn iter ( & self ) -> impl Iterator < Item = ( & str , & ' static str , usize ) > {
108+ pub fn iter ( & self ) -> impl Iterator < Item = ( & SecondaryCode , & ' static str , usize ) > {
108109 self . 0
109110 . iter ( )
110- . map ( |( code, FixCount { rule_name, count } ) | ( code. as_str ( ) , * rule_name, * count) )
111+ . map ( |( code, FixCount { rule_name, count } ) | ( code, * rule_name, * count) )
111112 }
112113
113- pub fn keys ( & self ) -> impl Iterator < Item = & str > {
114- self . 0 . keys ( ) . map ( String :: as_str )
114+ pub fn keys ( & self ) -> impl Iterator < Item = & SecondaryCode > {
115+ self . 0 . keys ( )
115116 }
116117
117118 pub fn is_empty ( & self ) -> bool {
@@ -120,7 +121,7 @@ impl FixTable {
120121}
121122
122123pub struct FixTableEntry < ' a > (
123- hashbrown:: hash_map:: EntryRef < ' a , ' a , String , str , FixCount , FxBuildHasher > ,
124+ hashbrown:: hash_map:: EntryRef < ' a , ' a , SecondaryCode , SecondaryCode , FixCount , FxBuildHasher > ,
124125) ;
125126
126127impl < ' a > FixTableEntry < ' a > {
@@ -678,7 +679,10 @@ pub fn lint_fix<'a>(
678679 }
679680}
680681
681- fn collect_rule_codes < ' a > ( rules : impl IntoIterator < Item = & ' a str > ) -> String {
682+ fn collect_rule_codes < T > ( rules : impl IntoIterator < Item = T > ) -> String
683+ where
684+ T : Ord + PartialEq + std:: fmt:: Display ,
685+ {
682686 rules. into_iter ( ) . sorted_unstable ( ) . dedup ( ) . join ( ", " )
683687}
684688
@@ -720,7 +724,7 @@ fn report_fix_syntax_error<'a>(
720724 path : & Path ,
721725 transformed : & str ,
722726 error : & ParseError ,
723- rules : impl IntoIterator < Item = & ' a str > ,
727+ rules : impl IntoIterator < Item = & ' a SecondaryCode > ,
724728) {
725729 let codes = collect_rule_codes ( rules) ;
726730 if cfg ! ( debug_assertions) {
0 commit comments