@@ -71,12 +71,6 @@ struct CargoToml {
71
71
workspace : Workspace ,
72
72
}
73
73
74
- #[ derive( Default , Debug ) ]
75
- struct LintsAndGroups {
76
- lints : Vec < Spanned < String > > ,
77
- groups : Vec < ( Spanned < String > , Spanned < LintConfig > ) > ,
78
- }
79
-
80
74
fn toml_span ( range : Range < usize > , file : & SourceFile ) -> Span {
81
75
Span :: new (
82
76
file. start_pos + BytePos :: from_usize ( range. start ) ,
@@ -86,69 +80,78 @@ fn toml_span(range: Range<usize>, file: &SourceFile) -> Span {
86
80
)
87
81
}
88
82
89
- fn check_table ( cx : & LateContext < ' _ > , table : LintTable , groups : & FxHashSet < & str > , file : & SourceFile ) {
90
- let mut by_priority = BTreeMap :: < _ , LintsAndGroups > :: new ( ) ;
83
+ fn check_table ( cx : & LateContext < ' _ > , table : LintTable , known_groups : & FxHashSet < & str > , file : & SourceFile ) {
84
+ let mut lints = Vec :: new ( ) ;
85
+ let mut groups = Vec :: new ( ) ;
91
86
for ( name, config) in table {
92
- let lints_and_groups = by_priority. entry ( config. as_ref ( ) . priority ( ) ) . or_default ( ) ;
93
- if groups. contains ( name. get_ref ( ) . as_str ( ) ) {
94
- lints_and_groups. groups . push ( ( name, config) ) ;
87
+ if name. get_ref ( ) == "warnings" {
88
+ continue ;
89
+ }
90
+
91
+ if known_groups. contains ( name. get_ref ( ) . as_str ( ) ) {
92
+ groups. push ( ( name, config) ) ;
95
93
} else {
96
- lints_and_groups . lints . push ( name) ;
94
+ lints. push ( ( name, config . into_inner ( ) ) ) ;
97
95
}
98
96
}
99
- let low_priority = by_priority
100
- . iter ( )
101
- . find ( |( _, lints_and_groups) | !lints_and_groups. lints . is_empty ( ) )
102
- . map_or ( -1 , |( & lowest_lint_priority, _) | lowest_lint_priority - 1 ) ;
103
97
104
- for ( priority, LintsAndGroups { lints, groups } ) in by_priority {
105
- let Some ( last_lint_alphabetically) = lints. last ( ) else {
98
+ for ( group, group_config) in groups {
99
+ let priority = group_config. get_ref ( ) . priority ( ) ;
100
+ let level = group_config. get_ref ( ) . level ( ) ;
101
+ let mut conflicts = lints
102
+ . iter ( )
103
+ . filter ( |( _, lint_config) | lint_config. priority ( ) == priority && lint_config. level ( ) != level) ;
104
+
105
+ let Some ( last_conflict) = conflicts. next_back ( ) else {
106
106
continue ;
107
107
} ;
108
108
109
- for ( group, config) in groups {
110
- span_lint_and_then (
111
- cx,
112
- LINT_GROUPS_PRIORITY ,
113
- toml_span ( group. span ( ) , file) ,
114
- format ! (
115
- "lint group `{}` has the same priority ({priority}) as a lint" ,
116
- group. as_ref( )
117
- ) ,
118
- |diag| {
119
- let config_span = toml_span ( config. span ( ) , file) ;
120
- if config. as_ref ( ) . is_implicit ( ) {
121
- diag. span_label ( config_span, "has an implicit priority of 0" ) ;
122
- }
123
- // add the label to next lint after this group that has the same priority
124
- let lint = lints
125
- . iter ( )
126
- . filter ( |lint| lint. span ( ) . start > group. span ( ) . start )
127
- . min_by_key ( |lint| lint. span ( ) . start )
128
- . unwrap_or ( last_lint_alphabetically) ;
129
- diag. span_label ( toml_span ( lint. span ( ) , file) , "has the same priority as this lint" ) ;
130
- diag. note ( "the order of the lints in the table is ignored by Cargo" ) ;
131
- let mut suggestion = String :: new ( ) ;
132
- Serialize :: serialize (
133
- & LintConfigTable {
134
- level : config. as_ref ( ) . level ( ) . into ( ) ,
135
- priority : Some ( low_priority) ,
136
- } ,
137
- toml:: ser:: ValueSerializer :: new ( & mut suggestion) ,
138
- )
139
- . unwrap ( ) ;
140
- diag. span_suggestion_verbose (
141
- config_span,
142
- format ! (
143
- "to have lints override the group set `{}` to a lower priority" ,
144
- group. as_ref( )
145
- ) ,
146
- suggestion,
147
- Applicability :: MaybeIncorrect ,
148
- ) ;
149
- } ,
150
- ) ;
151
- }
109
+ span_lint_and_then (
110
+ cx,
111
+ LINT_GROUPS_PRIORITY ,
112
+ toml_span ( group. span ( ) , file) ,
113
+ format ! (
114
+ "lint group `{}` has the same priority ({priority}) as a lint" ,
115
+ group. as_ref( )
116
+ ) ,
117
+ |diag| {
118
+ let config_span = toml_span ( group_config. span ( ) , file) ;
119
+
120
+ if group_config. as_ref ( ) . is_implicit ( ) {
121
+ diag. span_label ( config_span, "has an implicit priority of 0" ) ;
122
+ }
123
+ // add the label to next lint after this group that has the same priority
124
+ let ( lint, _) = conflicts
125
+ . find ( |( lint, _) | lint. span ( ) . start > group. span ( ) . start )
126
+ . unwrap_or ( last_conflict) ;
127
+ diag. span_label ( toml_span ( lint. span ( ) , file) , "has the same priority as this lint" ) ;
128
+ diag. note ( "the order of the lints in the table is ignored by Cargo" ) ;
129
+
130
+ let mut suggestion = String :: new ( ) ;
131
+ let low_priority = lints
132
+ . iter ( )
133
+ . map ( |( _, config) | config. priority ( ) . saturating_sub ( 1 ) )
134
+ . min ( )
135
+ . unwrap_or ( -1 ) ;
136
+ Serialize :: serialize (
137
+ & LintConfigTable {
138
+ level : level. into ( ) ,
139
+ priority : Some ( low_priority) ,
140
+ } ,
141
+ toml:: ser:: ValueSerializer :: new ( & mut suggestion) ,
142
+ )
143
+ . unwrap ( ) ;
144
+ diag. span_suggestion_verbose (
145
+ config_span,
146
+ format ! (
147
+ "to have lints override the group set `{}` to a lower priority" ,
148
+ group. as_ref( )
149
+ ) ,
150
+ suggestion,
151
+ Applicability :: MaybeIncorrect ,
152
+ ) ;
153
+ } ,
154
+ ) ;
152
155
}
153
156
}
154
157
0 commit comments