From 0c93ca80f44587ec864529c49b81dc5fe4911b7c Mon Sep 17 00:00:00 2001 From: cyqsimon <28627918+cyqsimon@users.noreply.github.com> Date: Sun, 5 Nov 2023 01:18:08 +0800 Subject: [PATCH] Guard against duplicate matchers in build script --- build/syntax_mapping.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/build/syntax_mapping.rs b/build/syntax_mapping.rs index cecf8ef5..0b4b5cd4 100644 --- a/build/syntax_mapping.rs +++ b/build/syntax_mapping.rs @@ -38,7 +38,7 @@ impl MappingTarget { } } -#[derive(Clone, Debug, DeserializeFromStr)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, DeserializeFromStr)] /// A single matcher. /// /// Codegen converts this into a `Lazy`. @@ -124,7 +124,7 @@ impl Matcher { /// A segment in a matcher. /// /// Corresponds to `syntax_mapping::MatcherSegment`. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] enum MatcherSegment { Text(String), Env(String), @@ -196,6 +196,14 @@ fn read_all_mappings() -> anyhow::Result { all_mappings.extend(mappings.0); } + let duplicates = all_mappings + .iter() + .duplicates_by(|(matcher, _)| matcher) + .collect_vec(); + if !duplicates.is_empty() { + bail!("Rules with duplicate matchers found: {duplicates:?}"); + } + Ok(MappingList(all_mappings)) }