Skip to content

Commit 9554b42

Browse files
committed
refactor: don't derive Default for ResolveVersion
This prevents a misuse of it.
1 parent d97256e commit 9554b42

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

crates/resolver-tests/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ pub fn resolve_with_config_raw(
175175
&[],
176176
&mut registry,
177177
&version_prefs,
178-
ResolveVersion::default(),
178+
ResolveVersion::with_rust_version(None),
179179
Some(config),
180180
);
181181

src/cargo/core/resolver/resolve.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub struct Resolve {
5151

5252
/// A version to indicate how a `Cargo.lock` should be serialized.
5353
///
54-
/// When creating a new lockfile, the version with `#[default]` is used.
54+
/// When creating a new lockfile, the version in [`ResolveVersion::default`] is used.
5555
/// If an old version of lockfile already exists, it will stay as-is.
5656
///
5757
/// It's important that if a new version is added that this is not updated
@@ -67,7 +67,7 @@ pub struct Resolve {
6767
///
6868
/// It's theorized that we can add more here over time to track larger changes
6969
/// to the `Cargo.lock` format, but we've yet to see how that strategy pans out.
70-
#[derive(Default, PartialEq, Eq, Clone, Copy, Debug, PartialOrd, Ord)]
70+
#[derive(PartialEq, Eq, Clone, Copy, Debug, PartialOrd, Ord)]
7171
pub enum ResolveVersion {
7272
/// Historical baseline for when this abstraction was added.
7373
V1,
@@ -81,7 +81,6 @@ pub enum ResolveVersion {
8181
/// `branch = "master"` are no longer encoded the same way as those without
8282
/// branch specifiers. Introduced in 2020 in version 1.47. New lockfiles use
8383
/// V3 by default staring in 1.53.
84-
#[default]
8584
V3,
8685
/// SourceId URL serialization is aware of URL encoding. For example,
8786
/// `?branch=foo bar` is now encoded as `?branch=foo+bar` and can be decoded
@@ -94,6 +93,17 @@ pub enum ResolveVersion {
9493
}
9594

9695
impl ResolveVersion {
96+
/// Gets the default lockfile version.
97+
///
98+
/// This is intended to be private.
99+
/// You shall use [`ResolveVersion::with_rust_version`] always.
100+
///
101+
/// Update this and the description of enum variants of [`ResolveVersion`]
102+
/// when we're changing the default lockfile version.
103+
fn default() -> ResolveVersion {
104+
ResolveVersion::V3
105+
}
106+
97107
/// The maximum version of lockfile made into the stable channel.
98108
///
99109
/// Any version larger than this needs `-Znext-lockfile-bump` to enable.

0 commit comments

Comments
 (0)