From 6e24868384408da8b542f70085f7a45a3c383fc7 Mon Sep 17 00:00:00 2001 From: David Wood Date: Tue, 21 Aug 2018 12:57:11 +0200 Subject: [PATCH] Normalize source line and column numbers. This commit adds a normalization for line and column numbers in stderr files where the line/col is from the source directory rather than the test itself - thereby removing the need to update tests as compiler source changes. --- src/test/ui/consts/const-size_of-cycle.stderr | 4 ++-- src/test/ui/impl-trait/impl-generic-mismatch.stderr | 2 +- src/tools/compiletest/src/runtest.rs | 7 +++++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/test/ui/consts/const-size_of-cycle.stderr b/src/test/ui/consts/const-size_of-cycle.stderr index b10dd509e0b13..16d87f7e31c9b 100644 --- a/src/test/ui/consts/const-size_of-cycle.stderr +++ b/src/test/ui/consts/const-size_of-cycle.stderr @@ -2,13 +2,13 @@ error[E0391]: cycle detected when computing layout of `Foo` | note: ...which requires normalizing `ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: All }, value: [u8; _] }`... note: ...which requires const-evaluating `Foo::bytes::{{constant}}`... - --> $SRC_DIR/libcore/mem.rs:323:14 + --> $SRC_DIR/libcore/mem.rs:LL:COL | LL | unsafe { intrinsics::size_of::() } | ^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: ...which again requires computing layout of `Foo`, completing the cycle note: cycle used when const-evaluating `Foo::bytes::{{constant}}` - --> $SRC_DIR/libcore/mem.rs:323:14 + --> $SRC_DIR/libcore/mem.rs:LL:COL | LL | unsafe { intrinsics::size_of::() } | ^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/impl-trait/impl-generic-mismatch.stderr b/src/test/ui/impl-trait/impl-generic-mismatch.stderr index a5f1580b60d2f..7ad16b1f8f237 100644 --- a/src/test/ui/impl-trait/impl-generic-mismatch.stderr +++ b/src/test/ui/impl-trait/impl-generic-mismatch.stderr @@ -30,7 +30,7 @@ error[E0643]: method `hash` has incompatible signature for trait LL | fn hash(&self, hasher: &mut impl Hasher) {} | ^^^^^^^^^^^ expected generic parameter, found `impl Trait` | - ::: $SRC_DIR/libcore/hash/mod.rs:185:13 + ::: $SRC_DIR/libcore/hash/mod.rs:LL:COL | LL | fn hash(&self, state: &mut H); | - declaration in trait here diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index b136173082600..24b575aae12f9 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -2963,6 +2963,13 @@ impl<'test> TestCx<'test> { normalized = normalized.replace("\\n", "\n"); } + // If there are `$SRC_DIR` normalizations with line and column numbers, then replace them + // with placeholders as we do not want tests needing updated when compiler source code + // changes. + // eg. $SRC_DIR/libcore/mem.rs:323:14 becomes $SRC_DIR/libcore/mem.rs:LL:COL + normalized = Regex::new("SRC_DIR(.+):\\d+:\\d+").unwrap() + .replace_all(&normalized, "SRC_DIR$1:LL:COL").into_owned(); + normalized = normalized.replace("\\\\", "\\") // denormalize for paths on windows .replace("\\", "/") // normalize for paths on windows .replace("\r\n", "\n") // normalize for linebreaks on windows