Skip to content

Ensure rustfmt is invoked without edition parameter #571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
17 changes: 17 additions & 0 deletions rust-cargo-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)))
6 changes: 4 additions & 2 deletions rust-rustfmt.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 5 additions & 0 deletions test-project/src/rustfmt-default.rs
Original file line number Diff line number Diff line change
@@ -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};