From cb48ac92071c43a9163329b66b5f74a7fb3dca69 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Sat, 17 Jun 2023 22:41:28 +0200 Subject: Add errors for deserializing with unknown fields Currently there are still some places where `Deserialize` is used rather than `ConfigDeserialize`, which means that the built-in warning for unused fields is not emitted automatically. To ensure users don't have invalid configurations, the `#[serde(deny_unknown_fields)]` annotation has been added to these structs, making it a hard error when an unknown field is present. --- alacritty/src/config/color.rs | 1 + alacritty/src/config/ui_config.rs | 1 + alacritty_terminal/src/config/mod.rs | 4 ++-- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/alacritty/src/config/color.rs b/alacritty/src/config/color.rs index e08b08b4..2ded7f04 100644 --- a/alacritty/src/config/color.rs +++ b/alacritty/src/config/color.rs @@ -75,6 +75,7 @@ impl Default for HintEndColors { } #[derive(Deserialize, Copy, Clone, Default, Debug, PartialEq, Eq)] +#[serde(deny_unknown_fields)] pub struct IndexedColor { pub color: Rgb, diff --git a/alacritty/src/config/ui_config.rs b/alacritty/src/config/ui_config.rs index c4a1c83d..658d2ea8 100644 --- a/alacritty/src/config/ui_config.rs +++ b/alacritty/src/config/ui_config.rs @@ -455,6 +455,7 @@ impl<'de> Deserialize<'de> for HintContent { /// Binding for triggering a keyboard hint. #[derive(Deserialize, Copy, Clone, Debug, PartialEq, Eq)] +#[serde(deny_unknown_fields)] pub struct HintBinding { pub key: Key, #[serde(default)] diff --git a/alacritty_terminal/src/config/mod.rs b/alacritty_terminal/src/config/mod.rs index 2d921b6e..80be4d16 100644 --- a/alacritty_terminal/src/config/mod.rs +++ b/alacritty_terminal/src/config/mod.rs @@ -127,7 +127,7 @@ impl Cursor { } #[derive(SerdeReplace, Deserialize, Debug, Copy, Clone, PartialEq, Eq)] -#[serde(untagged)] +#[serde(untagged, deny_unknown_fields)] pub enum ConfigCursorStyle { Shape(CursorShapeShim), WithBlinking { @@ -191,7 +191,7 @@ impl From for bool { } #[derive(Deserialize, Debug, Clone, PartialEq, Eq)] -#[serde(untagged)] +#[serde(untagged, deny_unknown_fields)] pub enum Program { Just(String), WithArgs { -- cgit