@@ -402,53 +402,53 @@ fn remove_lint_declaration(name: &str, path: &Path, lints: &mut Vec<Lint>) -> io
402402 }
403403 }
404404
405- if path. exists ( ) {
406- if let Some ( lint) = lints. iter ( ) . find ( |l| l. name == name) {
407- if lint. module == name {
408- // The lint name is the same as the file, we can just delete the entire file
409- fs:: remove_file ( path) ?;
410- } else {
411- // We can't delete the entire file, just remove the declaration
412-
413- if let Some ( Some ( "mod.rs" ) ) = path. file_name ( ) . map ( OsStr :: to_str) {
414- // Remove clippy_lints/src/some_mod/some_lint.rs
415- let mut lint_mod_path = path. to_path_buf ( ) ;
416- lint_mod_path. set_file_name ( name) ;
417- lint_mod_path. set_extension ( "rs" ) ;
405+ if path. exists ( )
406+ && let Some ( lint) = lints. iter ( ) . find ( |l| l. name == name)
407+ {
408+ if lint. module == name {
409+ // The lint name is the same as the file, we can just delete the entire file
410+ fs:: remove_file ( path) ?;
411+ } else {
412+ // We can't delete the entire file, just remove the declaration
418413
419- let _ = fs:: remove_file ( lint_mod_path) ;
420- }
414+ if let Some ( Some ( "mod.rs" ) ) = path. file_name ( ) . map ( OsStr :: to_str) {
415+ // Remove clippy_lints/src/some_mod/some_lint.rs
416+ let mut lint_mod_path = path. to_path_buf ( ) ;
417+ lint_mod_path. set_file_name ( name) ;
418+ lint_mod_path. set_extension ( "rs" ) ;
421419
422- let mut content =
423- fs :: read_to_string ( path ) . unwrap_or_else ( |_| panic ! ( "failed to read `{}`" , path . to_string_lossy ( ) ) ) ;
420+ let _ = fs :: remove_file ( lint_mod_path ) ;
421+ }
424422
425- eprintln ! (
426- "warn: you will have to manually remove any code related to `{name}` from `{}`" ,
427- path. display( )
428- ) ;
423+ let mut content =
424+ fs:: read_to_string ( path) . unwrap_or_else ( |_| panic ! ( "failed to read `{}`" , path. to_string_lossy( ) ) ) ;
429425
430- assert ! (
431- content[ lint. declaration_range. clone( ) ] . contains( & name. to_uppercase( ) ) ,
432- "error: `{}` does not contain lint `{}`'s declaration" ,
433- path. display( ) ,
434- lint. name
435- ) ;
426+ eprintln ! (
427+ "warn: you will have to manually remove any code related to `{name}` from `{}`" ,
428+ path. display( )
429+ ) ;
436430
437- // Remove lint declaration (declare_clippy_lint!)
438- content. replace_range ( lint. declaration_range . clone ( ) , "" ) ;
431+ assert ! (
432+ content[ lint. declaration_range. clone( ) ] . contains( & name. to_uppercase( ) ) ,
433+ "error: `{}` does not contain lint `{}`'s declaration" ,
434+ path. display( ) ,
435+ lint. name
436+ ) ;
439437
440- // Remove the module declaration (mod xyz;)
441- let mod_decl = format ! ( "\n mod {name};" ) ;
442- content = content. replacen ( & mod_decl, "" , 1 ) ;
438+ // Remove lint declaration (declare_clippy_lint!)
439+ content. replace_range ( lint. declaration_range . clone ( ) , "" ) ;
443440
444- remove_impl_lint_pass ( & lint . name . to_uppercase ( ) , & mut content ) ;
445- fs :: write ( path , content ) . unwrap_or_else ( |_| panic ! ( "failed to write to `{}`" , path . to_string_lossy ( ) ) ) ;
446- }
441+ // Remove the module declaration (mod xyz;)
442+ let mod_decl = format ! ( "\n mod {name};" ) ;
443+ content = content . replacen ( & mod_decl , "" , 1 ) ;
447444
448- remove_test_assets ( name) ;
449- remove_lint ( name, lints) ;
450- return Ok ( true ) ;
445+ remove_impl_lint_pass ( & lint. name . to_uppercase ( ) , & mut content) ;
446+ fs:: write ( path, content) . unwrap_or_else ( |_| panic ! ( "failed to write to `{}`" , path. to_string_lossy( ) ) ) ;
451447 }
448+
449+ remove_test_assets ( name) ;
450+ remove_lint ( name, lints) ;
451+ return Ok ( true ) ;
452452 }
453453
454454 Ok ( false )
0 commit comments