diff --git a/src/cargo/core/resolver/resolve.rs b/src/cargo/core/resolver/resolve.rs index 18a389773da9..70775b04c6d9 100644 --- a/src/cargo/core/resolver/resolve.rs +++ b/src/cargo/core/resolver/resolve.rs @@ -88,6 +88,17 @@ pub enum ResolveVersion { V4, } +impl ResolveVersion { + /// The maximum version of lockfile made into the stable channel. + /// + /// Any version larger than this needs `-Znext-lockfile-bump` to enable. ⋮ 97 │ /// ⋮ 98 │ /// Update this when you're going to stabilize a new lockfile version. + /// + /// Update this when you're going to stabilize a new lockfile version + pub fn max_stable() -> ResolveVersion { + ResolveVersion::V3 + } +} + impl Resolve { pub fn new( graph: Graph>, diff --git a/src/cargo/ops/lockfile.rs b/src/cargo/ops/lockfile.rs index aa05efd3559f..2160b6f01541 100644 --- a/src/cargo/ops/lockfile.rs +++ b/src/cargo/ops/lockfile.rs @@ -64,17 +64,16 @@ pub fn write_pkg_lockfile(ws: &Workspace<'_>, resolve: &mut Resolve) -> CargoRes // out lock file updates as they're otherwise already updated, and changes // which don't touch dependencies won't seemingly spuriously update the lock // file. - if resolve.version() < ResolveVersion::default() { - resolve.set_version(ResolveVersion::default()); + let default_version = ResolveVersion::default(); + let current_version = resolve.version(); + let next_lockfile_bump = ws.config().cli_unstable().next_lockfile_bump; + + if current_version < default_version { + resolve.set_version(default_version); out = serialize_resolve(resolve, orig.as_deref()); - } else if resolve.version() > ResolveVersion::default() - && !ws.config().cli_unstable().next_lockfile_bump - { + } else if current_version > ResolveVersion::max_stable() && !next_lockfile_bump { // The next version hasn't yet stabilized. - anyhow::bail!( - "lock file version `{:?}` requires `-Znext-lockfile-bump`", - resolve.version() - ) + anyhow::bail!("lock file version `{current_version:?}` requires `-Znext-lockfile-bump`") } // Ok, if that didn't work just write it out