From 9e6adb6f4577a7bfdd119163168e8c6902bd1b21 Mon Sep 17 00:00:00 2001 From: frozolotl <44589151+frozolotl@users.noreply.github.com> Date: Wed, 9 Jul 2025 14:04:22 +0200 Subject: [PATCH] Ignore spans when checking for RawElem equality (#6560) --- crates/typst-library/src/text/raw.rs | 22 +++++++++++++++++++++- tests/suite/text/raw.typ | 5 +++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/crates/typst-library/src/text/raw.rs b/crates/typst-library/src/text/raw.rs index 8cddfbfb5..0e61a8ef1 100644 --- a/crates/typst-library/src/text/raw.rs +++ b/crates/typst-library/src/text/raw.rs @@ -456,7 +456,11 @@ impl PlainText for Packed { } /// The content of the raw text. -#[derive(Debug, Clone, Hash, PartialEq)] +#[derive(Debug, Clone, Hash)] +#[allow( + clippy::derived_hash_with_manual_eq, + reason = "https://github.com/typst/typst/pull/6560#issuecomment-3045393640" +)] pub enum RawContent { /// From a string. Text(EcoString), @@ -481,6 +485,22 @@ impl RawContent { } } +impl PartialEq for RawContent { + fn eq(&self, other: &Self) -> bool { + match (self, other) { + (RawContent::Text(a), RawContent::Text(b)) => a == b, + (lines @ RawContent::Lines(_), RawContent::Text(text)) + | (RawContent::Text(text), lines @ RawContent::Lines(_)) => { + *text == lines.get() + } + (RawContent::Lines(a), RawContent::Lines(b)) => Iterator::eq( + a.iter().map(|(line, _)| line), + b.iter().map(|(line, _)| line), + ), + } + } +} + cast! { RawContent, self => self.get().into_value(), diff --git a/tests/suite/text/raw.typ b/tests/suite/text/raw.typ index a7f58a8d0..827edaf8c 100644 --- a/tests/suite/text/raw.typ +++ b/tests/suite/text/raw.typ @@ -687,6 +687,11 @@ a b c -------------------- #let hi = "你好world" ``` +--- issue-6559-equality-between-raws --- + +#test(`foo`, `foo`) +#assert.ne(`foo`, `bar`) + --- raw-theme-set-to-auto --- ```typ #let hi = "Hello World"