Skip to content

Commit e8a78cc

Browse files
committed
Auto merge of #9789 - ehuss:fix-value-after-table-profile, r=alexcrichton
Fix value-after-table error with profiles. If the `strip`, `dir-name`, or `inherits` fields were included along with a profile override, then `cargo publish` would fail with a `ValueAfterTable` error because the fields were listed in the wrong order in the struct definition. Fixes #9787
2 parents ddf9adb + f0909c7 commit e8a78cc

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

src/cargo/util/toml/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,11 +442,13 @@ pub struct TomlProfile {
442442
pub panic: Option<String>,
443443
pub overflow_checks: Option<bool>,
444444
pub incremental: Option<bool>,
445-
pub package: Option<BTreeMap<ProfilePackageSpec, TomlProfile>>,
446-
pub build_override: Option<Box<TomlProfile>>,
447445
pub dir_name: Option<InternedString>,
448446
pub inherits: Option<InternedString>,
449447
pub strip: Option<StringOrBool>,
448+
// These two fields must be last because they are sub-tables, and TOML
449+
// requires all non-tables to be listed first.
450+
pub package: Option<BTreeMap<ProfilePackageSpec, TomlProfile>>,
451+
pub build_override: Option<Box<TomlProfile>>,
450452
}
451453

452454
#[derive(Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash)]

tests/testsuite/config.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Tests for config settings.
22
3-
use cargo::core::Shell;
3+
use cargo::core::{PackageIdSpec, Shell};
44
use cargo::util::config::{self, Config, SslVersionConfig, StringList};
55
use cargo::util::interning::InternedString;
66
use cargo::util::toml::{self, VecStringOrBool as VSOB};
@@ -1461,3 +1461,38 @@ fn cargo_target_empty_env() {
14611461
.with_status(101)
14621462
.run()
14631463
}
1464+
1465+
#[cargo_test]
1466+
fn all_profile_options() {
1467+
// Check that all profile options can be serialized/deserialized.
1468+
let base_settings = toml::TomlProfile {
1469+
opt_level: Some(toml::TomlOptLevel("0".to_string())),
1470+
lto: Some(toml::StringOrBool::String("thin".to_string())),
1471+
codegen_backend: Some(InternedString::new("example")),
1472+
codegen_units: Some(123),
1473+
debug: Some(toml::U32OrBool::U32(1)),
1474+
split_debuginfo: Some("packed".to_string()),
1475+
debug_assertions: Some(true),
1476+
rpath: Some(true),
1477+
panic: Some("abort".to_string()),
1478+
overflow_checks: Some(true),
1479+
incremental: Some(true),
1480+
dir_name: Some(InternedString::new("dir_name")),
1481+
inherits: Some(InternedString::new("debug")),
1482+
strip: Some(toml::StringOrBool::String("symbols".to_string())),
1483+
package: None,
1484+
build_override: None,
1485+
};
1486+
let mut overrides = BTreeMap::new();
1487+
let key = toml::ProfilePackageSpec::Spec(PackageIdSpec::parse("foo").unwrap());
1488+
overrides.insert(key, base_settings.clone());
1489+
let profile = toml::TomlProfile {
1490+
build_override: Some(Box::new(base_settings.clone())),
1491+
package: Some(overrides),
1492+
..base_settings.clone()
1493+
};
1494+
let profile_toml = ::toml::to_string(&profile).unwrap();
1495+
let roundtrip: toml::TomlProfile = ::toml::from_str(&profile_toml).unwrap();
1496+
let roundtrip_toml = ::toml::to_string(&roundtrip).unwrap();
1497+
compare::assert_match_exact(&profile_toml, &roundtrip_toml);
1498+
}

0 commit comments

Comments
 (0)