1- use  crate :: update_lints:: { 
2-     DeprecatedLint ,  DeprecatedLints ,  Lint ,  find_lint_decls,  generate_lint_files,  read_deprecated_lints, 
3- } ; 
1+ use  crate :: update_lints:: { DeprecatedLint ,  Lint ,  find_lint_decls,  generate_lint_files,  read_deprecated_lints} ; 
42use  crate :: utils:: { UpdateMode ,  Version } ; 
53use  std:: ffi:: OsStr ; 
64use  std:: path:: { Path ,  PathBuf } ; 
@@ -16,28 +14,34 @@ use std::{fs, io};
1614/// 
1715/// If a file path could not read from or written to 
1816pub  fn  deprecate ( clippy_version :  Version ,  name :  & str ,  reason :  & str )  { 
19-     let  prefixed_name = if  name. starts_with ( "clippy::" )  { 
20-         name. to_owned ( ) 
21-     }  else  { 
22-         format ! ( "clippy::{name}" ) 
23-     } ; 
24-     let  stripped_name = & prefixed_name[ 8 ..] ; 
17+     if  let  Some ( ( prefix,  _) )  = name. split_once ( "::" )  { 
18+         panic ! ( "`{name}` should not contain the `{prefix}` prefix" ) ; 
19+     } 
2520
2621    let  mut  lints = find_lint_decls ( ) ; 
27-     let  DeprecatedLints  { 
28-         renamed :  renamed_lints, 
29-         deprecated :  mut  deprecated_lints, 
30-         file :  mut  deprecated_file, 
31-         contents :  mut  deprecated_contents, 
32-         deprecated_end, 
33-         ..
34-     }  = read_deprecated_lints ( ) ; 
35- 
36-     let  Some ( lint)  = lints. iter ( ) . find ( |l| l. name  == stripped_name)  else  { 
22+     let  ( mut  deprecated_lints,  renamed_lints)  = read_deprecated_lints ( ) ; 
23+ 
24+     let  Some ( lint)  = lints. iter ( ) . find ( |l| l. name  == name)  else  { 
3725        eprintln ! ( "error: failed to find lint `{name}`" ) ; 
3826        return ; 
3927    } ; 
4028
29+     let  prefixed_name = String :: from_iter ( [ "clippy::" ,  name] ) ; 
30+     match  deprecated_lints. binary_search_by ( |x| x. name . cmp ( & prefixed_name) )  { 
31+         Ok ( _)  => { 
32+             println ! ( "`{name}` is already deprecated" ) ; 
33+             return ; 
34+         } , 
35+         Err ( idx)  => deprecated_lints. insert ( 
36+             idx, 
37+             DeprecatedLint  { 
38+                 name :  prefixed_name, 
39+                 reason :  reason. into ( ) , 
40+                 version :  clippy_version. rust_display ( ) . to_string ( ) , 
41+             } , 
42+         ) , 
43+     } 
44+ 
4145    let  mod_path = { 
4246        let  mut  mod_path = PathBuf :: from ( format ! ( "clippy_lints/src/{}" ,  lint. module) ) ; 
4347        if  mod_path. is_dir ( )  { 
@@ -48,24 +52,7 @@ pub fn deprecate(clippy_version: Version, name: &str, reason: &str) {
4852        mod_path
4953    } ; 
5054
51-     if  remove_lint_declaration ( stripped_name,  & mod_path,  & mut  lints) . unwrap_or ( false )  { 
52-         deprecated_contents. insert_str ( 
53-             deprecated_end as  usize , 
54-             & format ! ( 
55-                 "    #[clippy::version = \" {}\" ]\n     (\" {}\" , \" {}\" ),\n " , 
56-                 clippy_version. rust_display( ) , 
57-                 prefixed_name, 
58-                 reason, 
59-             ) , 
60-         ) ; 
61-         deprecated_file. replace_contents ( deprecated_contents. as_bytes ( ) ) ; 
62-         drop ( deprecated_file) ; 
63- 
64-         deprecated_lints. push ( DeprecatedLint  { 
65-             name :  prefixed_name, 
66-             reason :  reason. into ( ) , 
67-         } ) ; 
68- 
55+     if  remove_lint_declaration ( name,  & mod_path,  & mut  lints) . unwrap_or ( false )  { 
6956        generate_lint_files ( UpdateMode :: Change ,  & lints,  & deprecated_lints,  & renamed_lints) ; 
7057        println ! ( "info: `{name}` has successfully been deprecated" ) ; 
7158        println ! ( "note: you must run `cargo uitest` to update the test results" ) ; 
0 commit comments