11use super :: unit_graph:: UnitGraph ;
2+ use crate :: core:: resolver:: errors:: describe_path;
23use crate :: core:: { PackageId , Resolve } ;
34use crate :: util:: errors:: CargoResult ;
45use std:: collections:: { HashMap , HashSet } ;
5- use std:: fmt:: Write ;
66
77/// Validate `links` field does not conflict between packages.
88pub fn validate_links ( resolve : & Resolve , unit_graph : & UnitGraph ) -> CargoResult < ( ) > {
@@ -28,17 +28,15 @@ pub fn validate_links(resolve: &Resolve, unit_graph: &UnitGraph) -> CargoResult<
2828 None => continue ,
2929 } ;
3030 if let Some ( & prev) = links. get ( lib) {
31+ let prev_path = resolve
32+ . path_to_top ( & prev)
33+ . into_iter ( )
34+ . map ( |( p, d) | ( p, d. and_then ( |d| d. iter ( ) . next ( ) ) ) ) ;
3135 let pkg = unit. pkg . package_id ( ) ;
32-
33- let describe_path = |pkgid : PackageId | -> String {
34- let dep_path = resolve. path_to_top ( & pkgid) ;
35- let mut dep_path_desc = format ! ( "package `{}`" , dep_path[ 0 ] ) ;
36- for dep in dep_path. iter ( ) . skip ( 1 ) {
37- write ! ( dep_path_desc, "\n ... which is depended on by `{}`" , dep) . unwrap ( ) ;
38- }
39- dep_path_desc
40- } ;
41-
36+ let path = resolve
37+ . path_to_top ( & pkg)
38+ . into_iter ( )
39+ . map ( |( p, d) | ( p, d. and_then ( |d| d. iter ( ) . next ( ) ) ) ) ;
4240 anyhow:: bail!(
4341 "multiple packages link to native library `{}`, \
4442 but a native library can be linked only once\n \
@@ -47,9 +45,9 @@ pub fn validate_links(resolve: &Resolve, unit_graph: &UnitGraph) -> CargoResult<
4745 \n \
4846 {}\n also links to native library `{}`",
4947 lib,
50- describe_path( prev ) ,
48+ describe_path( prev_path ) ,
5149 lib,
52- describe_path( pkg ) ,
50+ describe_path( path ) ,
5351 lib
5452 )
5553 }
0 commit comments