Skip to content

Commit 906b851

Browse files
committed
Factor Option out of copy_cgu_workproduct_to_incr_comp_cache_dir call
This improves clarity of the code a bit
1 parent 065e202 commit 906b851

File tree

3 files changed

+20
-28
lines changed

3 files changed

+20
-28
lines changed

compiler/rustc_codegen_cranelift/src/driver/aot.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,7 @@ fn emit_module(
6666
let work_product = if backend_config.disable_incr_cache {
6767
None
6868
} else {
69-
rustc_incremental::copy_cgu_workproduct_to_incr_comp_cache_dir(
70-
tcx.sess,
71-
&name,
72-
Some(&tmp_file),
73-
)
69+
rustc_incremental::copy_cgu_workproduct_to_incr_comp_cache_dir(tcx.sess, &name, &tmp_file)
7470
};
7571

7672
ModuleCodegenResult(

compiler/rustc_codegen_ssa/src/back/write.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -494,12 +494,12 @@ fn copy_all_cgu_workproducts_to_incr_comp_cache_dir(
494494
let _timer = sess.timer("copy_all_cgu_workproducts_to_incr_comp_cache_dir");
495495

496496
for module in compiled_modules.modules.iter().filter(|m| m.kind == ModuleKind::Regular) {
497-
let path = module.object.as_deref();
498-
499-
if let Some((id, product)) =
500-
copy_cgu_workproduct_to_incr_comp_cache_dir(sess, &module.name, path)
501-
{
502-
work_products.insert(id, product);
497+
if let Some(path) = &module.object {
498+
if let Some((id, product)) =
499+
copy_cgu_workproduct_to_incr_comp_cache_dir(sess, &module.name, path)
500+
{
501+
work_products.insert(id, product);
502+
}
503503
}
504504
}
505505

compiler/rustc_incremental/src/persist/work_product.rs

+13-17
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,24 @@ use std::path::Path;
1313
pub fn copy_cgu_workproduct_to_incr_comp_cache_dir(
1414
sess: &Session,
1515
cgu_name: &str,
16-
path: Option<&Path>,
16+
path: &Path,
1717
) -> Option<(WorkProductId, WorkProduct)> {
1818
debug!("copy_cgu_workproduct_to_incr_comp_cache_dir({:?},{:?})", cgu_name, path);
1919
sess.opts.incremental.as_ref()?;
2020

21-
let saved_file = if let Some(path) = path {
22-
let file_name = format!("{}.o", cgu_name);
23-
let path_in_incr_dir = in_incr_comp_dir_sess(sess, &file_name);
24-
match link_or_copy(path, &path_in_incr_dir) {
25-
Ok(_) => Some(file_name),
26-
Err(err) => {
27-
sess.warn(&format!(
28-
"error copying object file `{}` to incremental directory as `{}`: {}",
29-
path.display(),
30-
path_in_incr_dir.display(),
31-
err
32-
));
33-
return None;
34-
}
21+
let file_name = format!("{}.o", cgu_name);
22+
let path_in_incr_dir = in_incr_comp_dir_sess(sess, &file_name);
23+
let saved_file = match link_or_copy(path, &path_in_incr_dir) {
24+
Ok(_) => Some(file_name),
25+
Err(err) => {
26+
sess.warn(&format!(
27+
"error copying object file `{}` to incremental directory as `{}`: {}",
28+
path.display(),
29+
path_in_incr_dir.display(),
30+
err
31+
));
32+
return None;
3533
}
36-
} else {
37-
None
3834
};
3935

4036
let work_product = WorkProduct { cgu_name: cgu_name.to_string(), saved_file };

0 commit comments

Comments
 (0)