From 3948faec12f72b0b11fd573e3bcfe323de5b6d80 Mon Sep 17 00:00:00 2001 From: Lucas Soriano del Pino Date: Sun, 11 Feb 2024 11:54:31 +1100 Subject: Match panics in compilation-mode If we encounter a panic when executing Rust code in `compilation-mode`, we now correctly highlight the location where the panic occurred. For example: ``` thread 'main' panicked at src/main.rs:2:5: explicit panic note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ``` Here, `src/main.rs:2:5` is highlighted. The developer is then able to execute `compile-goto-error` to jump to the correct spot in the code. Co-authored-by: Brent Westbrook Co-authored-by: zlef --- rust-compile.el | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'rust-compile.el') diff --git a/rust-compile.el b/rust-compile.el index 1bb3103..04ac6b6 100644 --- a/rust-compile.el +++ b/rust-compile.el @@ -34,6 +34,12 @@ See `compilation-error-regexp-alist' for help on their format.") "Specifications for matching code references in rustc invocations. See `compilation-error-regexp-alist' for help on their format.") +(defvar rustc-panics-compilation-regexps + (let ((re (concat "thread '[^']+' panicked at " rustc-compilation-location))) + (cons re '(2 3 4 nil 1))) + "Specifications for matching panics in rustc invocations. +See `compilation-error-regexp-alist' for help on their format.") + ;; Match test run failures and panics during compilation as ;; compilation warnings (defvar cargo-compilation-regexps @@ -75,6 +81,9 @@ the compilation window until the top of the error is visible." (add-to-list 'compilation-error-regexp-alist 'rustc-colon) (add-to-list 'compilation-error-regexp-alist-alist (cons 'cargo cargo-compilation-regexps)) + (add-to-list 'compilation-error-regexp-alist-alist + (cons 'rustc-panics rustc-panics-compilation-regexps)) + (add-to-list 'compilation-error-regexp-alist 'rustc-panics) (add-to-list 'compilation-error-regexp-alist 'cargo) (add-hook 'next-error-hook #'rustc-scroll-down-after-next-error))) -- cgit v1.2.3