From 8590a5fba4cd341f2798398454b6d4472ef5f69f Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Sat, 18 Aug 2018 23:21:01 +0100 Subject: [PATCH] Fix serialization bug in `edition` field of `TomlProject`. Fixes #5906. --- src/cargo/util/toml/mod.rs | 8 +++++++- tests/testsuite/package.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 32df6d07582..426fa2b0985 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -568,8 +568,15 @@ impl<'de> de::Deserialize<'de> for VecStringOrBool { } } +/// Represents the `package`/`project` sections of a `Cargo.toml`. +/// +/// Note that the order of the fields matters, since this is the order they +/// are serialized to a TOML file. For example, you cannot have values after +/// the field `metadata`, since it is a table and values cannot appear after +/// tables. #[derive(Deserialize, Serialize, Clone, Debug)] pub struct TomlProject { + edition: Option, name: String, version: semver::Version, authors: Option>, @@ -604,7 +611,6 @@ pub struct TomlProject { license_file: Option, repository: Option, metadata: Option, - edition: Option, } #[derive(Debug, Deserialize, Serialize)] diff --git a/tests/testsuite/package.rs b/tests/testsuite/package.rs index 55fe71eb423..70dda65c139 100644 --- a/tests/testsuite/package.rs +++ b/tests/testsuite/package.rs @@ -967,6 +967,32 @@ fn test_edition() { ); } +#[test] +fn edition_with_metadata() { + if !is_nightly() { // --edition is nightly-only + return; + } + + let p = project() + .file("Cargo.toml", r#" + cargo-features = ["edition"] + [package] + name = "foo" + version = "0.0.1" + authors = [] + edition = "2018" + [package.metadata.docs.rs] + features = ["foobar"] + "#) + .file("src/lib.rs", "") + .build(); + + assert_that( + p.cargo("package").masquerade_as_nightly_cargo(), + execs(), + ); +} + #[test] fn test_edition_missing() { // no edition = 2015