summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSibi Prabakaran <sibi@psibi.in>2025-06-20 14:59:25 +0530
committerGitHub <noreply@github.com>2025-06-20 14:59:25 +0530
commit8cfcdd166b6c34b0eac3bc69b0141678a48db33d (patch)
tree92b66dcef473a9ef7fd8d14b208f799d68a0a859
parent0d5d54a19e89f9012f3fa84174f562ab18cebb96 (diff)
parentf2c0802b3325ca07681e8b5745690127a68cc037 (diff)
downloadrust-mode-8cfcdd166b6c34b0eac3bc69b0141678a48db33d.tar.gz
Merge pull request #571 from apiraino/rustfmt-2018-edition-default
Ensure rustfmt is invoked without edition parameter
-rw-r--r--.github/workflows/test.yml3
-rw-r--r--Changelog.md4
-rw-r--r--rust-cargo-tests.el17
-rw-r--r--rust-rustfmt.el6
-rw-r--r--test-project/src/rustfmt-default.rs5
5 files changed, 31 insertions, 4 deletions
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index fadf996..faabc18 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 bea46db..b603491 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 fe78ac7..1b072ee 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 6fb0e87..adaeb0d 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 0000000..3138c9c
--- /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};