From a20758e9a386bebe345ce1e6d497420de5be088c Mon Sep 17 00:00:00 2001 From: Danny Willems Date: Sun, 31 May 2026 07:51:11 +0200 Subject: [PATCH 1/3] fix: replace obsolete when-let with let and when The `when-let` macro is obsolete as of Emacs 31.1, producing byte-compile warnings. Since the declared minimum is Emacs 25.1, `when-let*` cannot be used as a replacement because it was only introduced in Emacs 26.1. Rewrite the three usages in rust-prog-mode.el using `let` plus `when`, which is available on all supported Emacs versions and preserves the short-circuiting evaluation order of the original code. --- rust-prog-mode.el | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/rust-prog-mode.el b/rust-prog-mode.el index ea6ef82..dfa8745 100644 --- a/rust-prog-mode.el +++ b/rust-prog-mode.el @@ -922,11 +922,12 @@ and end." (defun rust-string-interpolation-matcher (limit) "Match next Rust interpolation marker before LIMIT and set match data if found. Returns nil if not within a Rust string." - (when-let (((rust-in-str)) - (match (rust-next-string-interpolation limit))) - (set-match-data match) - (goto-char (cadr match)) - match)) + (when (rust-in-str) + (let ((match (rust-next-string-interpolation limit))) + (when match + (set-match-data match) + (goto-char (cadr match)) + match)))) (defun rust-syntax-class-before-point () (when (> (point) 1) @@ -950,18 +951,19 @@ Returns nil if not within a Rust string." ;; we're looking back at this, we want to end up just after "Fn". ((member (char-before) '(?\] ?\) )) (let ((is-paren (rust-looking-back-str ")"))) - (when-let ((dest (save-excursion + (let ((dest (save-excursion + (backward-sexp) + (rust-rewind-irrelevant) + (or + (when (rust-looking-back-str "->") + (backward-char 2) + (rust-rewind-irrelevant) + (when (rust-looking-back-str ")") (backward-sexp) - (rust-rewind-irrelevant) - (or - (when (rust-looking-back-str "->") - (backward-char 2) - (rust-rewind-irrelevant) - (when (rust-looking-back-str ")") - (backward-sexp) - (point))) - (and is-paren (point)))))) - (goto-char dest)))))) + (point))) + (and is-paren (point)))))) + (when dest + (goto-char dest))))))) (defun rust-rewind-to-decl-name () "Return the point at the beginning of the name in a declaration. @@ -1548,8 +1550,9 @@ whichever comes first." (defun rust-syntax-propertize (start end) "A `syntax-propertize-function' to apply properties from START to END." (goto-char start) - (when-let ((str-start (rust-in-str-or-cmnt))) - (rust--syntax-propertize-raw-string str-start end)) + (let ((str-start (rust-in-str-or-cmnt))) + (when str-start + (rust--syntax-propertize-raw-string str-start end))) (funcall (syntax-propertize-rules ;; Character literals. From 8480ca59e1c255d454321855e267f564427685eb Mon Sep 17 00:00:00 2001 From: Danny Willems Date: Sun, 31 May 2026 07:52:17 +0200 Subject: [PATCH 2/3] ci: add byte-compile workflow with warnings as errors Add a dedicated workflow that byte-compiles the package with `byte-compile-error-on-warn` enabled, so that any new byte-compile warning fails CI. It runs on the declared minimum (Emacs 25.1), the current stable (30.1), and the development snapshot. The treesitter integration file is only compiled on Emacs 29.1 and later, matching the runtime guard in rust-mode-treesitter.el. GitHub Actions are kept up to date by the existing dependabot configuration. --- .github/workflows/byte-compile.yml | 44 ++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 .github/workflows/byte-compile.yml diff --git a/.github/workflows/byte-compile.yml b/.github/workflows/byte-compile.yml new file mode 100644 index 0000000..a2cf96c --- /dev/null +++ b/.github/workflows/byte-compile.yml @@ -0,0 +1,44 @@ +name: Byte-compile + +on: + push: + branches: + - master + pull_request: + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + byte-compile: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + emacs-version: + - "25.1" + - "30.1" + - snapshot + steps: + - uses: actions/checkout@v5 + - uses: purcell/setup-emacs@master + with: + version: ${{ matrix.emacs-version }} + - name: Byte-compile with warnings as errors + run: | + emacs -Q --batch -L . \ + --eval '(setq byte-compile-error-on-warn t)' \ + --eval '(let ((files (list "rust-cargo.el" "rust-common.el" + "rust-compile.el" "rust-mode.el" + "rust-playpen.el" "rust-prog-mode.el" + "rust-rustfmt.el" "rust-utils.el")) + (ok t)) + (when (version<= "29.1" emacs-version) + (setq files + (append files (list "rust-mode-treesitter.el")))) + (dolist (f files) + (unless (byte-compile-file f) + (setq ok nil))) + (unless ok (kill-emacs 1)))' From 325c6ff98ef9084f1299e097388c36e12cd5af02 Mon Sep 17 00:00:00 2001 From: Danny Willems Date: Sun, 31 May 2026 07:56:14 +0200 Subject: [PATCH 3/3] fix: declare true minimum Emacs version 26.1 rust-cargo.el calls `file-local-name', which was introduced in Emacs 26.1, so the package cannot run on the previously declared minimum of Emacs 25.1. Update the Package-Requires header to 26.1, matching the oldest version actually exercised by the existing test matrix. Also require `subr-x' in rust-cargo.el for `string-trim'. It was only pulled in at compile time via rust-mode.el, leaving the symbol undefined at runtime and unknown to the byte-compiler on Emacs versions before 28, where subr-x is not preloaded. Set the byte-compile workflow minimum to 26.1 accordingly. --- .github/workflows/byte-compile.yml | 2 +- rust-cargo.el | 1 + rust-mode.el | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/byte-compile.yml b/.github/workflows/byte-compile.yml index a2cf96c..953f289 100644 --- a/.github/workflows/byte-compile.yml +++ b/.github/workflows/byte-compile.yml @@ -18,7 +18,7 @@ jobs: fail-fast: false matrix: emacs-version: - - "25.1" + - "26.1" - "30.1" - snapshot steps: diff --git a/rust-cargo.el b/rust-cargo.el index bb5d2ac..fd1d1ab 100644 --- a/rust-cargo.el +++ b/rust-cargo.el @@ -6,6 +6,7 @@ ;;; Code: (require 'json) +(require 'subr-x) ;;; Options diff --git a/rust-mode.el b/rust-mode.el index 52c5242..b116851 100644 --- a/rust-mode.el +++ b/rust-mode.el @@ -4,7 +4,7 @@ ;; Author: Mozilla ;; Url: https://github.com/rust-lang/rust-mode ;; Keywords: languages -;; Package-Requires: ((emacs "25.1")) +;; Package-Requires: ((emacs "26.1")) ;; This file is distributed under the terms of both the MIT license and the ;; Apache License (version 2.0).