File tree 2 files changed +11
-10
lines changed
2 files changed +11
-10
lines changed Original file line number Diff line number Diff line change 1
1
use std:: fmt:: Display ;
2
2
3
- use anyhow:: bail;
4
-
5
3
use crate :: CargoResult ;
6
4
7
5
/// Upgrade an existing requirement to a new version.
@@ -23,15 +21,18 @@ pub(crate) fn upgrade_requirement(
23
21
. map ( |p| set_comparator ( p, version) )
24
22
. collect ( ) ;
25
23
let comparators = comparators?;
26
- let new_req = semver:: VersionReq { comparators } ;
24
+ let mut new_req = semver:: VersionReq { comparators } ;
25
+ // Validate contract
26
+ if !new_req. matches ( version) {
27
+ // If req is ^0.1 and version is 0.2.0-beta, new_req becomes ^0.2.
28
+ // This does not match version. In such cases, we should let new_req
29
+ // be ^version.
30
+ new_req = semver:: VersionReq :: parse ( & format ! ( "^{version}" ) ) ?;
31
+ }
27
32
let mut new_req_text = new_req. to_string ( ) ;
28
33
if new_req_text. starts_with ( '^' ) && !req. starts_with ( '^' ) {
29
34
new_req_text. remove ( 0 ) ;
30
35
}
31
- // Validate contract
32
- if !new_req. matches ( version) {
33
- bail ! ( "new requirement {new_req_text} is invalid, because it doesn't match {version}" )
34
- }
35
36
if new_req_text == req_text {
36
37
Ok ( None )
37
38
} else {
Original file line number Diff line number Diff line change @@ -1785,7 +1785,7 @@ fn update_precise_breaking_alternative() {
1785
1785
}
1786
1786
1787
1787
#[ cargo_test]
1788
- fn update_precise_breaking_pre_release_cannot_upgrade_nonexplicit_version_req ( ) {
1788
+ fn update_precise_breaking_pre_release ( ) {
1789
1789
Package :: new ( "pre" , "0.1.0" ) . publish ( ) ;
1790
1790
1791
1791
let p = project ( )
@@ -1811,9 +1811,9 @@ fn update_precise_breaking_pre_release_cannot_upgrade_nonexplicit_version_req()
1811
1811
1812
1812
p. cargo ( "update -Zunstable-options pre --precise 0.2.0-beta" )
1813
1813
. masquerade_as_nightly_cargo ( & [ "update-precise-breaking" ] )
1814
- . with_status ( 101 )
1815
1814
. with_stderr_data ( str![ [ r#"
1816
- [ERROR] new requirement ^0.2 is invalid, because it doesn't match 0.2.0-beta
1815
+ [UPGRADING] pre ^0.1 -> ^0.2.0-beta
1816
+ [UPDATING] `dummy-registry` index
1817
1817
1818
1818
"# ] ] )
1819
1819
. run ( ) ;
You can’t perform that action at this time.
0 commit comments