summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrozolotl <44589151+frozolotl@users.noreply.github.com>2025-07-09 14:04:22 +0200
committerGitHub <noreply@github.com>2025-07-09 12:04:22 +0000
commit9e6adb6f4577a7bfdd119163168e8c6902bd1b21 (patch)
treecd5ce6dc9c8c27685e7211d81b1574050d163fe5
parent4534167656f34ea2a459fcc526ba41c6a89a5314 (diff)
Ignore spans when checking for RawElem equality (#6560)
-rw-r--r--crates/typst-library/src/text/raw.rs22
-rw-r--r--tests/suite/text/raw.typ5
2 files changed, 26 insertions, 1 deletions
diff --git a/crates/typst-library/src/text/raw.rs b/crates/typst-library/src/text/raw.rs
index 8cddfbfb..0e61a8ef 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<RawElem> {
}
/// 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 a7f58a8d..827edaf8 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"