@@ -33,7 +33,11 @@ pub enum OptVersionReq {
33
33
/// The exact locked version and the original version requirement.
34
34
Locked ( Version , VersionReq ) ,
35
35
/// The exact requested version and the original version requirement.
36
- UpdatePrecise ( Version , VersionReq ) ,
36
+ ///
37
+ /// This looks identical to [`OptVersionReq::Locked`] but has a different
38
+ /// meaning, and is used for the `--precise` field of `cargo update`.
39
+ /// See comments in [`OptVersionReq::matches`] for more.
40
+ Precise ( Version , VersionReq ) ,
37
41
}
38
42
39
43
impl OptVersionReq {
@@ -51,7 +55,7 @@ impl OptVersionReq {
51
55
pub fn is_exact ( & self ) -> bool {
52
56
match self {
53
57
OptVersionReq :: Any => false ,
54
- OptVersionReq :: Req ( req) | OptVersionReq :: UpdatePrecise ( _, req) => {
58
+ OptVersionReq :: Req ( req) | OptVersionReq :: Precise ( _, req) => {
55
59
req. comparators . len ( ) == 1 && {
56
60
let cmp = & req. comparators [ 0 ] ;
57
61
cmp. op == Op :: Exact && cmp. minor . is_some ( ) && cmp. patch . is_some ( )
@@ -67,18 +71,19 @@ impl OptVersionReq {
67
71
let version = version. clone ( ) ;
68
72
* self = match self {
69
73
Any => Locked ( version, VersionReq :: STAR ) ,
70
- Req ( req) | Locked ( _, req) | UpdatePrecise ( _, req) => Locked ( version, req. clone ( ) ) ,
74
+ Req ( req) | Locked ( _, req) | Precise ( _, req) => Locked ( version, req. clone ( ) ) ,
71
75
} ;
72
76
}
73
77
74
- pub fn update_precise ( & mut self , version : & Version ) {
78
+ /// Makes the requirement precise to the requested version.
79
+ ///
80
+ /// This is used for the `--precise` field of `cargo update`.
81
+ pub fn precise_to ( & mut self , version : & Version ) {
75
82
use OptVersionReq :: * ;
76
83
let version = version. clone ( ) ;
77
84
* self = match self {
78
- Any => UpdatePrecise ( version, VersionReq :: STAR ) ,
79
- Req ( req) | Locked ( _, req) | UpdatePrecise ( _, req) => {
80
- UpdatePrecise ( version, req. clone ( ) )
81
- }
85
+ Any => Precise ( version, VersionReq :: STAR ) ,
86
+ Req ( req) | Locked ( _, req) | Precise ( _, req) => Precise ( version, req. clone ( ) ) ,
82
87
} ;
83
88
}
84
89
@@ -108,7 +113,7 @@ impl OptVersionReq {
108
113
// we should not silently use `1.0.0+foo` even though they have the same version.
109
114
v == version
110
115
}
111
- OptVersionReq :: UpdatePrecise ( v, _) => {
116
+ OptVersionReq :: Precise ( v, _) => {
112
117
// This is used for the `--precise` field of cargo update.
113
118
//
114
119
// Unfortunately crates.io allowed versions to differ only
@@ -135,7 +140,7 @@ impl Display for OptVersionReq {
135
140
OptVersionReq :: Any => f. write_str ( "*" ) ,
136
141
OptVersionReq :: Req ( req)
137
142
| OptVersionReq :: Locked ( _, req)
138
- | OptVersionReq :: UpdatePrecise ( _, req) => Display :: fmt ( req, f) ,
143
+ | OptVersionReq :: Precise ( _, req) => Display :: fmt ( req, f) ,
139
144
}
140
145
}
141
146
}
0 commit comments