@@ -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,21 +71,34 @@ 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
90
+ pub fn is_precise ( & self ) -> bool {
91
+ matches ! ( self , OptVersionReq :: Precise ( ..) )
92
+ }
93
+
94
+ /// Gets the version to which this req is precise to, if any.
95
+ pub fn precise_version ( & self ) -> Option < & Version > {
96
+ match self {
97
+ OptVersionReq :: Precise ( version, _) => Some ( version) ,
98
+ _ => None ,
99
+ }
100
+ }
101
+
85
102
pub fn is_locked ( & self ) -> bool {
86
103
matches ! ( self , OptVersionReq :: Locked ( ..) )
87
104
}
@@ -108,7 +125,7 @@ impl OptVersionReq {
108
125
// we should not silently use `1.0.0+foo` even though they have the same version.
109
126
v == version
110
127
}
111
- OptVersionReq :: UpdatePrecise ( v, _) => {
128
+ OptVersionReq :: Precise ( v, _) => {
112
129
// This is used for the `--precise` field of cargo update.
113
130
//
114
131
// Unfortunately crates.io allowed versions to differ only
@@ -135,7 +152,7 @@ impl Display for OptVersionReq {
135
152
OptVersionReq :: Any => f. write_str ( "*" ) ,
136
153
OptVersionReq :: Req ( req)
137
154
| OptVersionReq :: Locked ( _, req)
138
- | OptVersionReq :: UpdatePrecise ( _, req) => Display :: fmt ( req, f) ,
155
+ | OptVersionReq :: Precise ( _, req) => Display :: fmt ( req, f) ,
139
156
}
140
157
}
141
158
}
0 commit comments