From 129f4da371f998d1ec67f8774f4be32c243d0b8f Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 25 Mar 2021 09:13:40 -0700 Subject: [PATCH] Fix publication of packages with metadata and resolver This commit fixes an issue where packages which specify `resolver = '2'` cannot be packaged if they also have a `package.metadata` table. The issue is that the `toml` serialization implementation serializes fields in order which requires that tables be emitted last. --- src/cargo/util/toml/mod.rs | 10 ++++++++-- tests/testsuite/package.rs | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 7f7aadb4ca5..733a5c5b58c 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -889,8 +889,11 @@ pub struct TomlProject { license: Option, license_file: Option, repository: Option, - metadata: Option, resolver: Option, + + // Note that this field must come last due to the way toml serialization + // works which requires tables to be emitted after all values. + metadata: Option, } #[derive(Debug, Deserialize, Serialize)] @@ -899,8 +902,11 @@ pub struct TomlWorkspace { #[serde(rename = "default-members")] default_members: Option>, exclude: Option>, - metadata: Option, resolver: Option, + + // Note that this field must come last due to the way toml serialization + // works which requires tables to be emitted after all values. + metadata: Option, } impl TomlProject { diff --git a/tests/testsuite/package.rs b/tests/testsuite/package.rs index cbe998e82fb..df4371c58f0 100644 --- a/tests/testsuite/package.rs +++ b/tests/testsuite/package.rs @@ -1954,3 +1954,25 @@ fn reproducible_output() { assert_eq!(header.groupname().unwrap().unwrap(), ""); } } + +#[cargo_test] +fn package_with_resolver_and_metadata() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + resolver = '2' + + [package.metadata.docs.rs] + all-features = true + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("package").run(); +}