@@ -245,11 +245,13 @@ pub fn rename(old_name: &str, new_name: &str, uplift: bool) {
245
245
new_name
246
246
) ;
247
247
} else {
248
- // Rename the lint struct and the containing module if it shares the lint name across all files .
248
+ // Rename the lint struct and source files sharing a name with the lint.
249
249
let lint = & mut lints[ old_lint_index] ;
250
250
let old_name_upper = old_name. to_uppercase ( ) ;
251
251
let new_name_upper = new_name. to_uppercase ( ) ;
252
+ lint. name = new_name. into ( ) ;
252
253
254
+ // Rename test files. only rename `.stderr` and `.fixed` files if the new test name doesn't exist.
253
255
if try_rename_file (
254
256
Path :: new ( & format ! ( "tests/ui/{}.rs" , old_name) ) ,
255
257
Path :: new ( & format ! ( "tests/ui/{}.rs" , new_name) ) ,
@@ -264,30 +266,41 @@ pub fn rename(old_name: &str, new_name: &str, uplift: bool) {
264
266
) ;
265
267
}
266
268
269
+ // Try to rename the file containing the lint if the file name matches the lint's name.
267
270
let replacements;
268
- let replacements = if lint. module == lint . name
271
+ let replacements = if lint. module == old_name
269
272
&& try_rename_file (
270
273
Path :: new ( & format ! ( "clippy_lints/src/{}.rs" , old_name) ) ,
271
274
Path :: new ( & format ! ( "clippy_lints/src/{}.rs" , new_name) ) ,
272
275
) {
273
- lint. module = new_name. into ( ) ;
276
+ // Edit the module name in the lint list. Note there could be multiple lints.
277
+ for lint in lints. iter_mut ( ) . filter ( |l| l. module == old_name) {
278
+ lint. module = new_name. into ( ) ;
279
+ }
274
280
replacements = [ ( & * old_name_upper, & * new_name_upper) , ( old_name, new_name) ] ;
275
281
replacements. as_slice ( )
276
282
} else if !lint. module . contains ( "::" )
283
+ // Catch cases like `methods/lint_name.rs` where the lint is stored in `methods/mod.rs`
277
284
&& try_rename_file (
278
285
Path :: new ( & format ! ( "clippy_lints/src/{}/{}.rs" , lint. module, old_name) ) ,
279
286
Path :: new ( & format ! ( "clippy_lints/src/{}/{}.rs" , lint. module, new_name) ) ,
280
287
)
281
288
{
289
+ // Edit the module name in the lint list. Note there could be multiple lints, or none.
290
+ let renamed_mod = format ! ( "{}::{}" , lint. module, old_name) ;
291
+ for lint in lints. iter_mut ( ) . filter ( |l| l. module == renamed_mod) {
292
+ lint. module = format ! ( "{}::{}" , lint. module, new_name) ;
293
+ }
282
294
replacements = [ ( & * old_name_upper, & * new_name_upper) , ( old_name, new_name) ] ;
283
295
replacements. as_slice ( )
284
296
} else {
285
297
replacements = [ ( & * old_name_upper, & * new_name_upper) , ( "" , "" ) ] ;
286
298
& replacements[ 0 ..1 ]
287
299
} ;
288
- lint. name = new_name. into ( ) ;
289
300
290
- for ( _, file) in clippy_lints_src_files ( ) {
301
+ // Don't change `clippy_utils/src/renamed_lints.rs` here as it would try to edit the lint being
302
+ // renamed.
303
+ for ( _, file) in clippy_lints_src_files ( ) . filter ( |( rel_path, _) | rel_path != OsStr :: new ( "renamed_lints.rs" ) ) {
291
304
rewrite_file ( file. path ( ) , |s| replace_ident_like ( s, replacements) ) ;
292
305
}
293
306
0 commit comments