Skip to content

Commit cc88d01

Browse files
committed
Auto merge of #5908 - orium:fix-package-cargo-toml, r=alexcrichton
Fix serialization bug in `edition` field of `TomlProject`. Fixes #5906.
2 parents a78f5aa + 8590a5f commit cc88d01

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/cargo/util/toml/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,15 @@ impl<'de> de::Deserialize<'de> for VecStringOrBool {
568568
}
569569
}
570570

571+
/// Represents the `package`/`project` sections of a `Cargo.toml`.
572+
///
573+
/// Note that the order of the fields matters, since this is the order they
574+
/// are serialized to a TOML file. For example, you cannot have values after
575+
/// the field `metadata`, since it is a table and values cannot appear after
576+
/// tables.
571577
#[derive(Deserialize, Serialize, Clone, Debug)]
572578
pub struct TomlProject {
579+
edition: Option<String>,
573580
name: String,
574581
version: semver::Version,
575582
authors: Option<Vec<String>>,
@@ -604,7 +611,6 @@ pub struct TomlProject {
604611
license_file: Option<String>,
605612
repository: Option<String>,
606613
metadata: Option<toml::Value>,
607-
edition: Option<String>,
608614
}
609615

610616
#[derive(Debug, Deserialize, Serialize)]

tests/testsuite/package.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,32 @@ fn test_edition() {
965965
);
966966
}
967967

968+
#[test]
969+
fn edition_with_metadata() {
970+
if !is_nightly() { // --edition is nightly-only
971+
return;
972+
}
973+
974+
let p = project()
975+
.file("Cargo.toml", r#"
976+
cargo-features = ["edition"]
977+
[package]
978+
name = "foo"
979+
version = "0.0.1"
980+
authors = []
981+
edition = "2018"
982+
[package.metadata.docs.rs]
983+
features = ["foobar"]
984+
"#)
985+
.file("src/lib.rs", "")
986+
.build();
987+
988+
assert_that(
989+
p.cargo("package").masquerade_as_nightly_cargo(),
990+
execs(),
991+
);
992+
}
993+
968994
#[test]
969995
fn test_edition_missing() {
970996
// no edition = 2015

0 commit comments

Comments
 (0)