错误:工具链'stable-x86_64-apple-darwin'没有二进制`rustfmt`

dvn*_*yen 24 rust rustup

我跑来rustup update更新我的工具链并看到两个警告:

warning: tool `rustfmt` is already installed, remove it from `/Users/<username>/.cargo/bin`, then run `rustup update` to have rustup manage this tool.
warning: tool `cargo-fmt` is already installed, remove it from `/Users/<username>/.cargo/bin`, then run `rustup update` to have rustup manage this tool.
Run Code Online (Sandbox Code Playgroud)

我按照警告信息中的说明操作,然后rustfmt再次尝试运行.我收到了错误

error: toolchain 'stable-x86_64-apple-darwin' does not have the binary rustfmt`
Run Code Online (Sandbox Code Playgroud)

出了什么问题,我该如何解决?

E_n*_*ate 22

通过您执行的步骤,Rustup已配置为管理rustfmt二进制文件.这意味着它们可以与您的工具链一起自动更新,而不是依赖cargo install.这里缺少的是rustfmtRustup试图执行的实际组件.

为了让Rustup管理rustfmt,请参阅以下步骤:

  1. 将Rustup更新到最新版本后,您可能会收到该消息warning: tool rustfmt is already installed.按照建议从Cargo的二进制文件夹中删除二进制文件.cargo uninstall rustfmt(或者,rustfmt-nightly如果你安装了)效果很好.
  2. 运行rustup update以让它用自己的托管rustfmt和填充已删除的二进制文件cargo-fmt.
  3. 完成后,您仍然需要为将rustfmt-preview要使用的每个工具链安装组件.并非所有工具链都会暂时提供此组件,但最新的stable工具链肯定会拥有它.因此,请确保已安装此工具链,然后:
$ rustup component add rustfmt-preview
Run Code Online (Sandbox Code Playgroud)

完成后,rustfmt使用该工具链调用应该有效:

$ rustup run stable rustfmt --version

rustfmt 0.99.4-stable (1c40881 2018-08-27)
Run Code Online (Sandbox Code Playgroud)

rustfmtRustup管理的当前使用状态可能有点令人困惑.关于这个主题有一些相关的问题和PR(#1305#1310),并且它们之后提供了使这项工作正常运行的必要线索.


小智 18

错误告诉您rustfmt-preview实际上没有安装*-apple-darwin.

你需要做的是:

rustup component add rustfmt-preview --toolchain stable-x86_64-apple-darwin

在你好好去之后:)

  • 谢谢!这就是我对"默认"新手安装所需要的. (4认同)