diff --git a/niri-config/src/binds.rs b/niri-config/src/binds.rs index 27eeee3e..724a36d4 100644 --- a/niri-config/src/binds.rs +++ b/niri-config/src/binds.rs @@ -1,5 +1,3 @@ -use std::collections::hash_map::Entry; -use std::collections::HashMap; use std::str::FromStr; use std::time::Duration; @@ -779,9 +777,8 @@ where ) -> Result> { expect_only_children(node, ctx); - let mut seen_keys: HashMap> = HashMap::new(); - - let mut binds = Vec::new(); + let mut nodes: Vec<&knuffel::ast::SpannedNode> = Vec::new(); + let mut binds: Vec = Vec::new(); for child in node.children() { match Bind::decode_node(child, ctx) { @@ -789,26 +786,24 @@ where ctx.emit_error(e); } Ok(bind) => { - match seen_keys.entry(bind.key) { - Entry::Occupied(entry) => { - // Even though it's technically incorrect, we use - // `DecodeError::Missing` here because it labels the bind with - // "node starts here", which is the least bad option - ctx.emit_error(DecodeError::missing( - entry.get(), - "keybind first defined here", - )); + let conflict = binds.iter().position(|prev| prev.key == bind.key); + if let Some(idx) = conflict { + // Even though it's technically incorrect, we use + // `DecodeError::Missing` here because it labels the bind with + // "node starts here", which is the least bad option + ctx.emit_error(DecodeError::missing( + nodes[idx], + "keybind first defined here", + )); - ctx.emit_error(DecodeError::unexpected( - &child.node_name, - "keybind", - "duplicate keybind later defined here", - )); - } - Entry::Vacant(entry) => { - entry.insert(child); - binds.push(bind); - } + ctx.emit_error(DecodeError::unexpected( + &child.node_name, + "keybind", + "duplicate keybind later defined here", + )); + } else { + nodes.push(child); + binds.push(bind); } } } diff --git a/niri-config/src/recent_windows.rs b/niri-config/src/recent_windows.rs index 1846f03a..62480a40 100644 --- a/niri-config/src/recent_windows.rs +++ b/niri-config/src/recent_windows.rs @@ -1,5 +1,3 @@ -use std::collections::HashSet; - use knuffel::errors::DecodeError; use smithay::input::keyboard::Keysym; @@ -262,26 +260,34 @@ where ) -> Result> { expect_only_children(node, ctx); - let mut seen_keys = HashSet::new(); - - let mut binds = Vec::new(); + let mut nodes: Vec<&knuffel::ast::SpannedNode> = Vec::new(); + let mut binds: Vec = Vec::new(); for child in node.children() { match MruBind::decode_node(child, ctx) { + Err(e) => { + ctx.emit_error(e); + } Ok(bind) => { - if !seen_keys.insert(bind.key) { + let conflict = binds.iter().position(|prev| prev.key == bind.key); + if let Some(idx) = conflict { + // Even though it's technically incorrect, we use + // `DecodeError::Missing` here because it labels the bind with + // "node starts here", which is the least bad option + ctx.emit_error(DecodeError::missing( + nodes[idx], + "keybind first defined here", + )); + ctx.emit_error(DecodeError::unexpected( &child.node_name, "keybind", - "duplicate keybind", + "duplicate keybind later defined here", )); - continue; + } else { + nodes.push(child); + binds.push(bind); } - - binds.push(bind); - } - Err(e) => { - ctx.emit_error(e); } } }