@@ -772,78 +772,59 @@ fn summary_for_patch(
772
772
}
773
773
assert ! ( summaries. is_empty( ) ) ;
774
774
// No summaries found, try to help the user figure out what is wrong.
775
- if let Some ( ( locked_patch , locked_id) ) = locked {
775
+ if let Some ( ( _locked_patch , locked_id) ) = locked {
776
776
// Since the locked patch did not match anything, try the unlocked one.
777
- let mut orig_matches = source. query_vec ( orig_patch) . unwrap_or_else ( |e| {
777
+ let orig_matches = source. query_vec ( orig_patch) . unwrap_or_else ( |e| {
778
778
log:: warn!(
779
779
"could not determine unlocked summaries for dep {:?}: {:?}" ,
780
780
orig_patch,
781
781
e
782
782
) ;
783
783
Vec :: new ( )
784
784
} ) ;
785
- if orig_matches. is_empty ( ) {
786
- // This should be relatively unusual. For example, a patch of
787
- // {version="0.1.2", ...} and the patch location no longer contains a
788
- // version that matches "0.1.2". It is unusual to explicitly write a
789
- // version in the patch.
790
- anyhow:: bail!(
791
- "The patch is locked to {} in Cargo.lock, but the version in the \
792
- patch location does not match any packages in the patch location.\n \
793
- Make sure the patch points to the correct version.",
794
- locked_patch. version_req( ) ,
795
- ) ;
796
- }
797
- let summary = best_summary ( & mut orig_matches) ;
798
- debug ! (
799
- "locked patch no longer matches, but unlocked version should work. \
800
- locked={:?} unlocked={:?} summary={:?}",
801
- locked, orig_patch, summary
802
- ) ;
785
+ let ( summary, _) = summary_for_patch ( orig_patch, & None , orig_matches, source) ?;
803
786
// The unlocked version found a match. This returns a value to
804
787
// indicate that this entry should be unlocked.
805
788
return Ok ( ( summary, Some ( * locked_id) ) ) ;
806
- } else {
807
- // Try checking if there are *any* packages that match this by name.
808
- let name_only_dep =
809
- Dependency :: new_override ( orig_patch. package_name ( ) , orig_patch. source_id ( ) ) ;
810
- let name_summaries = source. query_vec ( & name_only_dep) . unwrap_or_else ( |e| {
811
- log:: warn!(
812
- "failed to do name-only summary query for {:?}: {:?}" ,
813
- name_only_dep,
814
- e
815
- ) ;
816
- Vec :: new ( )
817
- } ) ;
818
- let mut vers = name_summaries
819
- . iter ( )
820
- . map ( |summary| summary. version ( ) )
821
- . collect :: < Vec < _ > > ( ) ;
822
- let found = match vers. len ( ) {
823
- 0 => format ! ( "" ) ,
824
- 1 => format ! ( "version `{}`" , vers[ 0 ] ) ,
825
- _ => {
826
- vers. sort ( ) ;
827
- let strs: Vec < _ > = vers. into_iter ( ) . map ( |v| v. to_string ( ) ) . collect ( ) ;
828
- format ! ( "versions `{}`" , strs. join( ", " ) )
829
- }
830
- } ;
831
- if found. is_empty ( ) {
832
- anyhow:: bail!(
833
- "The patch location does not appear to contain any packages \
834
- matching the name `{}`.",
835
- orig_patch. package_name( )
836
- ) ;
837
- } else {
838
- anyhow:: bail!(
839
- "The patch location contains a `{}` package with {}, but the patch \
840
- definition requires `{}`.\n \
841
- Check that the version in the patch location is what you expect, \
842
- and update the patch definition to match.",
843
- orig_patch. package_name( ) ,
844
- found,
845
- orig_patch. version_req( )
846
- ) ;
789
+ }
790
+ // Try checking if there are *any* packages that match this by name.
791
+ let name_only_dep = Dependency :: new_override ( orig_patch. package_name ( ) , orig_patch. source_id ( ) ) ;
792
+ let name_summaries = source. query_vec ( & name_only_dep) . unwrap_or_else ( |e| {
793
+ log:: warn!(
794
+ "failed to do name-only summary query for {:?}: {:?}" ,
795
+ name_only_dep,
796
+ e
797
+ ) ;
798
+ Vec :: new ( )
799
+ } ) ;
800
+ let mut vers = name_summaries
801
+ . iter ( )
802
+ . map ( |summary| summary. version ( ) )
803
+ . collect :: < Vec < _ > > ( ) ;
804
+ let found = match vers. len ( ) {
805
+ 0 => format ! ( "" ) ,
806
+ 1 => format ! ( "version `{}`" , vers[ 0 ] ) ,
807
+ _ => {
808
+ vers. sort ( ) ;
809
+ let strs: Vec < _ > = vers. into_iter ( ) . map ( |v| v. to_string ( ) ) . collect ( ) ;
810
+ format ! ( "versions `{}`" , strs. join( ", " ) )
847
811
}
812
+ } ;
813
+ if found. is_empty ( ) {
814
+ anyhow:: bail!(
815
+ "The patch location does not appear to contain any packages \
816
+ matching the name `{}`.",
817
+ orig_patch. package_name( )
818
+ ) ;
819
+ } else {
820
+ anyhow:: bail!(
821
+ "The patch location contains a `{}` package with {}, but the patch \
822
+ definition requires `{}`.\n \
823
+ Check that the version in the patch location is what you expect, \
824
+ and update the patch definition to match.",
825
+ orig_patch. package_name( ) ,
826
+ found,
827
+ orig_patch. version_req( )
828
+ ) ;
848
829
}
849
830
}
0 commit comments