安装最新的 Rust Nightly 版本时,提示缺少 RLS 组件。

11

尝试编译:https://github.com/SergioBenitez/Rocket/tree/master/examples/hello

Cargo.toml

[dependencies]
rocket = "0.4.10"

抱怨说我需要Rust夜版

$ cargo build
...
  Error: Rocket (core) requires a more recent version of rustc.
  Installed version: 1.54.0 (2021-05-17)
  Minimum required:  1.54.0-nightly (2021-05-18)

我已经完成了本地目录覆盖

$ rustup override set nightly

我正在运行夜间版本 2021-05-17,但我需要的是 2021-05-18 版本。

$ rustup show
...
active toolchain
----------------

nightly-x86_64-unknown-linux-gnu (directory override for '/<redacted>')
rustc 1.54.0-nightly (3e99439f4 2021-05-17)

我已经尝试了各种命令来获取一个更新的夜间版本。

$ rustup update
$ rustup update nightly
$ rustup toolchain install nightly-2021-05-18

当我执行 rustup update nightly 命令时,出现了一些奇怪的问题。

$ rustup update nightly 
info: syncing channel updates for 'nightly-x86_64-unknown-linux-gnu'
info: latest update on 2021-05-23, rust version 1.54.0-nightly (e4ca1662f 2021-05-22)
info: skipping nightly which is missing installed component 'rls'
info: syncing channel updates for 'nightly-2021-05-22-x86_64-unknown-linux-gnu'
info: latest update on 2021-05-22, rust version 1.54.0-nightly (5dc8789e3 2021-05-21)
info: skipping nightly which is missing installed component 'rls'
info: syncing channel updates for 'nightly-2021-05-21-x86_64-unknown-linux-gnu'
info: latest update on 2021-05-21, rust version 1.54.0-nightly (40d230204 2021-05-20)
info: skipping nightly which is missing installed component 'rls'
info: syncing channel updates for 'nightly-2021-05-20-x86_64-unknown-linux-gnu'
info: latest update on 2021-05-20, rust version 1.54.0-nightly (f94942d84 2021-05-19)
info: skipping nightly which is missing installed component 'rls'
info: syncing channel updates for 'nightly-2021-05-19-x86_64-unknown-linux-gnu'
info: latest update on 2021-05-19, rust version 1.54.0-nightly (4e3e6db01 2021-05-18)
info: skipping nightly which is missing installed component 'rls'
info: syncing channel updates for 'nightly-2021-05-18-x86_64-unknown-linux-gnu'

  nightly-x86_64-unknown-linux-gnu unchanged - rustc 1.54.0-nightly (3e99439f4 2021-05-17)

抱怨关于跳过 nightly,缺少安装组件 'rls',我不知道如何解决

希望能得到任何帮助

1个回答

9
如果您只想快速解决问题,请参阅下面问题的解决方案。您还可以查看Rustup手册,其中包含有关此类问题的信息。
您正在尝试安装 Rust 的 nightly 版本。在 nightly 版本中,Rust 的非必要组件(例如 Rust 语言服务器,或简称为 rls)的可用性不能保证 - 如果它们无法构建,则 nightly 将不包含它们。您可以在此处看到,rls 确实不是最近几个 Nightly 版本的一部分。上次一个包含 rls 的 nightly 版本是 2021-05-18,这是前一天的构建,因此是 2021-05-17(有点让人困惑,但这种情况似乎是被接受的行为)。
您的 rustup 安装似乎配置了包括 rls。因此,当您告诉 rustup 更新您的 nightly 工具链时,rustup 会选择包含rls的最新 nightly 版本。没有比您当前安装的 nightly-2021-05-17 更新的这样的 nightlies,因此 rustup 不会更新工具链。

问题的解决方案

  • 如果您不需要rls(它仅在IDE和类似工具的自动完成中需要),那么有多种解决方案可解决您的问题:
    • 您可以从您的夜版工具链中移除rls组件:rustup component remove --toolchain nightly rls
    • rustup手册还提供了更多解决方案:

      如果缺少一个[先前安装的组件],rustup将自动搜索包含所需组件的较旧版本。有几种方法可以更改此行为:

      • 使用--force标志强制安装最新版本,即使缺少某个组件。
      • 使用--profile标志来使用不包含缺少组件的不同配置文件。例如,--profile=minimal应该始终有效,因为需要存在最小集。有关详细信息,请参见配置文件章节。
      • 安装包含您需要的组件的特定日期。例如,rustup toolchain install nightly-2020-07-27。然后,您可以使用覆盖将其固定到该特定版本。
  • 如果您确实需要rls,那么可能有些棘手。您可能希望为项目使用覆盖,实际上是在构建代码和运行rls时使用不同的Rust构建。但是,这可能无法正常工作-rls可能需要构建项目依赖项以进行自动完成,并且Rocket将不允许使用旧的夜版。我没有真正的解决方案-您可能需要留在较旧版本的Rocket上,或者暂停使用rls,直到有新的Rust夜版再次提供rls

感谢您提供详细的答案。我通过直接从Github使用Rocket 0.5来解决了这个问题,这不需要使用Nightly版本。但是,如果将来遇到类似的问题,这些信息将非常有用。 - Chuck
执行命令 "rustup component remove --toolchain nightly rls" 时,我收到以下错误提示:"error: toolchain 'nightly-aarch64-apple-darwin' does not contain component 'rls' for target 'aarch64-apple-darwin'; did you mean 'rustc'?" - pfincent
https://rust-lang.github.io/rustup-components-history/ 现在不再显示 rls。 - Dereckson
@Dereckson 看起来 rust-lang.github.io/rustup-components-history 只显示最近7天的记录。rls 最后一次可用是在2022年2月22日,所以它已经不可见了。 - Elias Holzmann

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接