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

From: Vincenzo Pupillo <[email-masked]>
Date: Mon, 28 Apr 2025 22:22:16 +0200

Ciao,
Would the attached patch be good?

Vincenzo

p.s. the tests come from Rust docs.

In data giovedì 6 giugno 2024 09:34:42 Ora legale dell’Europa centrale, Stefan 
Kangas ha scritto:
> Mattias Engdegård <[email-masked]> writes:
> > 3 juni 2024 kl. 18.33 skrev Eli Zaretskii <[email-masked]>:
> >> Fine by me (I don't use Rust), but is the rule really broken?  What
> >> happens if you move it to the end?
> > 
> > It is indeed broken as written because it would match anything
> > starting with 'warning:' to something that looks like an arrow further
> > down the log which could be an unrelated message a megabyte away.
> > 
> > I could try to slap together a guess at what a better one would be but
> > then again, I wouldn't use it myself (rarely use Rust and when I do
> > it's one of those external packages which have their own patterns and
> > more importantly active maintainers). Furthermore I don't have the
> > time to go poking around in the rustc (or cargo?) source code to see
> > what the message-emitting parts look like, which is very useful when
> > adding patterns.
> > 
> > Even with the obvious fixes, the pattern would still be incomplete and
> > not even match parts of the examples given. I'm happy to work with
> > Rust users or package maintainers to work out details but I don't want
> > to do a rush job now, nor delay Emacs 30.
> 
> Randy, would you be interested in working with Mattias to create a good
> `compilation-mode` regexp for Rust?

>From 3a1bcf8e5cfa4cd2640ccece85d68df3f880cc46 Mon Sep 17 00:00:00 2001
From: Vincenzo Pupillo <[email-masked]>
Date: Sat, 26 Apr 2025 23:42:36 +0200
Subject: [PATCH] Support Rust compiler error and warning messages in compile
 mode.

* etc/compilation.txt: Add examples of Rust compiler error and warning
messages.
* lisp/progmodes/compile.el
(compilation-error-regexp-alist-alist): Add Rust error and warning
regexps.
* test/lisp/progmodes/compile-tests.el
(compile-tests--test-regexps-data): Add test case.
---
 etc/compilation.txt                  | 9 +++++++++
 lisp/progmodes/compile.el            | 7 +++++++
 test/lisp/progmodes/compile-tests.el | 6 ++++++
 3 files changed, 22 insertions(+)

diff --git a/etc/compilation.txt b/etc/compilation.txt
index 67c7000ae09..c8a66bd074f 100644
--- a/etc/compilation.txt
+++ b/etc/compilation.txt
@@ -487,6 +487,15 @@ 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 rust-warning
+
+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
+
 * Ruby
 
 symbol: ruby
diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el
index 1ca58b3ac7d..7a1b5d4fdd1 100644
--- a/lisp/progmodes/compile.el
+++ b/lisp/progmodes/compile.el
@@ -565,6 +565,13 @@ compilation-error-regexp-alist-alist
      "\\(?:Parse\\|Fatal\\) error: \\(.*\\) in \\(.*\\) on line \\([0-9]+\\)"
      2 3 nil nil)
 
+    (rustc-error
+     "^error[^:]*:[^\n]*\n\s+-->\s\\([^\n]+\\):\\([0-9]+\\):\\([0-9]+\\)"
+     1 2 3)
+    (rustc-warning
+     "^warning[^:]*:[^\n]*\n\s+-->\s\\([^\n]+\\):\\([0-9]+\\):\\([0-9]+\\)"
+     1 2 3 1)
+
     (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..c98f8404e7b 100644
--- a/test/lisp/progmodes/compile-tests.el
+++ b/test/lisp/progmodes/compile-tests.el
@@ -372,6 +372,12 @@ 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
+     "error[E0277]: `Foo` is not an iterator\n --> src/main.rs:4:16"
+     1 16 4 "src/main.rs")
+    (rust-warning "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")
     ;; ruby (uses gnu)
     (gnu "plain-exception.rb:7:in `fun': unhandled exception"
      1 nil 7 "plain-exception.rb")
-- 
2.49.0