Skip to content

Commit 515f6e3

Browse files
committed
refactor: rename items in OptVersionReq
* `OptVersionReq::update_precise` to `precise_to` * `OptVersionReq::UpdatePrecise` to `Precise`
1 parent 70e7868 commit 515f6e3

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

src/cargo/sources/registry/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ impl<'cfg> Source for RegistrySource<'cfg> {
748748
.precise_registry_version(dep.package_name().as_str())
749749
.filter(|(c, _)| req.matches(c))
750750
{
751-
req.update_precise(&requested);
751+
req.precise_to(&requested);
752752
}
753753

754754
let mut called = false;

src/cargo/util/semver_ext.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ pub enum OptVersionReq {
3333
/// The exact locked version and the original version requirement.
3434
Locked(Version, VersionReq),
3535
/// 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),
3741
}
3842

3943
impl OptVersionReq {
@@ -51,7 +55,7 @@ impl OptVersionReq {
5155
pub fn is_exact(&self) -> bool {
5256
match self {
5357
OptVersionReq::Any => false,
54-
OptVersionReq::Req(req) | OptVersionReq::UpdatePrecise(_, req) => {
58+
OptVersionReq::Req(req) | OptVersionReq::Precise(_, req) => {
5559
req.comparators.len() == 1 && {
5660
let cmp = &req.comparators[0];
5761
cmp.op == Op::Exact && cmp.minor.is_some() && cmp.patch.is_some()
@@ -67,18 +71,19 @@ impl OptVersionReq {
6771
let version = version.clone();
6872
*self = match self {
6973
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()),
7175
};
7276
}
7377

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) {
7582
use OptVersionReq::*;
7683
let version = version.clone();
7784
*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()),
8287
};
8388
}
8489

@@ -108,7 +113,7 @@ impl OptVersionReq {
108113
// we should not silently use `1.0.0+foo` even though they have the same version.
109114
v == version
110115
}
111-
OptVersionReq::UpdatePrecise(v, _) => {
116+
OptVersionReq::Precise(v, _) => {
112117
// This is used for the `--precise` field of cargo update.
113118
//
114119
// Unfortunately crates.io allowed versions to differ only
@@ -135,7 +140,7 @@ impl Display for OptVersionReq {
135140
OptVersionReq::Any => f.write_str("*"),
136141
OptVersionReq::Req(req)
137142
| OptVersionReq::Locked(_, req)
138-
| OptVersionReq::UpdatePrecise(_, req) => Display::fmt(req, f),
143+
| OptVersionReq::Precise(_, req) => Display::fmt(req, f),
139144
}
140145
}
141146
}

0 commit comments

Comments
 (0)