Skip to content

Commit c6762ce

Browse files
committed
Update synthetic locked version_req to real locked
Previously we use exact semver version req to synthesize locked version req. Now we make those need a truly locked to be `OptVersionReq::Locked`.
1 parent d6fd499 commit c6762ce

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

src/cargo/core/dependency.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,6 @@ impl Dependency {
320320
/// Locks this dependency to depending on the specified package ID.
321321
pub fn lock_to(&mut self, id: PackageId) -> &mut Dependency {
322322
assert_eq!(self.inner.source_id, id.source_id());
323-
assert!(self.inner.req.matches(id.version()));
324323
trace!(
325324
"locking dep from `{}` with `{}` at {} to {}",
326325
self.package_name(),
@@ -329,7 +328,7 @@ impl Dependency {
329328
id
330329
);
331330
let me = Rc::make_mut(&mut self.inner);
332-
me.req = OptVersionReq::exact(id.version());
331+
me.req.lock_to(id.version());
333332

334333
// Only update the `precise` of this source to preserve other
335334
// information about dependency's source which may not otherwise be
@@ -340,10 +339,10 @@ impl Dependency {
340339
self
341340
}
342341

343-
/// Returns `true` if this is a "locked" dependency, basically whether it has
344-
/// an exact version req.
342+
/// Returns `true` if this is a "locked" dependency. Basically a locked
343+
/// dependency has an exact version req, but not vice versa.
345344
pub fn is_locked(&self) -> bool {
346-
self.inner.req.is_exact()
345+
self.inner.req.is_locked()
347346
}
348347

349348
/// Returns `false` if the dependency is only used to build the local package.

src/cargo/core/registry.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ use crate::core::{Dependency, PackageId, Source, SourceId, SourceMap, Summary};
55
use crate::sources::config::SourceConfigMap;
66
use crate::util::errors::CargoResult;
77
use crate::util::interning::InternedString;
8-
use crate::util::{profile, CanonicalUrl, Config, VersionReqExt};
8+
use crate::util::{profile, CanonicalUrl, Config};
99
use anyhow::{bail, Context as _};
1010
use log::{debug, trace};
11-
use semver::VersionReq;
1211
use url::Url;
1312

1413
/// Source of information about a group of packages.
@@ -765,8 +764,7 @@ fn lock(
765764
if locked.source_id() == dep.source_id() {
766765
dep.lock_to(locked);
767766
} else {
768-
let req = VersionReq::exact(locked.version());
769-
dep.set_version_req(req);
767+
dep.lock_version(locked.version());
770768
}
771769
return dep;
772770
}

src/cargo/ops/cargo_install.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ fn installed_exact_package<T>(
681681
where
682682
T: Source,
683683
{
684-
if !dep.is_locked() {
684+
if !dep.version_req().is_exact() {
685685
// If the version isn't exact, we may need to update the registry and look for a newer
686686
// version - we can't know if the package is installed without doing so.
687687
return Ok(None);

0 commit comments

Comments
 (0)