@@ -43,17 +43,16 @@ fn generate_lint_files(
43
43
deprecated_lints : & [ DeprecatedLint ] ,
44
44
renamed_lints : & [ RenamedLint ] ,
45
45
) {
46
- let internal_lints = Lint :: internal_lints ( lints) ;
47
- let mut usable_lints = Lint :: usable_lints ( lints) ;
48
- usable_lints. sort_by_key ( |lint| lint. name . clone ( ) ) ;
46
+ let mut lints = lints. to_owned ( ) ;
47
+ lints. sort_by_key ( |lint| lint. name . clone ( ) ) ;
49
48
50
49
replace_region_in_file (
51
50
update_mode,
52
51
Path :: new ( "README.md" ) ,
53
52
"[There are over " ,
54
53
" lints included in this crate!]" ,
55
54
|res| {
56
- write ! ( res, "{}" , round_to_fifty( usable_lints . len( ) ) ) . unwrap ( ) ;
55
+ write ! ( res, "{}" , round_to_fifty( lints . len( ) ) ) . unwrap ( ) ;
57
56
} ,
58
57
) ;
59
58
@@ -63,7 +62,7 @@ fn generate_lint_files(
63
62
"[There are over " ,
64
63
" lints included in this crate!]" ,
65
64
|res| {
66
- write ! ( res, "{}" , round_to_fifty( usable_lints . len( ) ) ) . unwrap ( ) ;
65
+ write ! ( res, "{}" , round_to_fifty( lints . len( ) ) ) . unwrap ( ) ;
67
66
} ,
68
67
) ;
69
68
@@ -73,7 +72,7 @@ fn generate_lint_files(
73
72
"<!-- begin autogenerated links to lint list -->\n " ,
74
73
"<!-- end autogenerated links to lint list -->" ,
75
74
|res| {
76
- for lint in usable_lints
75
+ for lint in lints
77
76
. iter ( )
78
77
. map ( |l| & * l. name )
79
78
. chain ( deprecated_lints. iter ( ) . filter_map ( |l| l. name . strip_prefix ( "clippy::" ) ) )
@@ -92,7 +91,7 @@ fn generate_lint_files(
92
91
"// begin lints modules, do not remove this comment, it’s used in `update_lints`\n " ,
93
92
"// end lints modules, do not remove this comment, it’s used in `update_lints`" ,
94
93
|res| {
95
- for lint_mod in usable_lints . iter ( ) . map ( |l| & l. module ) . unique ( ) . sorted ( ) {
94
+ for lint_mod in lints . iter ( ) . map ( |l| & l. module ) . unique ( ) . sorted ( ) {
96
95
writeln ! ( res, "mod {lint_mod};" ) . unwrap ( ) ;
97
96
}
98
97
} ,
@@ -101,7 +100,7 @@ fn generate_lint_files(
101
100
process_file (
102
101
"clippy_lints/src/declared_lints.rs" ,
103
102
update_mode,
104
- & gen_declared_lints ( internal_lints . iter ( ) , usable_lints . iter ( ) ) ,
103
+ & gen_declared_lints ( lints . iter ( ) ) ,
105
104
) ;
106
105
107
106
let content = gen_deprecated_lints_test ( deprecated_lints) ;
@@ -112,10 +111,9 @@ fn generate_lint_files(
112
111
}
113
112
114
113
pub fn print_lints ( ) {
115
- let ( lint_list, _, _) = gather_all ( ) ;
116
- let usable_lints = Lint :: usable_lints ( & lint_list) ;
117
- let usable_lint_count = usable_lints. len ( ) ;
118
- let grouped_by_lint_group = Lint :: by_lint_group ( usable_lints. into_iter ( ) ) ;
114
+ let ( lints, _, _) = gather_all ( ) ;
115
+ let lint_count = lints. len ( ) ;
116
+ let grouped_by_lint_group = Lint :: by_lint_group ( lints. into_iter ( ) ) ;
119
117
120
118
for ( lint_group, mut lints) in grouped_by_lint_group {
121
119
println ! ( "\n ## {lint_group}" ) ;
@@ -127,7 +125,7 @@ pub fn print_lints() {
127
125
}
128
126
}
129
127
130
- println ! ( "there are {usable_lint_count } lints" ) ;
128
+ println ! ( "there are {lint_count } lints" ) ;
131
129
}
132
130
133
131
/// Runs the `rename_lint` command.
@@ -191,11 +189,14 @@ pub fn rename(old_name: &str, new_name: &str, uplift: bool) {
191
189
. into_iter ( )
192
190
. map ( Result :: unwrap)
193
191
. filter ( |f| {
194
- let name = f. path ( ) . file_name ( ) ;
195
- let ext = f. path ( ) . extension ( ) ;
196
- ( ext == Some ( OsStr :: new ( "rs" ) ) || ext == Some ( OsStr :: new ( "fixed" ) ) )
197
- && name != Some ( OsStr :: new ( "rename.rs" ) )
198
- && name != Some ( OsStr :: new ( "deprecated_lints.rs" ) )
192
+ let path = f. path ( ) ;
193
+ path. extension ( ) . is_some_and ( |ext| ext == "rs" || ext == "fixed" )
194
+ && !( path. file_name ( ) . is_some_and ( |n| n == "lib.rs" )
195
+ && path
196
+ . parent ( )
197
+ . and_then ( |p| p. parent ( ) )
198
+ . and_then ( |p| p. file_name ( ) )
199
+ . is_some_and ( |name| name == "clippy_deprecated_lints" ) )
199
200
} )
200
201
{
201
202
rewrite_file ( file. path ( ) , |s| {
@@ -204,7 +205,7 @@ pub fn rename(old_name: &str, new_name: &str, uplift: bool) {
204
205
}
205
206
206
207
let version = crate :: new_lint:: get_stabilization_version ( ) ;
207
- rewrite_file ( Path :: new ( "clippy_lints /src/deprecated_lints .rs" ) , |s| {
208
+ rewrite_file ( Path :: new ( "clippy_deprecated_lints /src/lib .rs" ) , |s| {
208
209
insert_at_marker (
209
210
s,
210
211
"// end renamed lints. used by `cargo dev rename_lint`" ,
@@ -289,10 +290,7 @@ pub fn rename(old_name: &str, new_name: &str, uplift: bool) {
289
290
& replacements[ 0 ..1 ]
290
291
} ;
291
292
292
- // Don't change `clippy_utils/src/renamed_lints.rs` here as it would try to edit the lint being
293
- // renamed.
294
- for ( _, file) in clippy_lints_src_files ( ) . filter ( |( rel_path, _) | rel_path != OsStr :: new ( "deprecated_lints.rs" ) )
295
- {
293
+ for ( _, file) in clippy_lints_src_files ( ) {
296
294
rewrite_file ( file. path ( ) , |s| replace_ident_like ( s, replacements) ) ;
297
295
}
298
296
@@ -306,7 +304,7 @@ pub fn rename(old_name: &str, new_name: &str, uplift: bool) {
306
304
/// Runs the `deprecate` command
307
305
///
308
306
/// This does the following:
309
- /// * Adds an entry to `deprecated_lints .rs`.
307
+ /// * Adds an entry to `clippy_deprecated_lints/src/lib .rs`.
310
308
/// * Removes the lint declaration (and the entire file if applicable)
311
309
///
312
310
/// # Panics
@@ -336,7 +334,7 @@ pub fn deprecate(name: &str, reason: &str) {
336
334
mod_path
337
335
} ;
338
336
339
- let deprecated_lints_path = & * clippy_project_root ( ) . join ( "clippy_lints /src/deprecated_lints .rs" ) ;
337
+ let deprecated_lints_path = & * clippy_project_root ( ) . join ( "clippy_deprecated_lints /src/lib .rs" ) ;
340
338
341
339
if remove_lint_declaration ( stripped_name, & mod_path, & mut lints) . unwrap_or ( false ) {
342
340
let version = crate :: new_lint:: get_stabilization_version ( ) ;
@@ -541,22 +539,6 @@ impl Lint {
541
539
}
542
540
}
543
541
544
- /// Returns all non-deprecated lints and non-internal lints
545
- #[ must_use]
546
- fn usable_lints ( lints : & [ Self ] ) -> Vec < Self > {
547
- lints
548
- . iter ( )
549
- . filter ( |l| !l. group . starts_with ( "internal" ) )
550
- . cloned ( )
551
- . collect ( )
552
- }
553
-
554
- /// Returns all internal lints
555
- #[ must_use]
556
- fn internal_lints ( lints : & [ Self ] ) -> Vec < Self > {
557
- lints. iter ( ) . filter ( |l| l. group == "internal" ) . cloned ( ) . collect ( )
558
- }
559
-
560
542
/// Returns the lints in a `HashMap`, grouped by the different lint groups
561
543
#[ must_use]
562
544
fn by_lint_group ( lints : impl Iterator < Item = Self > ) -> HashMap < String , Vec < Self > > {
@@ -593,23 +575,14 @@ impl RenamedLint {
593
575
594
576
/// Generates the code for registering lints
595
577
#[ must_use]
596
- fn gen_declared_lints < ' a > (
597
- internal_lints : impl Iterator < Item = & ' a Lint > ,
598
- usable_lints : impl Iterator < Item = & ' a Lint > ,
599
- ) -> String {
600
- let mut details: Vec < _ > = internal_lints
601
- . map ( |l| ( false , & l. module , l. name . to_uppercase ( ) ) )
602
- . chain ( usable_lints. map ( |l| ( true , & l. module , l. name . to_uppercase ( ) ) ) )
603
- . collect ( ) ;
578
+ fn gen_declared_lints < ' a > ( lints : impl Iterator < Item = & ' a Lint > ) -> String {
579
+ let mut details: Vec < _ > = lints. map ( |l| ( & l. module , l. name . to_uppercase ( ) ) ) . collect ( ) ;
604
580
details. sort_unstable ( ) ;
605
581
606
582
let mut output = GENERATED_FILE_COMMENT . to_string ( ) ;
607
583
output. push_str ( "pub(crate) static LINTS: &[&crate::LintInfo] = &[\n " ) ;
608
584
609
- for ( is_public, module_name, lint_name) in details {
610
- if !is_public {
611
- output. push_str ( " #[cfg(feature = \" internal\" )]\n " ) ;
612
- }
585
+ for ( module_name, lint_name) in details {
613
586
let _: fmt:: Result = writeln ! ( output, " crate::{module_name}::{lint_name}_INFO," ) ;
614
587
}
615
588
output. push_str ( "];\n " ) ;
@@ -669,13 +642,12 @@ fn gather_all() -> (Vec<Lint>, Vec<DeprecatedLint>, Vec<RenamedLint>) {
669
642
} else {
670
643
module. strip_suffix ( ".rs" ) . unwrap_or ( & module)
671
644
} ;
672
-
673
- if module == "deprecated_lints" {
674
- parse_deprecated_contents ( & contents, & mut deprecated_lints, & mut renamed_lints) ;
675
- } else {
676
- parse_contents ( & contents, module, & mut lints) ;
677
- }
645
+ parse_contents ( & contents, module, & mut lints) ;
678
646
}
647
+ let contents = fs:: read_to_string ( clippy_project_root ( ) . join ( "clippy_deprecated_lints/src/lib.rs" ) )
648
+ . unwrap_or_else ( |e| panic ! ( "Cannot read from `clippy_deprecated_lints/src/lib.rs`: {e}" ) ) ;
649
+ parse_deprecated_contents ( & contents, & mut deprecated_lints, & mut renamed_lints) ;
650
+
679
651
( lints, deprecated_lints, renamed_lints)
680
652
}
681
653
@@ -999,41 +971,6 @@ mod tests {
999
971
assert_eq ! ( expected, result) ;
1000
972
}
1001
973
1002
- #[ test]
1003
- fn test_usable_lints ( ) {
1004
- let lints = vec ! [
1005
- Lint :: new(
1006
- "should_assert_eq2" ,
1007
- "Not Deprecated" ,
1008
- "\" abc\" " ,
1009
- "module_name" ,
1010
- Range :: default ( ) ,
1011
- ) ,
1012
- Lint :: new(
1013
- "should_assert_eq2" ,
1014
- "internal" ,
1015
- "\" abc\" " ,
1016
- "module_name" ,
1017
- Range :: default ( ) ,
1018
- ) ,
1019
- Lint :: new(
1020
- "should_assert_eq2" ,
1021
- "internal_style" ,
1022
- "\" abc\" " ,
1023
- "module_name" ,
1024
- Range :: default ( ) ,
1025
- ) ,
1026
- ] ;
1027
- let expected = vec ! [ Lint :: new(
1028
- "should_assert_eq2" ,
1029
- "Not Deprecated" ,
1030
- "\" abc\" " ,
1031
- "module_name" ,
1032
- Range :: default ( ) ,
1033
- ) ] ;
1034
- assert_eq ! ( expected, Lint :: usable_lints( & lints) ) ;
1035
- }
1036
-
1037
974
#[ test]
1038
975
fn test_by_lint_group ( ) {
1039
976
let lints = vec ! [
0 commit comments