@@ -58,37 +58,31 @@ impl Lint {
58
58
}
59
59
60
60
pub fn gather_all ( ) -> impl Iterator < Item =Lint > {
61
- let mut lints = vec ! [ ] ;
62
- for dir_entry in lint_files ( ) {
63
- lints. append ( & mut gather_from_file ( & dir_entry) . collect ( ) ) ;
64
- }
65
- lints. into_iter ( )
61
+ lint_files ( ) . flat_map ( gather_from_file)
66
62
}
67
63
68
- fn gather_from_file ( dir_entry : & fs:: DirEntry ) -> impl Iterator < Item =Lint > {
64
+ fn gather_from_file ( dir_entry : fs:: DirEntry ) -> impl Iterator < Item =Lint > {
69
65
let mut file = fs:: File :: open ( dir_entry. path ( ) ) . unwrap ( ) ;
70
66
let mut content = String :: new ( ) ;
71
67
file. read_to_string ( & mut content) . unwrap ( ) ;
72
68
parse_contents ( & content, dir_entry. path ( ) . file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) )
73
69
}
74
70
75
71
fn parse_contents ( content : & str , filename : & str ) -> impl Iterator < Item =Lint > {
76
- let mut lints: Vec < Lint > = DEC_CLIPPY_LINT_RE
77
- . captures_iter ( & content)
78
- . map ( |m| Lint :: new ( & m[ "name" ] , & m[ "cat" ] , & m[ "desc" ] , None , filename) )
79
- . collect ( ) ;
80
- let mut deprecated = DEC_DEPRECATED_LINT_RE
81
- . captures_iter ( & content)
82
- . map ( |m| Lint :: new ( & m[ "name" ] , "Deprecated" , & m[ "desc" ] , Some ( & m[ "desc" ] ) , filename) )
83
- . collect ( ) ;
84
- lints. append ( & mut deprecated) ;
85
- lints. into_iter ( )
72
+ let lints = DEC_CLIPPY_LINT_RE
73
+ . captures_iter ( content)
74
+ . map ( |m| Lint :: new ( & m[ "name" ] , & m[ "cat" ] , & m[ "desc" ] , None , filename) ) ;
75
+ let deprecated = DEC_DEPRECATED_LINT_RE
76
+ . captures_iter ( content)
77
+ . map ( |m| Lint :: new ( & m[ "name" ] , "Deprecated" , & m[ "desc" ] , Some ( & m[ "desc" ] ) , filename) ) ;
78
+ // Removing the `.collect::<Vec<Lint>>().into_iter()` causes some lifetime issues due to the map
79
+ lints. chain ( deprecated) . collect :: < Vec < Lint > > ( ) . into_iter ( )
86
80
}
87
81
88
82
/// Collects all .rs files in the `clippy_lints/src` directory
89
83
fn lint_files ( ) -> impl Iterator < Item =fs:: DirEntry > {
90
- let paths = fs:: read_dir ( "../clippy_lints/src" ) . unwrap ( ) ;
91
- paths
84
+ fs:: read_dir ( "../clippy_lints/src" )
85
+ . unwrap ( )
92
86
. filter_map ( |f| f. ok ( ) )
93
87
. filter ( |f| f. path ( ) . extension ( ) == Some ( OsStr :: new ( "rs" ) ) )
94
88
}
0 commit comments