Skip to content

Commit

Permalink
Auto merge of #5908 - orium:fix-package-cargo-toml, r=alexcrichton
Browse files Browse the repository at this point in the history
Fix serialization bug in `edition` field of `TomlProject`.

Fixes #5906.
  • Loading branch information
bors committed Aug 19, 2018
2 parents a78f5aa + 8590a5f commit cc88d01
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
name: String,
version: semver::Version,
authors: Option<Vec<String>>,
Expand Down Expand Up @@ -604,7 +611,6 @@ pub struct TomlProject {
license_file: Option<String>,
repository: Option<String>,
metadata: Option<toml::Value>,
edition: Option<String>,
}

#[derive(Debug, Deserialize, Serialize)]
Expand Down
26 changes: 26 additions & 0 deletions tests/testsuite/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,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
Expand Down

0 comments on commit cc88d01

Please sign in to comment.