Skip to content

Commit 4bdface

Browse files
committed
applying code review to make get_sysroot_target_libdir more readable + incorporated changes into corresponding test
1 parent 96366bd commit 4bdface

File tree

2 files changed

+21
-26
lines changed

2 files changed

+21
-26
lines changed

src/cargo/core/compiler/compilation.rs

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -381,30 +381,25 @@ fn get_sysroot_target_libdir(
381381
bcx.all_kinds
382382
.iter()
383383
.map(|&kind| {
384-
Ok((
385-
kind,
386-
bcx.target_data
387-
.get_info(kind)
388-
.ok_or_else(|| {
389-
let target = match kind {
390-
CompileKind::Host => "host".to_owned(),
391-
CompileKind::Target(s) => s.short_name().to_owned(),
392-
};
393-
394-
let dependency = bcx
395-
.unit_graph
396-
.iter()
397-
.find_map(|(u, _)| (unit.kind == kind).then_some(unit.pkg.summary().package_id()))
398-
.unwrap();
399-
400-
anyhow::anyhow!(
401-
"could not find specification for target `{target}`.\n \
402-
Dependency `{dependency}` requires to build for target `{target}`."
403-
)
404-
})?
405-
.sysroot_target_libdir
406-
.clone(),
407-
))
384+
let Some(info) = bcx.target_data.get_info(kind) else {
385+
let target = match kind {
386+
CompileKind::Host => "host".to_owned(),
387+
CompileKind::Target(s) => s.short_name().to_owned(),
388+
};
389+
390+
let dependency = bcx
391+
.unit_graph
392+
.iter()
393+
.find_map(|(u, _)| (u.kind == kind).then_some(u.pkg.summary().package_id()))
394+
.unwrap();
395+
396+
anyhow::bail!(
397+
"could not find specification for target `{target}`.\n \
398+
Dependency `{dependency}` requires to build for target `{target}`."
399+
)
400+
};
401+
402+
Ok((kind, info.sysroot_target_libdir.clone()))
408403
})
409404
.collect()
410405
}

tests/testsuite/artifact_dep.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2900,8 +2900,8 @@ fn check_transitive_artifact_dependency_with_different_target() {
29002900
p.cargo("check -Z bindeps")
29012901
.masquerade_as_nightly_cargo(&["bindeps"])
29022902
.with_stderr_contains(
2903-
"error: could not find specification for target \"custom-target\".\n \
2904-
Dependency `baz v0.0.0` requires to build for target \"custom-target\".",
2903+
"error: could not find specification for target `custom-target`.\n \
2904+
Dependency `baz v0.0.0 [..]` requires to build for target `custom-target`.",
29052905
)
29062906
.with_status(101)
29072907
.run();

0 commit comments

Comments
 (0)