From f0909c7a6ca5c45d86c0c8bc4017253d8042db41 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sat, 14 Aug 2021 14:45:25 -0700 Subject: [PATCH] Fix value-after-table error with profiles. --- src/cargo/util/toml/mod.rs | 6 ++++-- tests/testsuite/config.rs | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index ee5abeeba..e1919c946 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -442,11 +442,13 @@ pub struct TomlProfile { pub panic: Option, pub overflow_checks: Option, pub incremental: Option, - pub package: Option>, - pub build_override: Option>, pub dir_name: Option, pub inherits: Option, pub strip: Option, + // These two fields must be last because they are sub-tables, and TOML + // requires all non-tables to be listed first. + pub package: Option>, + pub build_override: Option>, } #[derive(Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash)] diff --git a/tests/testsuite/config.rs b/tests/testsuite/config.rs index 77fac2c54..176fdd883 100644 --- a/tests/testsuite/config.rs +++ b/tests/testsuite/config.rs @@ -1,6 +1,6 @@ //! Tests for config settings. -use cargo::core::Shell; +use cargo::core::{PackageIdSpec, Shell}; use cargo::util::config::{self, Config, SslVersionConfig, StringList}; use cargo::util::interning::InternedString; use cargo::util::toml::{self, VecStringOrBool as VSOB}; @@ -1461,3 +1461,38 @@ fn cargo_target_empty_env() { .with_status(101) .run() } + +#[cargo_test] +fn all_profile_options() { + // Check that all profile options can be serialized/deserialized. + let base_settings = toml::TomlProfile { + opt_level: Some(toml::TomlOptLevel("0".to_string())), + lto: Some(toml::StringOrBool::String("thin".to_string())), + codegen_backend: Some(InternedString::new("example")), + codegen_units: Some(123), + debug: Some(toml::U32OrBool::U32(1)), + split_debuginfo: Some("packed".to_string()), + debug_assertions: Some(true), + rpath: Some(true), + panic: Some("abort".to_string()), + overflow_checks: Some(true), + incremental: Some(true), + dir_name: Some(InternedString::new("dir_name")), + inherits: Some(InternedString::new("debug")), + strip: Some(toml::StringOrBool::String("symbols".to_string())), + package: None, + build_override: None, + }; + let mut overrides = BTreeMap::new(); + let key = toml::ProfilePackageSpec::Spec(PackageIdSpec::parse("foo").unwrap()); + overrides.insert(key, base_settings.clone()); + let profile = toml::TomlProfile { + build_override: Some(Box::new(base_settings.clone())), + package: Some(overrides), + ..base_settings.clone() + }; + let profile_toml = ::toml::to_string(&profile).unwrap(); + let roundtrip: toml::TomlProfile = ::toml::from_str(&profile_toml).unwrap(); + let roundtrip_toml = ::toml::to_string(&roundtrip).unwrap(); + compare::assert_match_exact(&profile_toml, &roundtrip_toml); +} -- 2.39.5