@@ -13,10 +13,10 @@ use crate::bindgen::error::Error;
1313use crate :: bindgen:: ir:: Cfg ;
1414
1515/// Parse a dependency string used in Cargo.lock
16- fn parse_dep_string ( dep_string : & str ) -> ( & str , & str ) {
16+ fn parse_dep_string ( dep_string : & str ) -> ( & str , Option < & str > ) {
1717 let split: Vec < & str > = dep_string. split_whitespace ( ) . collect ( ) ;
1818
19- ( split[ 0 ] , split[ 1 ] )
19+ ( split[ 0 ] , split. get ( 1 ) . cloned ( ) )
2020}
2121
2222/// A collection of metadata for a library from cargo.
@@ -99,14 +99,25 @@ impl Cargo {
9999
100100 // Find the dependencies listing in the lockfile
101101 if let Some ( ref root) = lock. root {
102- if root. name == package. name && root. version == package. version {
102+ // If the version is not on the lockfile then it shouldn't be
103+ // ambiguous.
104+ if root. name == package. name
105+ && package
106+ . version
107+ . as_ref ( )
108+ . map_or ( true , |v| * v == root. version )
109+ {
103110 dependencies = root. dependencies . as_ref ( ) ;
104111 }
105112 }
106113 if dependencies. is_none ( ) {
107114 if let Some ( ref lock_packages) = lock. package {
108115 for lock_package in lock_packages {
109- if lock_package. name == package. name && lock_package. version == package. version
116+ if lock_package. name == package. name
117+ && package
118+ . version
119+ . as_ref ( )
120+ . map_or ( true , |v| * v == lock_package. version )
110121 {
111122 dependencies = lock_package. dependencies . as_ref ( ) ;
112123 break ;
@@ -134,7 +145,7 @@ impl Cargo {
134145
135146 let package_ref = PackageRef {
136147 name : dep_name. to_owned ( ) ,
137- version : dep_version. to_owned ( ) ,
148+ version : dep_version. map ( |v| v . to_owned ( ) ) ,
138149 } ;
139150
140151 ( package_ref, cfg)
@@ -202,7 +213,7 @@ impl Cargo {
202213 cargo_expand:: expand (
203214 & self . manifest_path ,
204215 & package. name ,
205- & package. version ,
216+ package. version . as_ref ( ) . map ( |v| & * * v ) ,
206217 self . clean ,
207218 expand_all_features,
208219 expand_default_features,
0 commit comments