@@ -9,6 +9,7 @@ use std::process::{Child, Command, ExitStatus, Output, Stdio};
99use std:: sync:: Arc ;
1010use std:: { env, iter, str} ;
1111
12+ use build_helper:: fs:: remove_and_create_dir_all;
1213use camino:: { Utf8Path , Utf8PathBuf } ;
1314use colored:: Colorize ;
1415use regex:: { Captures , Regex } ;
@@ -207,12 +208,6 @@ pub fn compute_stamp_hash(config: &Config) -> String {
207208 format ! ( "{:x}" , hash. finish( ) )
208209}
209210
210- fn remove_and_create_dir_all ( path : & Utf8Path ) {
211- let path = path. as_std_path ( ) ;
212- let _ = fs:: remove_dir_all ( path) ;
213- fs:: create_dir_all ( path) . unwrap ( ) ;
214- }
215-
216211#[ derive( Copy , Clone , Debug ) ]
217212struct TestCx < ' test > {
218213 config : & ' test Config ,
@@ -523,7 +518,9 @@ impl<'test> TestCx<'test> {
523518 let mut rustc = Command :: new ( & self . config . rustc_path ) ;
524519
525520 let out_dir = self . output_base_name ( ) . with_extension ( "pretty-out" ) ;
526- remove_and_create_dir_all ( & out_dir) ;
521+ remove_and_create_dir_all ( & out_dir) . unwrap_or_else ( |e| {
522+ panic ! ( "failed to remove and recreate output directory `{out_dir}`: {e}" )
523+ } ) ;
527524
528525 let target = if self . props . force_host { & * self . config . host } else { & * self . config . target } ;
529526
@@ -1098,13 +1095,19 @@ impl<'test> TestCx<'test> {
10981095 let aux_dir = self . aux_output_dir_name ( ) ;
10991096
11001097 if !self . props . aux . builds . is_empty ( ) {
1101- remove_and_create_dir_all ( & aux_dir) ;
1098+ remove_and_create_dir_all ( & aux_dir) . unwrap_or_else ( |e| {
1099+ panic ! ( "failed to remove and recreate output directory `{aux_dir}`: {e}" )
1100+ } ) ;
11021101 }
11031102
11041103 if !self . props . aux . bins . is_empty ( ) {
11051104 let aux_bin_dir = self . aux_bin_output_dir_name ( ) ;
1106- remove_and_create_dir_all ( & aux_dir) ;
1107- remove_and_create_dir_all ( & aux_bin_dir) ;
1105+ remove_and_create_dir_all ( & aux_dir) . unwrap_or_else ( |e| {
1106+ panic ! ( "failed to remove and recreate output directory `{aux_dir}`: {e}" )
1107+ } ) ;
1108+ remove_and_create_dir_all ( & aux_bin_dir) . unwrap_or_else ( |e| {
1109+ panic ! ( "failed to remove and recreate output directory `{aux_bin_dir}`: {e}" )
1110+ } ) ;
11081111 }
11091112
11101113 aux_dir
@@ -1509,7 +1512,9 @@ impl<'test> TestCx<'test> {
15091512
15101513 let set_mir_dump_dir = |rustc : & mut Command | {
15111514 let mir_dump_dir = self . get_mir_dump_dir ( ) ;
1512- remove_and_create_dir_all ( & mir_dump_dir) ;
1515+ remove_and_create_dir_all ( & mir_dump_dir) . unwrap_or_else ( |e| {
1516+ panic ! ( "failed to remove and recreate output directory `{mir_dump_dir}`: {e}" )
1517+ } ) ;
15131518 let mut dir_opt = "-Zdump-mir-dir=" . to_string ( ) ;
15141519 dir_opt. push_str ( mir_dump_dir. as_str ( ) ) ;
15151520 debug ! ( "dir_opt: {:?}" , dir_opt) ;
@@ -1969,7 +1974,9 @@ impl<'test> TestCx<'test> {
19691974 let suffix =
19701975 self . safe_revision ( ) . map_or ( "nightly" . into ( ) , |path| path. to_owned ( ) + "-nightly" ) ;
19711976 let compare_dir = output_base_dir ( self . config , self . testpaths , Some ( & suffix) ) ;
1972- remove_and_create_dir_all ( & compare_dir) ;
1977+ remove_and_create_dir_all ( & compare_dir) . unwrap_or_else ( |e| {
1978+ panic ! ( "failed to remove and recreate output directory `{compare_dir}`: {e}" )
1979+ } ) ;
19731980
19741981 // We need to create a new struct for the lifetimes on `config` to work.
19751982 let new_rustdoc = TestCx {
0 commit comments