diff --git a/src/cargo/util/config/de.rs b/src/cargo/util/config/de.rs index ab8f96fbadf..1564a60f07d 100644 --- a/src/cargo/util/config/de.rs +++ b/src/cargo/util/config/de.rs @@ -195,11 +195,31 @@ impl<'de, 'config> de::Deserializer<'de> for Deserializer<'config> { } } + fn deserialize_enum( + self, + _name: &'static str, + _variants: &'static [&'static str], + visitor: V, + ) -> Result + where + V: de::Visitor<'de>, + { + let value = self + .config + .get_string_priv(&self.key)? + .ok_or_else(|| ConfigError::missing(&self.key))?; + + let Value { val, definition } = value; + visitor + .visit_enum(val.into_deserializer()) + .map_err(|e: ConfigError| e.with_key_context(&self.key, definition)) + } + // These aren't really supported, yet. serde::forward_to_deserialize_any! { f32 f64 char str bytes byte_buf unit unit_struct - enum identifier ignored_any + identifier ignored_any } } diff --git a/tests/testsuite/config.rs b/tests/testsuite/config.rs index 5771440e9da..29e79dba37a 100644 --- a/tests/testsuite/config.rs +++ b/tests/testsuite/config.rs @@ -1,5 +1,6 @@ //! Tests for config settings. +use cargo::core::profiles::Strip; use cargo::core::{enable_nightly_features, Shell}; use cargo::util::config::{self, Config, SslVersionConfig, StringList}; use cargo::util::interning::InternedString; @@ -1259,3 +1260,42 @@ fn string_list_advanced_env() { "error in environment variable `CARGO_KEY3`: expected string, found integer", ); } + +#[cargo_test] +fn parse_enum() { + write_config( + "\ +[profile.release] +strip = 'debuginfo' +", + ); + + let config = new_config(); + + let p: toml::TomlProfile = config.get("profile.release").unwrap(); + let strip = p.strip.unwrap(); + assert_eq!(strip, Strip::DebugInfo); +} + +#[cargo_test] +fn parse_enum_fail() { + write_config( + "\ +[profile.release] +strip = 'invalid' +", + ); + + let config = new_config(); + + assert_error( + config + .get::("profile.release") + .unwrap_err(), + "\ +error in [..]/.cargo/config: could not load config key `profile.release.strip` + +Caused by: + unknown variant `invalid`, expected one of `debuginfo`, `none`, `symbols`", + ); +}