-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Format-on-save no longer functioning for rustfmt. No configuration change was made #4897
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
Comments
I had similar issue due to passing from edition 2021 to 2024. You should probably change the Probably we should also detect the first |
Unacceptable. While less drastic, I still consider that a "Downgrade to Windows XP. Our product doesn't support Windows 11" answer. I'll probably experiment with just turning off ALE's format-on-save in my |
For now you can try something like this : # replace with the correct version depending of your project
echo 'edition = "2021"' > ~/.config/rustfmt.toml There's maybe a rustfmt option to point on the correct Cargo.toml, but I don't know about it. |
Again, that would not achieve the desired result. I don't want it messing up or yelling at me that I'm trying to force formatting based on an edition that doesn't match the project or what have you. Running |
It is the same tool, ll /usr/bin/rustfmt
# lrwxrwxrwx 1 root root 15 Mar 6 00:53 /usr/bin/rustfmt -> /usr/bin/rustup
ll /usr/bin/cargo
# lrwxrwxrwx 1 root root 15 Mar 6 00:53 /usr/bin/cargo -> /usr/bin/rustup
cargo fmt --version
# rustfmt 1.8.0-nightly (e2014e876e 2025-04-01)
rustfmt --version
# rustfmt 1.8.0-nightly (e2014e876e 2025-04-01) The issue is about Cargo.toml detection. Maybe we should consider using |
No, Rust's toolchain just dispatches through (eg. If your default toolchain is the stable channel but you've got a matching nightly-channel build of the toolchain installed too, you can go It's a toolchain-specific analogue to Debian's Alternatives system. (On a Debian-lineage distro such as Ubuntu, The real binaries will be elsewhere. (eg. when using rustup to install the stable-channel toolchain into your user profile as is the default configuration, you'll see separate
As an alternative fixer and one I'd personally be fine with using, sure, but not as a silent change to how the As It's a "Run I believe the "correct" solution for formatting a single file is to run The relevant parts of a non-workspace (i.e. single-package) project look like this: {
"packages": [{
// ...
"targets": [{
// ...
"src_path": "/home/ssokolow/src/hello/src/main.rs",
// ...
}],
// ...
"manifest_path": "/home/ssokolow/src/hello/Cargo.toml",
// ...
}],
// ...
"workspace_root": "/home/ssokolow/src/hello",
// ...
} With a workspace project, Their README just says this without clarifying whether "the project" means the package root or the workspace root in a workspace-based configuration:
(If you're OK with having looked at MIT-licensed code, given your 2BSD license, you could look at how https://github.com/rust-lang/rust.vim does it. That's what the rustfmt repo points people at for Vim integration... I just don't want all that overlap with my existing cross-language plugins for everything other than format-on-save.) |
Uh oh!
There was an error while loading. Please reload this page.
Information
VIM version
VIM - Vi IMproved 9.0 (2022 Jun 28, compiled May 10 2022 08:40:37)
Included patches: 1-749
Operating System:
NOTE: LSP support is disabled because I'm also running coc.nvim for languages where a suitably performant, suitably licensed LSP is available... which does include Rust, though adding that predates format-on-save breaking by a long time and I have
coc.nvim
's format-on-save support disabled because it's much more laissez-faire thancargo fmt
and I can't find docs for changing that.What went wrong
Somewhere along the way,
rustfmt
-on-save stopped working and:ALEFix
also has no effect.I'm guessing it happened as a result of a
:PlugUpdate
bumping ALE somewhere along the way (I use vim-plug) though I suppose it could also have come as a result of arustup update
.Running
cargo fmt
manually still has the expected effect, meaning that my test input is testing what I want it to test, given the context of myrustfmt.toml
.I couldn't find any issues that appeared to be describing the same problem and the
ALEInfo
command history says thatrustfmt
is getting run and returning an exit code of 1, which, if this list is still valid, basically means "anything but the code being too malformed to format".Reproducing the bug
>>
(indent) a statement that's currently properly indented. (eg.println!(...);
):ALEFix
:w
!cargo fmt
:ALEInfo
Expand
The text was updated successfully, but these errors were encountered: