Skip to content

Commit 8cfcdd1

Browse files
authored
Merge pull request #571 from apiraino/rustfmt-2018-edition-default
Ensure rustfmt is invoked without edition parameter
2 parents 0d5d54a + f2c0802 commit 8cfcdd1

File tree

5 files changed

+31
-4
lines changed

5 files changed

+31
-4
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ jobs:
4545
- uses: jcs090218/setup-emacs@master
4646
with:
4747
version: ${{ matrix.emacs-version }}
48+
- uses: dtolnay/rust-toolchain@stable
49+
with:
50+
components: rustfmt
4851
- uses: emacs-eask/setup-eask@master
4952
with:
5053
version: "snapshot"

Changelog.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Unreleased
22

3-
- Update rustfmt's defaults to use 2024 edition ([#566](https://github.com/rust-lang/rust-mode/issues/509)).
4-
- Update rustfmt's defaults to use 2021 edition ([#554](https://github.com/rust-lang/rust-mode/issues/509)).
3+
- Ensure rustfmt is invoked without overriding parameters [#571](https://github.com/rust-lang/rust-mode/pull/571)
4+
- Fix native compilation warnings ([#509](https://github.com/rust-lang/rust-mode/issues/509)).
55
- Introduce `rust-format-mode` for `rust-format-buffer` ([#556](https://github.com/rust-lang/rust-mode/pull/556)).
66

77
# v1.0.6

rust-cargo-tests.el

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@
2121
(find-file main-file)
2222
,expr)))
2323

24+
(defmacro rust-test--with-snippet-buffer (expr)
25+
`(let* ((test-dir (expand-file-name "test-project/" default-directory))
26+
(snippet-file (expand-file-name "src/rustfmt-default.rs" test-dir)))
27+
(save-current-buffer
28+
(find-file snippet-file)
29+
,expr)))
30+
2431
(defun rust-test--find-string (string)
2532
"Find STRING in current buffer."
2633
(goto-char (point-min))
@@ -70,3 +77,13 @@
7077
(should (eq major-mode 'rust-format-mode))
7178
(should (rust-test--find-string "error:")))
7279
(kill-buffer "*rustfmt*")))
80+
81+
(ert-deftest rust-test-respect-rustfmt-defaults ()
82+
(skip-unless (executable-find "rustfmt"))
83+
(rust-test--with-snippet-buffer
84+
(let ((old-content (buffer-string))
85+
(ret (rust-format-buffer)))
86+
(should (string= old-content (buffer-string))))))
87+
88+
(ert-deftest rust-test-ensure-rustfmt-switches-nil ()
89+
(should (eq rust-rustfmt-switches nil)))

rust-rustfmt.el

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@
3333
:type 'string
3434
:group 'rust-mode)
3535

36-
(defcustom rust-rustfmt-switches '("--edition" "2024")
37-
"Arguments to pass when invoking the `rustfmt' executable."
36+
(defcustom rust-rustfmt-switches nil
37+
"Arguments to pass when invoking the `rustfmt' executable. This variable
38+
will override any user configuration (e.g. rustfmt.toml). Recommendation
39+
is to not modify this and rely on declarative configuration instead."
3840
:type '(repeat string)
3941
:group 'rust-mode)
4042

test-project/src/rustfmt-default.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// this file ensures that by default rustfmt is invoked without parameters
2+
// and formats with its default (--edition=2015 as of today)
3+
4+
// With --edition=2024 this import will be reordered
5+
use std::{i16, i8};

0 commit comments

Comments
 (0)