branch: elpa/rust-mode
commit f2c0802b3325ca07681e8b5745690127a68cc037
Author: apiraino <apira...@users.noreply.github.com>
Commit: apiraino <apira...@users.noreply.github.com>

    Ensure rustfmt is invoked without edition parameter
---
 .github/workflows/test.yml          |  3 +++
 Changelog.md                        |  4 ++--
 rust-cargo-tests.el                 | 17 +++++++++++++++++
 rust-rustfmt.el                     |  6 ++++--
 test-project/src/rustfmt-default.rs |  5 +++++
 5 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index fadf996609..faabc1813d 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -45,6 +45,9 @@ jobs:
       - uses: jcs090218/setup-emacs@master
         with:
           version: ${{ matrix.emacs-version }}
+      - uses: dtolnay/rust-toolchain@stable
+        with:
+          components: rustfmt
       - uses: emacs-eask/setup-eask@master
         with:
           version: "snapshot"
diff --git a/Changelog.md b/Changelog.md
index bea46dbd30..b603491caf 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -1,7 +1,7 @@
 # Unreleased
 
-- Update rustfmt's defaults to use 2024 edition 
([#566](https://github.com/rust-lang/rust-mode/issues/509)).
-- Update rustfmt's defaults to use 2021 edition 
([#554](https://github.com/rust-lang/rust-mode/issues/509)).
+- Ensure rustfmt is invoked without overriding parameters 
[#571](https://github.com/rust-lang/rust-mode/pull/571)
+- Fix native compilation warnings 
([#509](https://github.com/rust-lang/rust-mode/issues/509)).
 - Introduce `rust-format-mode` for `rust-format-buffer` 
([#556](https://github.com/rust-lang/rust-mode/pull/556)).
 
 # v1.0.6
diff --git a/rust-cargo-tests.el b/rust-cargo-tests.el
index fe78ac79ed..1b072ee579 100644
--- a/rust-cargo-tests.el
+++ b/rust-cargo-tests.el
@@ -21,6 +21,13 @@
        (find-file main-file)
        ,expr)))
 
+(defmacro rust-test--with-snippet-buffer (expr)
+  `(let* ((test-dir (expand-file-name "test-project/" default-directory))
+          (snippet-file (expand-file-name "src/rustfmt-default.rs" test-dir)))
+     (save-current-buffer
+       (find-file snippet-file)
+       ,expr)))
+
 (defun rust-test--find-string (string)
   "Find STRING in current buffer."
   (goto-char (point-min))
@@ -70,3 +77,13 @@
       (should (eq major-mode 'rust-format-mode))
       (should (rust-test--find-string "error:")))
     (kill-buffer "*rustfmt*")))
+
+(ert-deftest rust-test-respect-rustfmt-defaults ()
+  (skip-unless (executable-find "rustfmt"))
+  (rust-test--with-snippet-buffer
+   (let ((old-content (buffer-string))
+             (ret (rust-format-buffer)))
+         (should (string= old-content (buffer-string))))))
+
+(ert-deftest rust-test-ensure-rustfmt-switches-nil ()
+  (should (eq rust-rustfmt-switches nil)))
diff --git a/rust-rustfmt.el b/rust-rustfmt.el
index 6fb0e8796a..adaeb0d36c 100644
--- a/rust-rustfmt.el
+++ b/rust-rustfmt.el
@@ -33,8 +33,10 @@
   :type 'string
   :group 'rust-mode)
 
-(defcustom rust-rustfmt-switches '("--edition" "2024")
-  "Arguments to pass when invoking the `rustfmt' executable."
+(defcustom rust-rustfmt-switches nil
+  "Arguments to pass when invoking the `rustfmt' executable. This variable
+will override any user configuration (e.g. rustfmt.toml). Recommendation
+is to not modify this and rely on declarative configuration instead."
   :type '(repeat string)
   :group 'rust-mode)
 
diff --git a/test-project/src/rustfmt-default.rs 
b/test-project/src/rustfmt-default.rs
new file mode 100644
index 0000000000..3138c9c5de
--- /dev/null
+++ b/test-project/src/rustfmt-default.rs
@@ -0,0 +1,5 @@
+// this file ensures that by default rustfmt is invoked without parameters
+// and formats with its default (--edition=2015 as of today)
+
+// With --edition=2024 this import will be reordered
+use std::{i16, i8};

Reply via email to