about summary refs log tree commit diff
diff options
context:
space:
mode:
authorZalathar <Zalathar@users.noreply.github.com>2024-07-11 21:17:09 +1000
committerZalathar <Zalathar@users.noreply.github.com>2024-07-11 21:51:20 +1000
commit08a2992d6bed7be4e673989965949b610c46e7e8 (patch)
tree397637be4c8ade1128233714df1b8f5b5a2d85ab
parentfdf7ea6b5b1cac83c0f29e681202cf18bf25b01c (diff)
downloadrust-08a2992d6bed7be4e673989965949b610c46e7e8.tar.gz
rust-08a2992d6bed7be4e673989965949b610c46e7e8.zip
compiletest: Better error message for bad `normalize-*` headers
-rw-r--r--src/tools/compiletest/src/header.rs18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs
index 7479be90797..7f5d4f4b416 100644
--- a/src/tools/compiletest/src/header.rs
+++ b/src/tools/compiletest/src/header.rs
@@ -991,13 +991,19 @@ impl Config {
     }
 
     fn parse_custom_normalization(&self, line: &str, prefix: &str) -> Option<(String, String)> {
-        if parse_cfg_name_directive(self, line, prefix).outcome == MatchOutcome::Match {
-            let (regex, replacement) = parse_normalize_rule(line)
-                .unwrap_or_else(|| panic!("couldn't parse custom normalization rule: `{line}`"));
-            Some((regex, replacement))
-        } else {
-            None
+        let parsed = parse_cfg_name_directive(self, line, prefix);
+        if parsed.outcome != MatchOutcome::Match {
+            return None;
         }
+        let name = parsed.name.expect("successful match always has a name");
+
+        let Some((regex, replacement)) = parse_normalize_rule(line) else {
+            panic!(
+                "couldn't parse custom normalization rule: `{line}`\n\
+                help: expected syntax is: `{prefix}-{name}: \"REGEX\" -> \"REPLACEMENT\"`"
+            );
+        };
+        Some((regex, replacement))
     }
 
     fn parse_name_directive(&self, line: &str, directive: &str) -> bool {