Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix serialization bug in edition field of TomlProject. #5908

Merged
merged 1 commit into from
Aug 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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
Expand Down