Skip to content

Commit 6bc7455

Browse files
committed
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.
1 parent 56b3497 commit 6bc7455

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/cargo/util/toml/mod.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -815,8 +815,11 @@ pub struct TomlProject {
815815
license: Option<String>,
816816
license_file: Option<String>,
817817
repository: Option<String>,
818-
metadata: Option<toml::Value>,
819818
resolver: Option<String>,
819+
820+
// Note that this field must come last due to the way toml serialization
821+
// works which requires tables to be emitted after all values.
822+
metadata: Option<toml::Value>,
820823
}
821824

822825
#[derive(Debug, Deserialize, Serialize)]
@@ -825,8 +828,11 @@ pub struct TomlWorkspace {
825828
#[serde(rename = "default-members")]
826829
default_members: Option<Vec<String>>,
827830
exclude: Option<Vec<String>>,
828-
metadata: Option<toml::Value>,
829831
resolver: Option<String>,
832+
833+
// Note that this field must come last due to the way toml serialization
834+
// works which requires tables to be emitted after all values.
835+
metadata: Option<toml::Value>,
830836
}
831837

832838
impl TomlProject {

tests/testsuite/package.rs

+22
Original file line numberDiff line numberDiff line change
@@ -1954,3 +1954,25 @@ fn reproducible_output() {
19541954
assert_eq!(header.groupname().unwrap().unwrap(), "");
19551955
}
19561956
}
1957+
1958+
#[cargo_test]
1959+
fn package_with_resolver_and_metadata() {
1960+
let p = project()
1961+
.file(
1962+
"Cargo.toml",
1963+
r#"
1964+
[package]
1965+
name = "foo"
1966+
version = "0.0.1"
1967+
authors = []
1968+
resolver = '2'
1969+
1970+
[package.metadata.docs.rs]
1971+
all-features = true
1972+
"#,
1973+
)
1974+
.file("src/lib.rs", "")
1975+
.build();
1976+
1977+
p.cargo("package").run();
1978+
}

0 commit comments

Comments
 (0)