From 4bdface19a46443d5a0e1f8ff9606eb80f776d94 Mon Sep 17 00:00:00 2001 From: jofas Date: Mon, 6 Feb 2023 14:43:44 +0100 Subject: [PATCH] applying code review to make get_sysroot_target_libdir more readable + incorporated changes into corresponding test --- src/cargo/core/compiler/compilation.rs | 43 ++++++++++++-------------- tests/testsuite/artifact_dep.rs | 4 +-- 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/src/cargo/core/compiler/compilation.rs b/src/cargo/core/compiler/compilation.rs index c5ace57b1f7..d89263479d1 100644 --- a/src/cargo/core/compiler/compilation.rs +++ b/src/cargo/core/compiler/compilation.rs @@ -381,30 +381,25 @@ fn get_sysroot_target_libdir( bcx.all_kinds .iter() .map(|&kind| { - Ok(( - kind, - bcx.target_data - .get_info(kind) - .ok_or_else(|| { - let target = match kind { - CompileKind::Host => "host".to_owned(), - CompileKind::Target(s) => s.short_name().to_owned(), - }; - - let dependency = bcx - .unit_graph - .iter() - .find_map(|(u, _)| (unit.kind == kind).then_some(unit.pkg.summary().package_id())) - .unwrap(); - - anyhow::anyhow!( - "could not find specification for target `{target}`.\n \ - Dependency `{dependency}` requires to build for target `{target}`." - ) - })? - .sysroot_target_libdir - .clone(), - )) + let Some(info) = bcx.target_data.get_info(kind) else { + let target = match kind { + CompileKind::Host => "host".to_owned(), + CompileKind::Target(s) => s.short_name().to_owned(), + }; + + let dependency = bcx + .unit_graph + .iter() + .find_map(|(u, _)| (u.kind == kind).then_some(u.pkg.summary().package_id())) + .unwrap(); + + anyhow::bail!( + "could not find specification for target `{target}`.\n \ + Dependency `{dependency}` requires to build for target `{target}`." + ) + }; + + Ok((kind, info.sysroot_target_libdir.clone())) }) .collect() } diff --git a/tests/testsuite/artifact_dep.rs b/tests/testsuite/artifact_dep.rs index fdcbe20cdc4..46e78caafe7 100644 --- a/tests/testsuite/artifact_dep.rs +++ b/tests/testsuite/artifact_dep.rs @@ -2900,8 +2900,8 @@ fn check_transitive_artifact_dependency_with_different_target() { p.cargo("check -Z bindeps") .masquerade_as_nightly_cargo(&["bindeps"]) .with_stderr_contains( - "error: could not find specification for target \"custom-target\".\n \ - Dependency `baz v0.0.0` requires to build for target \"custom-target\".", + "error: could not find specification for target `custom-target`.\n \ + Dependency `baz v0.0.0 [..]` requires to build for target `custom-target`.", ) .with_status(101) .run();