mirror of
https://github.com/rust-lang/cargo
synced 2024-10-13 03:02:45 +00:00
refactor: rename items in OptVersionReq
* `OptVersionReq::update_precise` to `precise_to` * `OptVersionReq::UpdatePrecise` to `Precise`
This commit is contained in:
parent
70e7868ddb
commit
515f6e3f9d
|
@ -748,7 +748,7 @@ impl<'cfg> Source for RegistrySource<'cfg> {
|
|||
.precise_registry_version(dep.package_name().as_str())
|
||||
.filter(|(c, _)| req.matches(c))
|
||||
{
|
||||
req.update_precise(&requested);
|
||||
req.precise_to(&requested);
|
||||
}
|
||||
|
||||
let mut called = false;
|
||||
|
|
|
@ -33,7 +33,11 @@ pub enum OptVersionReq {
|
|||
/// The exact locked version and the original version requirement.
|
||||
Locked(Version, VersionReq),
|
||||
/// The exact requested version and the original version requirement.
|
||||
UpdatePrecise(Version, VersionReq),
|
||||
///
|
||||
/// This looks identical to [`OptVersionReq::Locked`] but has a different
|
||||
/// meaning, and is used for the `--precise` field of `cargo update`.
|
||||
/// See comments in [`OptVersionReq::matches`] for more.
|
||||
Precise(Version, VersionReq),
|
||||
}
|
||||
|
||||
impl OptVersionReq {
|
||||
|
@ -51,7 +55,7 @@ impl OptVersionReq {
|
|||
pub fn is_exact(&self) -> bool {
|
||||
match self {
|
||||
OptVersionReq::Any => false,
|
||||
OptVersionReq::Req(req) | OptVersionReq::UpdatePrecise(_, req) => {
|
||||
OptVersionReq::Req(req) | OptVersionReq::Precise(_, req) => {
|
||||
req.comparators.len() == 1 && {
|
||||
let cmp = &req.comparators[0];
|
||||
cmp.op == Op::Exact && cmp.minor.is_some() && cmp.patch.is_some()
|
||||
|
@ -67,18 +71,19 @@ impl OptVersionReq {
|
|||
let version = version.clone();
|
||||
*self = match self {
|
||||
Any => Locked(version, VersionReq::STAR),
|
||||
Req(req) | Locked(_, req) | UpdatePrecise(_, req) => Locked(version, req.clone()),
|
||||
Req(req) | Locked(_, req) | Precise(_, req) => Locked(version, req.clone()),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn update_precise(&mut self, version: &Version) {
|
||||
/// Makes the requirement precise to the requested version.
|
||||
///
|
||||
/// This is used for the `--precise` field of `cargo update`.
|
||||
pub fn precise_to(&mut self, version: &Version) {
|
||||
use OptVersionReq::*;
|
||||
let version = version.clone();
|
||||
*self = match self {
|
||||
Any => UpdatePrecise(version, VersionReq::STAR),
|
||||
Req(req) | Locked(_, req) | UpdatePrecise(_, req) => {
|
||||
UpdatePrecise(version, req.clone())
|
||||
}
|
||||
Any => Precise(version, VersionReq::STAR),
|
||||
Req(req) | Locked(_, req) | Precise(_, req) => Precise(version, req.clone()),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -108,7 +113,7 @@ impl OptVersionReq {
|
|||
// we should not silently use `1.0.0+foo` even though they have the same version.
|
||||
v == version
|
||||
}
|
||||
OptVersionReq::UpdatePrecise(v, _) => {
|
||||
OptVersionReq::Precise(v, _) => {
|
||||
// This is used for the `--precise` field of cargo update.
|
||||
//
|
||||
// Unfortunately crates.io allowed versions to differ only
|
||||
|
@ -135,7 +140,7 @@ impl Display for OptVersionReq {
|
|||
OptVersionReq::Any => f.write_str("*"),
|
||||
OptVersionReq::Req(req)
|
||||
| OptVersionReq::Locked(_, req)
|
||||
| OptVersionReq::UpdatePrecise(_, req) => Display::fmt(req, f),
|
||||
| OptVersionReq::Precise(_, req) => Display::fmt(req, f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue