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

错误:工具链';stable-x86_64-apple-darwin';没有二进制'rustfmt'`,rust,rustup,Rust,Rustup,我已经运行了rustup update来更新我的工具链,并看到了两个警告: 警告:工具'rustfmt'已安装,请将其从'/Users//.cargo/bin'中删除,然后运行'rustup update',让rustup管理此工具。 警告:工具“cargo fmt”已安装,请将其从“/Users/.cargo/bin”中删除,然后运行“Rustop update”让Rustop管理此工具。 我按照警告消息中的说明操作,然后再次尝试运行rustfmt。我弄错了 错误:工具链“stable-x8

我已经运行了
rustup update
来更新我的工具链,并看到了两个警告:

警告:工具'rustfmt'已安装,请将其从'/Users//.cargo/bin'中删除,然后运行'rustup update',让rustup管理此工具。
警告:工具“cargo fmt”已安装,请将其从“/Users/.cargo/bin”中删除,然后运行“Rustop update”让Rustop管理此工具。
我按照警告消息中的说明操作,然后再次尝试运行
rustfmt
。我弄错了

错误:工具链“stable-x86_64-apple-darwin”没有二进制文件rustfmt`

出现了什么问题以及如何修复?

在系统中安装
rustfmt
最标准、最可靠的方法是确保在Rustup工具链中安装
rustfmt
组件

rustup组件添加rustfmt
或针对特定的工具链:

rustup组件添加rustfmt——工具链nightly-2020-06-09
夜间工具链中的测试和构建可能会失败,这意味着这些工具链不太可能总是包含此组件。最新的
stable
beta
工具链通常会根据策略提供

要让Rustop管理rustfmt,请参阅以下步骤:

  • 将Rustup更新至最新版本后,您可能会收到消息
    警告:工具rustfmt已安装
    。按照建议,从Cargo的二进制文件夹中删除二进制文件
    cargo uninstall rustfmt
    (或者
    rustfmt nightly
    ,如果您安装了它)工作正常
  • 运行
    rustup update
    ,让它用自己管理的
    rustfmt
    cargo fmt
    填充删除的二进制文件
  • 确保您希望使用的工具链已安装(例如,
    stable
  • 也运行上面的命令,确保为该工具链安装了
    rustfmt
    组件
  • 完成此操作后,调用
    rustfmt
    将按预期工作:

    $ rustup run stable rustfmt --version
    rustfmt 1.4.12-stable (a828ffea 2020-03-11)
    
    或通过货物子命令:

    $cargo fmt--版本
    rustfmt 1.4.12-稳定(a828ffea 2020-03-11)
    


    在早期,由Rustup管理的
    rustfmt
    可能会有点混乱,因为Rustup并不总是有
    rustfmt
    ,并且仍然经常出现作为一个预览组件,必须以
    rustfmt preview
    的名称安装。关于该主题(和)有一些相关问题和PRs。

    错误告诉您没有
    rustfmt预览版
    未安装在实际的
    *-apple darwin

    您需要做的是:

    rustup组件添加rustfmt预览——工具链stable-x86_64-apple-darwin

    之后你就可以走了:)


    我认为你问题的第一部分与此无关——现在你只是在一次全新的安装中遇到了
    rustfmt
    问题。我也是..要使用该工具链添加
    rustfmt预览
    ,您还需要安装该工具链:
    rustup install nightly-2017-12-20-x86_64-apple-darwin
    谢谢!这就是“默认”新手安装所需的。
    $ rustup run stable rustfmt --version
    error: `toolchain 'stable-x86_64-pc-windows-msvc' does not have th`e binary `rustfmt.exe`
    
    $ 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)