@@ -46,8 +46,9 @@ impl Lint {
46
46
}
47
47
}
48
48
49
- pub fn active_lints ( lints : & [ Lint ] ) -> Vec < Lint > {
50
- lints. iter ( ) . filter ( |l| l. deprecation . is_none ( ) ) . cloned ( ) . collect :: < Vec < Lint > > ( )
49
+ /// Returns all non-deprecated lints
50
+ pub fn active_lints ( lints : & [ Lint ] ) -> impl Iterator < Item =& Lint > {
51
+ lints. iter ( ) . filter ( |l| l. deprecation . is_none ( ) )
51
52
}
52
53
53
54
/// Returns the lints in a HashMap, grouped by the different lint groups
@@ -56,22 +57,22 @@ impl Lint {
56
57
}
57
58
}
58
59
59
- pub fn collect_all ( ) -> Vec < Lint > {
60
+ pub fn gather_all ( ) -> impl Iterator < Item = Lint > {
60
61
let mut lints = vec ! [ ] ;
61
62
for dir_entry in lint_files ( ) {
62
- lints. append ( & mut collect_from_file ( & dir_entry) ) ;
63
+ lints. append ( & mut gather_from_file ( & dir_entry) . collect ( ) ) ;
63
64
}
64
- lints
65
+ lints. into_iter ( )
65
66
}
66
67
67
- fn collect_from_file ( dir_entry : & fs:: DirEntry ) -> Vec < Lint > {
68
+ fn gather_from_file ( dir_entry : & fs:: DirEntry ) -> impl Iterator < Item = Lint > {
68
69
let mut file = fs:: File :: open ( dir_entry. path ( ) ) . unwrap ( ) ;
69
70
let mut content = String :: new ( ) ;
70
71
file. read_to_string ( & mut content) . unwrap ( ) ;
71
72
parse_contents ( & content, dir_entry. path ( ) . file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) )
72
73
}
73
74
74
- fn parse_contents ( content : & str , filename : & str ) -> Vec < Lint > {
75
+ fn parse_contents ( content : & str , filename : & str ) -> impl Iterator < Item = Lint > {
75
76
let mut lints: Vec < Lint > = DEC_CLIPPY_LINT_RE
76
77
. captures_iter ( & content)
77
78
. map ( |m| Lint :: new ( & m[ "name" ] , & m[ "cat" ] , & m[ "desc" ] , None , filename) )
@@ -81,21 +82,20 @@ fn parse_contents(content: &str, filename: &str) -> Vec<Lint> {
81
82
. map ( |m| Lint :: new ( & m[ "name" ] , "Deprecated" , & m[ "desc" ] , Some ( & m[ "desc" ] ) , filename) )
82
83
. collect ( ) ;
83
84
lints. append ( & mut deprecated) ;
84
- lints
85
+ lints. into_iter ( )
85
86
}
86
87
87
88
/// Collects all .rs files in the `clippy_lints/src` directory
88
- fn lint_files ( ) -> Vec < fs:: DirEntry > {
89
+ fn lint_files ( ) -> impl Iterator < Item = fs:: DirEntry > {
89
90
let paths = fs:: read_dir ( "../clippy_lints/src" ) . unwrap ( ) ;
90
91
paths
91
92
. filter_map ( |f| f. ok ( ) )
92
93
. filter ( |f| f. path ( ) . extension ( ) == Some ( OsStr :: new ( "rs" ) ) )
93
- . collect :: < Vec < fs:: DirEntry > > ( )
94
94
}
95
95
96
96
#[ test]
97
97
fn test_parse_contents ( ) {
98
- let result = parse_contents (
98
+ let result: Vec < Lint > = parse_contents (
99
99
r#"
100
100
declare_clippy_lint! {
101
101
pub PTR_ARG,
@@ -116,7 +116,7 @@ declare_deprecated_lint! {
116
116
"`assert!()` will be more flexible with RFC 2011"
117
117
}
118
118
"# ,
119
- "module_name" ) ;
119
+ "module_name" ) . collect ( ) ;
120
120
121
121
let expected = vec ! [
122
122
Lint :: new( "ptr_arg" , "style" , "really long text" , None , "module_name" ) ,
@@ -141,7 +141,7 @@ fn test_active_lints() {
141
141
let expected = vec ! [
142
142
Lint :: new( "should_assert_eq2" , "Not Deprecated" , "abc" , None , "module_name" )
143
143
] ;
144
- assert_eq ! ( expected, Lint :: active_lints( & lints) ) ;
144
+ assert_eq ! ( expected, Lint :: active_lints( & lints) . cloned ( ) . collect :: < Vec < Lint >> ( ) ) ;
145
145
}
146
146
147
147
#[ test]
0 commit comments