Subject: bug#70794: 30.0.50; Add Rust compilation regex

From: Vincenzo Pupillo <[email-masked]>
Date: Mon, 19 May 2025 22:58:14 +0200

Ciao Mattias,

In data domenica 18 maggio 2025 13:09:16 Ora legale dell’Europa centrale, 
Mattias Engdegård ha scritto:
> 17 maj 2025 kl. 22.37 skrev Vincenzo Pupillo <[email-masked]>:
> > No, the spaces before the arrow vary according to the line number of the
> > error. The arrow is aligned with the vertical bar separating the line
> > number from the error description.
> 
> Thank you for finding that out. Then I think (repeat 1 6 " ") more
> complicated than it's worth; just (+ " ") will do (and is actually faster).

Done.
The patch is attached.

Thanks.
Vincenzo

>From 8de3d8916d4de5e1d1eecde50454a9d0a6b23947 Mon Sep 17 00:00:00 2001
From: Vincenzo Pupillo <[email-masked]>
Date: Mon, 19 May 2025 22:31:41 +0200
Subject: [PATCH] Support Rust compiler messages in compile mode (bug#70794).

* etc/compilation.txt: Add examples of Rust compiler error, warning and
note messages.
* lisp/progmodes/compile.el
(compilation-error-regexp-alist-alist): Add Rust regexps for error,
warning and note messages.
* test/lisp/progmodes/compile-tests.el
(compile-tests--test-regexps-data): Add new test cases.
(compile-test-error-regexps): Increase expected errors.
---
 etc/compilation.txt                  | 11 +++++++++++
 lisp/progmodes/compile.el            | 13 +++++++++++++
 test/lisp/progmodes/compile-tests.el | 15 ++++++++++++---
 3 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/etc/compilation.txt b/etc/compilation.txt
index 67c7000ae09..39d9c3a923c 100644
--- a/etc/compilation.txt
+++ b/etc/compilation.txt
@@ -487,6 +487,17 @@ symbol: php
 Parse error: parse error, unexpected $ in main.php on line 59
 Fatal error: Call to undefined function: mysql_pconnect() in db.inc on line 66
 
+* Rust
+
+symbol: rust
+
+error[E0277]: `Foo` is not an iterator
+  --> src/main.rs:4:16
+warning: borrow of packed field is unsafe and requires unsafe function or block (error E0133)
+  --> lint_example.rs:11:13
+note: required by a bound in `Trait`
+  --> src/auxiliary/trait-debuginfo.rs:23:18
+
 * Ruby
 
 symbol: ruby
diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el
index 1ca58b3ac7d..8cfa793cfc6 100644
--- a/lisp/progmodes/compile.el
+++ b/lisp/progmodes/compile.el
@@ -565,6 +565,19 @@ compilation-error-regexp-alist-alist
      "\\(?:Parse\\|Fatal\\) error: \\(.*\\) in \\(.*\\) on line \\([0-9]+\\)"
      2 3 nil nil)
 
+    (rust
+     ,(rx bol (or (group-n 1 "error") (group-n 2 "warning") (group-n 3 "note"))
+          (? "[" (+ (in "A-Z" "0-9")) "]") ":" (* nonl)
+          "\n" (+ " ") "-->"
+          " " (group-n 4 (+ nonl))        ; file
+          ":" (group-n 5 (+ (in "0-9")))  ; line
+          ":" (group-n 6 (+ (in "0-9")))) ; column
+     4 5 6 (2 . 3)
+     nil
+     (1 compilation-error-face)
+     (2 compilation-warning-face)
+     (3 compilation-info-face))
+
     (rxp
      "^\\(?:Error\\|Warnin\\(g\\)\\):.*\n.* line \\([0-9]+\\) char\
  \\([0-9]+\\) of file://\\(.+\\)"
diff --git a/test/lisp/progmodes/compile-tests.el b/test/lisp/progmodes/compile-tests.el
index b12e5d0b2d4..38d5d2bb43b 100644
--- a/test/lisp/progmodes/compile-tests.el
+++ b/test/lisp/progmodes/compile-tests.el
@@ -372,6 +372,15 @@ compile-tests--test-regexps-data
      1 nil 59 "main.php")
     (php "Fatal error: Call to undefined function: mysql_pconnect() in db.inc on line 66"
      1 nil 66 "db.inc")
+    ;; rust
+    (rust
+     "error[E0277]: `Foo` is not an iterator\n --> src/main.rs:4:16"
+     1 16 4 "src/main.rs")
+    (rust "warning: borrow of packed field is unsafe and requires unsafe function or block (error E0133)\n  --> lint_example.rs:11:13"
+           1 13 11 "lint_example.rs")
+    (rust
+     "note: required by a bound in `Trait`\n  --> src/auxiliary/trait-debuginfo.rs:23:18"
+     1 18 23 "src/auxiliary/trait-debuginfo.rs")
     ;; ruby (uses gnu)
     (gnu "plain-exception.rb:7:in `fun': unhandled exception"
      1 nil 7 "plain-exception.rb")
@@ -538,9 +547,9 @@ compile-test-error-regexps
                    1 15 5 "alpha.c")))
         (compile--test-error-line test))
 
-      (should (eq compilation-num-errors-found 107))
-      (should (eq compilation-num-warnings-found 36))
-      (should (eq compilation-num-infos-found 35)))))
+      (should (eq compilation-num-errors-found 108))
+      (should (eq compilation-num-warnings-found 37))
+      (should (eq compilation-num-infos-found 36)))))
 
 (ert-deftest compile-test-grep-regexps ()
   "Test the `grep-regexp-alist' regexps.
-- 
2.49.0