From 75a155bda18a9e95c566e9e45f168dede1bac6cc Mon Sep 17 00:00:00 2001 From: xmakro Date: Tue, 2 Jun 2026 18:18:22 -0700 Subject: [PATCH] compiletest: ignore SVG `y` offset in by-lines comparison SVG diagnostic snapshots (`--color=always`) render one terminal row per line. Under the parallel front-end, independent diagnostics can be emitted in a different order, which only permutes the rows and re-renders each at a different vertical `y` offset; the content of every row is unchanged. The parallel front-end already compares ui output as a sorted line multiset, but the `y` attribute is part of each line, so a pure reordering was still reported as a difference. Strip the `y` coordinate (and the `` header line, whose width and height are already ignored by the exact comparison) before the multiset comparison. The normalization is only used for the equality check; the original strings are kept for the diff and for blessing, and single-threaded runs keep the exact comparison including `y`. With this, the multiline-removal-suggestion test passes under the parallel front-end, so drop its ignore directive. --- src/tools/compiletest/src/runtest.rs | 36 ++++++++++++++++--- .../multiline-removal-suggestion.rs | 1 - 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 72817ad64521a..c60c0e73828b1 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -2714,11 +2714,37 @@ impl<'test> TestCx<'test> { (&tmp.0, &tmp.1) } } else if compare_output_by_lines { - let mut actual_lines: Vec<&str> = actual.lines().collect(); - let mut expected_lines: Vec<&str> = expected.lines().collect(); - actual_lines.sort_unstable(); - expected_lines.sort_unstable(); - if actual_lines == expected_lines { + // SVG output (`--color=always`) renders one terminal row per line, + // laid out top to bottom. Under the parallel front-end, independent + // diagnostics can be emitted in a different order, which permutes the + // rows and re-renders each at a different vertical `y` offset without + // changing its content. Strip the `y` coordinate (and the first line, + // the `` header whose width/height are already ignored by the + // exact comparison above) before the line-multiset comparison so that + // such a reordering is not reported as a difference. The normalization + // is comparison-only: on mismatch the original strings are kept for + // the diff and for blessing. Single-threaded runs take the + // exact-comparison path above and still check `y`. + let matches = if self.force_color_svg() { + let strip_y = static_regex!(r#"y="\d+px""#); + let normalize = |svg: &str| { + let mut lines: Vec = svg + .lines() + .skip(1) + .map(|line| strip_y.replace_all(line, r#"y="0px""#).into_owned()) + .collect(); + lines.sort_unstable(); + lines + }; + normalize(expected) == normalize(actual) + } else { + let mut actual_lines: Vec<&str> = actual.lines().collect(); + let mut expected_lines: Vec<&str> = expected.lines().collect(); + actual_lines.sort_unstable(); + expected_lines.sort_unstable(); + actual_lines == expected_lines + }; + if matches { return CompareOutcome::Same; } else { (expected, actual) diff --git a/tests/ui/error-emitter/multiline-removal-suggestion.rs b/tests/ui/error-emitter/multiline-removal-suggestion.rs index 36127ab13123a..72e9ea357c9e6 100644 --- a/tests/ui/error-emitter/multiline-removal-suggestion.rs +++ b/tests/ui/error-emitter/multiline-removal-suggestion.rs @@ -56,4 +56,3 @@ fn bay() -> Vec<(bool, HashSet)> { .collect() } fn main() {} -//@ ignore-parallel-frontend invalid svg(multiple threads trying to write to the same file)