Skip to content

Commit 5ef7b7c

Browse files
committed
feat: stabilize lockfile v4
1 parent 0820fa1 commit 5ef7b7c

File tree

4 files changed

+11
-70
lines changed

4 files changed

+11
-70
lines changed

src/cargo/core/resolver/encode.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -154,18 +154,11 @@ impl EncodableResolve {
154154
/// primary uses is to be used with `resolve_with_previous` to guide the
155155
/// resolver to create a complete Resolve.
156156
pub fn into_resolve(self, original: &str, ws: &Workspace<'_>) -> CargoResult<Resolve> {
157-
let unstable_lockfile_version_allowed = ws.config().cli_unstable().next_lockfile_bump;
158157
let path_deps = build_path_deps(ws)?;
159158
let mut checksums = HashMap::new();
160159

161160
let mut version = match self.version {
162-
Some(4) if ws.config().nightly_features_allowed => {
163-
if unstable_lockfile_version_allowed {
164-
ResolveVersion::V4
165-
} else {
166-
anyhow::bail!("lock file version 4 requires `-Znext-lockfile-bump`");
167-
}
168-
}
161+
Some(4) => ResolveVersion::V4,
169162
Some(3) => ResolveVersion::V3,
170163
Some(n) => bail!(
171164
"lock file version `{}` was found, but this version of Cargo \
@@ -797,9 +790,10 @@ fn encodable_source_id(id: SourceId, version: ResolveVersion) -> Option<Encodabl
797790
if id.is_path() {
798791
None
799792
} else {
793+
use ResolveVersion::*;
800794
Some(match version {
801-
ResolveVersion::V4 => EncodableSourceId::new(id),
802-
_ => EncodableSourceId::without_url_encoded(id),
795+
V4 => EncodableSourceId::new(id),
796+
V1 | V2 | V3 => EncodableSourceId::without_url_encoded(id),
803797
})
804798
}
805799
}

src/cargo/core/resolver/resolve.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,9 @@ pub enum ResolveVersion {
8080
/// V3 by default staring in 1.53.
8181
#[default]
8282
V3,
83-
/// Unstable. Will collect a certain amount of changes and then go.
84-
///
85-
/// Changes made:
86-
///
87-
/// * SourceId URL serialization is aware of URL encoding.
83+
/// SourceId URL serialization is aware of URL encoding. For example,
84+
/// `?branch=foo bar` is now encoded as `?branch=foo+bar` and can be decoded
85+
/// back and forth correctly. Introduced in 2023 in version 1.75.
8886
V4,
8987
}
9088

src/cargo/ops/lockfile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub fn write_pkg_lockfile(ws: &Workspace<'_>, resolve: &mut Resolve) -> CargoRes
6767
if resolve.version() < ResolveVersion::default() {
6868
resolve.set_version(ResolveVersion::default());
6969
out = serialize_resolve(resolve, orig.as_deref());
70-
} else if resolve.version() > ResolveVersion::default()
70+
} else if resolve.version() > ResolveVersion::V4
7171
&& !ws.config().cli_unstable().next_lockfile_bump
7272
{
7373
// The next version hasn't yet stabilized.

tests/testsuite/lockfile_compat.rs

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -889,51 +889,6 @@ perhaps a crate was updated and forgotten to be re-vendored?
889889
.run();
890890
}
891891

892-
#[cargo_test]
893-
fn v4_is_unstable() {
894-
let p = project()
895-
.file(
896-
"Cargo.toml",
897-
&format!(
898-
r#"
899-
[package]
900-
name = "foo"
901-
version = "0.0.1"
902-
"#,
903-
),
904-
)
905-
.file("src/lib.rs", "")
906-
.file("Cargo.lock", "version = 4")
907-
.build();
908-
909-
p.cargo("fetch")
910-
.with_status(101)
911-
.with_stderr(
912-
"\
913-
error: failed to parse lock file at: [CWD]/Cargo.lock
914-
915-
Caused by:
916-
lock file version `4` was found, but this version of Cargo does not \
917-
understand this lock file, perhaps Cargo needs to be updated?
918-
",
919-
)
920-
.run();
921-
922-
// On nightly, let the user know about the `-Z` flag.
923-
p.cargo("fetch")
924-
.masquerade_as_nightly_cargo(&["-Znext-lockfile-bump"])
925-
.with_status(101)
926-
.with_stderr(
927-
"\
928-
error: failed to parse lock file at: [CWD]/Cargo.lock
929-
930-
Caused by:
931-
lock file version 4 requires `-Znext-lockfile-bump`
932-
",
933-
)
934-
.run();
935-
}
936-
937892
#[cargo_test]
938893
fn v4_cannot_be_created_from_scratch() {
939894
let p = project()
@@ -950,9 +905,7 @@ fn v4_cannot_be_created_from_scratch() {
950905
.file("src/lib.rs", "")
951906
.build();
952907

953-
p.cargo("fetch -Znext-lockfile-bump")
954-
.masquerade_as_nightly_cargo(&["-Znext-lockfile-bump"])
955-
.run();
908+
p.cargo("fetch").run();
956909

957910
let lockfile = r#"# This file is automatically @generated by Cargo.
958911
# It is not intended for manual editing.
@@ -1124,8 +1077,7 @@ dependencies = [
11241077
.file("Cargo.lock", "version = 4")
11251078
.build();
11261079

1127-
p.cargo("check -Znext-lockfile-bump")
1128-
.masquerade_as_nightly_cargo(&["-Znext-lockfile-bump"])
1080+
p.cargo("check")
11291081
.with_stderr(format!(
11301082
"\
11311083
[UPDATING] git repository `{url}`
@@ -1141,10 +1093,7 @@ dependencies = [
11411093

11421094
// Unlike v3_and_git_url_encoded, v4 encodes URL parameters so no git
11431095
// repository re-clone happen.
1144-
p.cargo("check -Znext-lockfile-bump")
1145-
.masquerade_as_nightly_cargo(&["-Znext-lockfile-bump"])
1146-
.with_stderr("[FINISHED] dev [..]")
1147-
.run();
1096+
p.cargo("check").with_stderr("[FINISHED] dev [..]").run();
11481097
}
11491098

11501099
#[cargo_test]

0 commit comments

Comments
 (0)