diff --git a/clippy_dev/src/bless.rs b/clippy_dev/src/bless.rs index 8d5c2e95055..645098e4cfc 100644 --- a/clippy_dev/src/bless.rs +++ b/clippy_dev/src/bless.rs @@ -46,13 +46,16 @@ fn update_reference_file(reference_file_path: PathBuf) { } let test_output_file = fs::read(&test_output_path).expect("Unable to read test output file"); - let reference_file = fs::read(&reference_file_path).expect("Unable to read reference file"); + let reference_file = fs::read(&reference_file_path).unwrap_or_default(); if test_output_file != reference_file { // If a test run caused an output file to change, update the reference file println!("updating {}", &relative_reference_file_path.display()); fs::copy(test_output_path, &reference_file_path).expect("Could not update reference file"); + // We need to re-read the file now because it was potentially updated from copying + let reference_file = fs::read(&reference_file_path).unwrap_or_default(); + if reference_file.is_empty() { // If we copied over an empty output file, we remove the now empty reference file println!("removing {}", &relative_reference_file_path.display());