Problem with rustfmt on stable


#1

I am having problems running the command ‘rustfmt’ on stable.

If I run the old rustfmt (installed using cargo), it prints out an error message saying that it is deprecated.

If I run the version installed with ‘rustup’ it only works with the nightly compiler:

error: toolchain 'stable-x86_64-unknown-linux-gnu' does not have the binary `rustfmt`

I think there are some workarounds:

  • Use the cargo version and add a flag when executing ‘rustfmt’
  • Use the nightly version, but only through cargo and add a flag to cargo.

However, none of these work in emacs/spacemacs without some temporary fix that involves editing the editor configuration.

I’l really like to just have the ‘rustfmt’ command work without any extra flags. Is there some way to do this?


#2

I don’t use emacs, but maybe this library could be of help? https://github.com/rust-lang/rust-mode#formatting-with-rustfmt


#3

off top of my head without checking
rustup component add rustfmt-preview
or view list first with
rustup component list


#4

I think that rustfmt-preview only works in nightly – although it would be good if I was wrong.

Edit: Yes it works. Many thanks.


#5

Spacemacs normally supports rustfmt and will autoformat on save. The problem is that the libraries assume that an executable called ‘rustfmt’ exists, and with the stable toolchain it gives the error:

error: toolchain 'stable-x86_64-unknown-linux-gnu' does not have the binary `rustfmt`

I could edit the emacs libraries to make it work but I rather wouldn’t if there is another solution.


#6

rustfmt-preview is on all three channels, though stable only has rustfmt, not cargo fmt. That’s coming in the next release.