@@ -62,13 +62,25 @@ impl Lint {
62
62
}
63
63
64
64
/// Returns all non-deprecated lints and non-internal lints
65
- pub fn usable_lints ( lints : impl Iterator < Item = Self > ) -> impl Iterator < Item = Self > {
66
- lints. filter ( |l| l. deprecation . is_none ( ) && !l. group . starts_with ( "internal" ) )
65
+ #[ must_use]
66
+ pub fn usable_lints ( lints : & [ Self ] ) -> Vec < Self > {
67
+ lints
68
+ . iter ( )
69
+ . filter ( |l| l. deprecation . is_none ( ) && !l. group . starts_with ( "internal" ) )
70
+ . cloned ( )
71
+ . collect ( )
67
72
}
68
73
69
74
/// Returns all internal lints (not `internal_warn` lints)
70
- pub fn internal_lints ( lints : impl Iterator < Item = Self > ) -> impl Iterator < Item = Self > {
71
- lints. filter ( |l| l. group == "internal" )
75
+ #[ must_use]
76
+ pub fn internal_lints ( lints : & [ Self ] ) -> Vec < Self > {
77
+ lints. iter ( ) . filter ( |l| l. group == "internal" ) . cloned ( ) . collect ( )
78
+ }
79
+
80
+ /// Returns all deprecated lints
81
+ #[ must_use]
82
+ pub fn deprecated_lints ( lints : & [ Self ] ) -> Vec < Self > {
83
+ lints. iter ( ) . filter ( |l| l. deprecation . is_some ( ) ) . cloned ( ) . collect ( )
72
84
}
73
85
74
86
/// Returns the lints in a `HashMap`, grouped by the different lint groups
@@ -80,9 +92,8 @@ impl Lint {
80
92
81
93
/// Generates the Vec items for `register_lint_group` calls in `clippy_lints/src/lib.rs`.
82
94
#[ must_use]
83
- pub fn gen_lint_group_list ( lints : & [ Lint ] ) -> Vec < String > {
95
+ pub fn gen_lint_group_list < ' a > ( lints : impl Iterator < Item = & ' a Lint > ) -> Vec < String > {
84
96
lints
85
- . into_iter ( )
86
97
. filter_map ( |l| {
87
98
if l. deprecation . is_some ( ) {
88
99
None
@@ -96,9 +107,8 @@ pub fn gen_lint_group_list(lints: &[Lint]) -> Vec<String> {
96
107
97
108
/// Generates the `pub mod module_name` list in `clippy_lints/src/lib.rs`.
98
109
#[ must_use]
99
- pub fn gen_modules_list ( lints : & [ Lint ] ) -> Vec < String > {
110
+ pub fn gen_modules_list < ' a > ( lints : impl Iterator < Item = & ' a Lint > ) -> Vec < String > {
100
111
lints
101
- . iter ( )
102
112
. map ( |l| & l. module )
103
113
. unique ( )
104
114
. map ( |module| format ! ( "pub mod {};" , module) )
@@ -108,9 +118,8 @@ pub fn gen_modules_list(lints: &[Lint]) -> Vec<String> {
108
118
109
119
/// Generates the list of lint links at the bottom of the README
110
120
#[ must_use]
111
- pub fn gen_changelog_lint_list ( lints : & [ Lint ] ) -> Vec < String > {
121
+ pub fn gen_changelog_lint_list < ' a > ( lints : impl Iterator < Item = & ' a Lint > ) -> Vec < String > {
112
122
lints
113
- . iter ( )
114
123
. sorted_by_key ( |l| l. name . clone ( ) )
115
124
. filter_map ( |l| {
116
125
if l. group . starts_with ( "internal" ) {
@@ -124,9 +133,8 @@ pub fn gen_changelog_lint_list(lints: &[Lint]) -> Vec<String> {
124
133
125
134
/// Generates the `register_removed` code in `./clippy_lints/src/lib.rs`.
126
135
#[ must_use]
127
- pub fn gen_deprecated ( lints : & [ Lint ] ) -> Vec < String > {
136
+ pub fn gen_deprecated < ' a > ( lints : impl Iterator < Item = & ' a Lint > ) -> Vec < String > {
128
137
lints
129
- . iter ( )
130
138
. filter_map ( |l| {
131
139
l. clone ( ) . deprecation . map ( |depr_text| {
132
140
vec ! [
@@ -142,11 +150,10 @@ pub fn gen_deprecated(lints: &[Lint]) -> Vec<String> {
142
150
}
143
151
144
152
#[ must_use]
145
- pub fn gen_register_lint_list ( lints : & [ Lint ] ) -> Vec < String > {
153
+ pub fn gen_register_lint_list < ' a > ( lints : impl Iterator < Item = & ' a Lint > ) -> Vec < String > {
146
154
let pre = " store.register_lints(&[" . to_string ( ) ;
147
155
let post = " ]);" . to_string ( ) ;
148
156
let mut inner = lints
149
- . iter ( )
150
157
. map ( |l| format ! ( " &{}::{}," , l. module, l. name. to_uppercase( ) ) )
151
158
. sorted ( )
152
159
. collect :: < Vec < String > > ( ) ;
@@ -421,7 +428,7 @@ fn test_usable_lints() {
421
428
None ,
422
429
"module_name" ,
423
430
) ] ;
424
- assert_eq ! ( expected, Lint :: usable_lints( lints. into_iter ( ) ) . collect :: < Vec < Lint >> ( ) ) ;
431
+ assert_eq ! ( expected, Lint :: usable_lints( & lints) ) ;
425
432
}
426
433
427
434
#[ test]
@@ -457,7 +464,7 @@ fn test_gen_changelog_lint_list() {
457
464
format!( "[`should_assert_eq`]: {}#should_assert_eq" , DOCS_LINK . to_string( ) ) ,
458
465
format!( "[`should_assert_eq2`]: {}#should_assert_eq2" , DOCS_LINK . to_string( ) ) ,
459
466
] ;
460
- assert_eq ! ( expected, gen_changelog_lint_list( & lints) ) ;
467
+ assert_eq ! ( expected, gen_changelog_lint_list( lints. iter ( ) ) ) ;
461
468
}
462
469
463
470
#[ test]
@@ -492,7 +499,7 @@ fn test_gen_deprecated() {
492
499
. into_iter ( )
493
500
. map ( String :: from)
494
501
. collect ( ) ;
495
- assert_eq ! ( expected, gen_deprecated( & lints) ) ;
502
+ assert_eq ! ( expected, gen_deprecated( lints. iter ( ) ) ) ;
496
503
}
497
504
498
505
#[ test]
@@ -507,7 +514,7 @@ fn test_gen_modules_list() {
507
514
"pub mod another_module;" . to_string( ) ,
508
515
"pub mod module_name;" . to_string( ) ,
509
516
] ;
510
- assert_eq ! ( expected, gen_modules_list( & lints) ) ;
517
+ assert_eq ! ( expected, gen_modules_list( lints. iter ( ) ) ) ;
511
518
}
512
519
513
520
#[ test]
@@ -523,5 +530,5 @@ fn test_gen_lint_group_list() {
523
530
" LintId::of(&module_name::INTERNAL)," . to_string( ) ,
524
531
" LintId::of(&module_name::SHOULD_ASSERT_EQ)," . to_string( ) ,
525
532
] ;
526
- assert_eq ! ( expected, gen_lint_group_list( & lints) ) ;
533
+ assert_eq ! ( expected, gen_lint_group_list( lints. iter ( ) ) ) ;
527
534
}
0 commit comments