Skip to content

Commit a941fdb

Browse files
committed
Fail nicely when copying artefacts fails
Fixes #22124
1 parent 88d8ba5 commit a941fdb

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/librustc_trans/back/write.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -658,14 +658,18 @@ pub fn run_passes(sess: &Session,
658658
}
659659

660660
// Produce final compile outputs.
661+
let copy_gracefully = |from: &Path, to: &Path| {
662+
if let Err(e) = fs::copy(from, to) {
663+
sess.err(&format!("could not copy {:?} to {:?}: {}", from, to, e));
664+
}
665+
};
661666

662667
let copy_if_one_unit = |ext: &str, output_type: config::OutputType, keep_numbered: bool| {
663668
// Three cases:
664669
if sess.opts.cg.codegen_units == 1 {
665670
// 1) Only one codegen unit. In this case it's no difficulty
666671
// to copy `foo.0.x` to `foo.x`.
667-
fs::copy(&crate_output.with_extension(ext),
668-
&crate_output.path(output_type)).unwrap();
672+
copy_gracefully(&crate_output.with_extension(ext), &crate_output.path(output_type));
669673
if !sess.opts.cg.save_temps && !keep_numbered {
670674
// The user just wants `foo.x`, not `foo.0.x`.
671675
remove(sess, &crate_output.with_extension(ext));
@@ -687,8 +691,7 @@ pub fn run_passes(sess: &Session,
687691
let link_obj = |output_path: &Path| {
688692
// Running `ld -r` on a single input is kind of pointless.
689693
if sess.opts.cg.codegen_units == 1 {
690-
fs::copy(&crate_output.with_extension("0.o"),
691-
output_path).unwrap();
694+
copy_gracefully(&crate_output.with_extension("0.o"), output_path);
692695
// Leave the .0.o file around, to mimic the behavior of the normal
693696
// code path.
694697
return;

0 commit comments

Comments
 (0)