Problem with rustfmt on stable

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?

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

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

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

Edit: Yes it works. Many thanks.

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.

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

This worked for me:

$ rustup component remove rustfmt-preview --toolchain=stable-x86_64-pc-windows-msvc
info: removing component 'rustfmt-preview'
warning: during uninstall component rustfmt-preview-x86_64-pc-windows-msvc was not found

$ rustup component add rustfmt-preview --toolchain=stable-x86_64-pc-windows-msvc
info: downloading component 'rustfmt-preview'
info: installing component 'rustfmt-preview'

$ rustup run stable rustfmt --version
rustfmt 0.99.1-stable (da17b689 2018-08-04)