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} ;
4
2
use crate :: utils:: { UpdateMode , Version } ;
5
3
use std:: ffi:: OsStr ;
6
4
use std:: path:: { Path , PathBuf } ;
@@ -16,28 +14,34 @@ use std::{fs, io};
16
14
///
17
15
/// If a file path could not read from or written to
18
16
pub 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
+ }
25
20
26
21
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 {
37
25
eprintln ! ( "error: failed to find lint `{name}`" ) ;
38
26
return ;
39
27
} ;
40
28
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
+
41
45
let mod_path = {
42
46
let mut mod_path = PathBuf :: from ( format ! ( "clippy_lints/src/{}" , lint. module) ) ;
43
47
if mod_path. is_dir ( ) {
@@ -48,24 +52,7 @@ pub fn deprecate(clippy_version: Version, name: &str, reason: &str) {
48
52
mod_path
49
53
} ;
50
54
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 ) {
69
56
generate_lint_files ( UpdateMode :: Change , & lints, & deprecated_lints, & renamed_lints) ;
70
57
println ! ( "info: `{name}` has successfully been deprecated" ) ;
71
58
println ! ( "note: you must run `cargo uitest` to update the test results" ) ;
0 commit comments