33use std:: collections:: HashSet ;
44use std:: path:: { Path , PathBuf } ;
55
6+ use crate :: walk:: walk_no_read;
7+
68fn check_unused_files ( path : & Path , bless : bool , bad : & mut bool ) {
79 let mut rs_files = Vec :: < PathBuf > :: new ( ) ;
810 let mut output_files = HashSet :: < PathBuf > :: new ( ) ;
9- let files = walkdir:: WalkDir :: new ( & path. join ( "mir-opt" ) ) . into_iter ( ) ;
1011
11- for file in files. filter_map ( Result :: ok) . filter ( |e| e. file_type ( ) . is_file ( ) ) {
12- let filepath = file. path ( ) ;
13- if filepath. extension ( ) == Some ( "rs" . as_ref ( ) ) {
14- rs_files. push ( filepath. to_owned ( ) ) ;
15- } else {
16- output_files. insert ( filepath. to_owned ( ) ) ;
17- }
18- }
12+ walk_no_read (
13+ & [ & path. join ( "mir-opt" ) ] ,
14+ |path| path. file_name ( ) == Some ( "README.md" . as_ref ( ) ) ,
15+ & mut |file| {
16+ let filepath = file. path ( ) ;
17+ if filepath. extension ( ) == Some ( "rs" . as_ref ( ) ) {
18+ rs_files. push ( filepath. to_owned ( ) ) ;
19+ } else {
20+ output_files. insert ( filepath. to_owned ( ) ) ;
21+ }
22+ } ,
23+ ) ;
1924
2025 for file in rs_files {
2126 for bw in [ 32 , 64 ] {
@@ -26,16 +31,14 @@ fn check_unused_files(path: &Path, bless: bool, bad: &mut bool) {
2631 }
2732
2833 for extra in output_files {
29- if extra. file_name ( ) != Some ( "README.md" . as_ref ( ) ) {
30- if !bless {
31- tidy_error ! (
32- bad,
33- "the following output file is not associated with any mir-opt test, you can remove it: {}" ,
34- extra. display( )
35- ) ;
36- } else {
37- let _ = std:: fs:: remove_file ( extra) ;
38- }
34+ if !bless {
35+ tidy_error ! (
36+ bad,
37+ "the following output file is not associated with any mir-opt test, you can remove it: {}" ,
38+ extra. display( )
39+ ) ;
40+ } else {
41+ let _ = std:: fs:: remove_file ( extra) ;
3942 }
4043 }
4144}
0 commit comments