Skip to content

Commit 6873c6f

Browse files
committed
Ensure rustfmt is invoked without edition parameter
1 parent 0d5d54a commit 6873c6f

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

rust-cargo-tests.el

Lines changed: 15 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-edition-2018-file-buffer (expr)
25+
`(let* ((test-dir (expand-file-name "test-project/" default-directory))
26+
(main-file (expand-file-name "src/edition-2018.rs" test-dir)))
27+
(save-current-buffer
28+
(find-file main-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,11 @@
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-rustfmt-2018 ()
82+
(skip-unless (executable-find "rustfmt"))
83+
(rust-test--with-edition-2018-file-buffer
84+
(let ((old-content (buffer-string))
85+
(ret (rust-format-buffer)))
86+
(should (string= ret "Formatted buffer with rustfmt."))
87+
(should (string= old-content (buffer-string))))))

rust-rustfmt.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
:type 'string
3434
:group 'rust-mode)
3535

36-
(defcustom rust-rustfmt-switches '("--edition" "2024")
36+
(defcustom rust-rustfmt-switches nil
3737
"Arguments to pass when invoking the `rustfmt' executable."
3838
:type '(repeat string)
3939
:group 'rust-mode)

test-project/src/edition-2018.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// this test ensures that by default rustfmt is invoked without parameters
2+
// and formats for --edition=2018
3+
// (with --edition=2024 this import would be reordered)
4+
use anyhow::{anyhow, Context};

0 commit comments

Comments
 (0)