Rustup and rustfmt [solved]

I updated rust toolchain with rustup today and got:

$ rustup update
...
warning: tool `rustfmt` is already installed, remove it from `/home/user/.cargo/bin`, then run `rustup update` to have rustup manage this tool.
warning: tool `cargo-fmt` is already installed, remove it from `/home/user/.cargo/bin`, then run `rustup update` to have rustup manage this tool.

So rustup at now can install rustfmt, it would be great, and I removed all files and run rustup update,
after that:

$ cd ~/.cargo/bin/ && ls *fmt*
cargo-fmt  git-fmt  rustfmt

So indeed rustup installed rustfmt, but

$ file ~/.cargo/bin/rustfmt
/home/user/.cargo/bin/rustfmt: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.9, with debug_info, not stripped
$ ~/.cargo/bin/rustfmt --help
error: toolchain 'nightly-x86_64-unknown-linux-gnu' does not have the binary `rustfmt`

So what is going on, rustfmt exists and not exists at the same time?

3 Likes

I've had similar problems. I'm using a mac and I have Windows and Ubuntu virtual machines. On Ubuntu everything just works. On my mac and windows it did not. I'm not sure if this has been tested on all platforms to make sure it works.

Also, I've had much better luck working with stable because nightly has been breaking a lot of little things here and there during the impl period, especially clippy.

You have to run

$ rustup component add --toolchain nightly rustfmt-preview

first to install rustfmt. What you see is a binary from rustup which runs the rustfmt of the current toolchain, but you dont have rustfmt installed for the current toolchain.

You will have to call rustfmt +nightly or cargo +nightly fmt to run rustfmt if you have nightly as default toolchain.

2 Likes

@bjorn3

Any idea why your answer become broken now?

$ rustup component add --toolchain nightly rustfmt-preview
error: toolchain 'nightly-x86_64-unknown-linux-gnu' does not contain component 'rustfmt-preview' for target 'x86_64-unknown-linux-gnu'

but it works for beta. But many tools at now expect that rustup run nightly rustfmt works,
so almost all tools become broken after update via rustup update.

Currently if rustfmt-nightly or rls fail to build, it won't fail the entire build and prevent the release of another nightly, which means that sometimes either or both of those components won't be available in nightly. Recently @nrc landed a rustup PR to address this - rustup update will detect this case and warn about it, unless you pass --force to bypass it.

https://github.com/rust-lang-nursery/rustup.rs/pull/1337

1 Like

Thanks @FaultyRAM

Currently if rustfmt-nightly or rls fail to build, it won’t fail the entire build and prevent the release of another > nightly, which means that sometimes either or both of those components won’t be available in nightly.

Current nightly build current rustfmt-nightly master, so rustfmt should come back as part of next nightly release?