Skip to content

Commit 8dd5336

Browse files
committed
Auto merge of #9384 - alexcrichton:fix-order, r=ehuss
Fix disagreement about lockfile ordering on stable/nightly This commit fixes an issue where the order of packages serialized into a lock file differs on stable vs nightly. This is due to a bug introduced in #9133 where a manual `Ord` implementation was replaced with a `#[derive]`'d one. This was an unintended consequence of #9133 and means that the same lock file produced by two different versions of Cargo only differs in what order items are serialized. With #9133 being reverted soon on the current beta channel this is intended to be the nightly fix for #9334. This will hopefully mean that those projects which don't build with beta/nightly will remain unaffected, and those affected on beta/nightly will need to switch to the new nightly ordering when it's published (which matches the current stable). The reverted beta will match this ordering as well. Closes #9334
2 parents fb0130c + eb6e1b3 commit 8dd5336

File tree

2 files changed

+77
-2
lines changed

2 files changed

+77
-2
lines changed

src/cargo/core/source/source_id.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ struct SourceIdInner {
4444
/// source.
4545
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
4646
enum SourceKind {
47-
/// A git repository.
48-
Git(GitReference),
47+
// Note that the ordering here is important for how it affects the `Ord`
48+
// implementation, notably how this affects the ordering of serialized
49+
// packages into lock files.
4950
/// A local path..
5051
Path,
5152
/// A remote registry.
@@ -54,6 +55,8 @@ enum SourceKind {
5455
LocalRegistry,
5556
/// A directory-based registry.
5657
Directory,
58+
/// A git repository.
59+
Git(GitReference),
5760
}
5861

5962
/// Information to find a specific commit in a Git repository.

tests/testsuite/lockfile_compat.rs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,3 +771,75 @@ dependencies = [
771771

772772
p.cargo("build --locked").run();
773773
}
774+
775+
#[cargo_test]
776+
fn same_name_version_different_sources() {
777+
let cksum = Package::new("foo", "0.1.0").publish();
778+
let (git_project, repo) = git::new_repo("dep1", |project| {
779+
project
780+
.file(
781+
"Cargo.toml",
782+
r#"
783+
[project]
784+
name = "foo"
785+
version = "0.1.0"
786+
"#,
787+
)
788+
.file("src/lib.rs", "")
789+
});
790+
let head_id = repo.head().unwrap().target().unwrap();
791+
792+
// Lockfile was generated with Rust 1.51
793+
let lockfile = format!(
794+
r#"# This file is automatically @generated by Cargo.
795+
# It is not intended for manual editing.
796+
version = 3
797+
798+
[[package]]
799+
name = "foo"
800+
version = "0.1.0"
801+
dependencies = [
802+
"foo 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
803+
"foo 0.1.0 (git+{url})",
804+
]
805+
806+
[[package]]
807+
name = "foo"
808+
version = "0.1.0"
809+
source = "registry+https://github.com/rust-lang/crates.io-index"
810+
checksum = "{cksum}"
811+
812+
[[package]]
813+
name = "foo"
814+
version = "0.1.0"
815+
source = "git+{url}#{sha}"
816+
"#,
817+
sha = head_id,
818+
url = git_project.url(),
819+
cksum = cksum
820+
);
821+
822+
let p = project()
823+
.file(
824+
"Cargo.toml",
825+
&format!(
826+
r#"
827+
[project]
828+
name = "foo"
829+
version = "0.1.0"
830+
831+
[dependencies]
832+
foo = "0.1.0"
833+
foo2 = {{ git = '{}', package = 'foo' }}
834+
"#,
835+
git_project.url(),
836+
),
837+
)
838+
.file("src/lib.rs", "")
839+
.file("Cargo.lock", &lockfile)
840+
.build();
841+
842+
p.cargo("build").run();
843+
844+
assert_eq!(p.read_file("Cargo.lock"), lockfile);
845+
}

0 commit comments

Comments
 (0)