错误:未为工具链“stable-x86_64-unknown-linux-gnu”安装“rust-analyzer”

Zor*_*b29 7 rust rust-analyzer

我已按照https://rust-analyzer.github.io/manual.html#installation上的说明安装了 rust-analyzer :

\n
\xe2\x9c\x94 ~> rustup component add rust-src\ninfo: component \'rust-src\' is up to date\n
Run Code Online (Sandbox Code Playgroud)\n

但是,我得到:

\n
\xe2\x9c\x94 ~> rust-analyzer -v\nerror: \'rust-analyzer\' is not installed for the toolchain \'stable-x86_64-unknown-linux-gnu\'\n
Run Code Online (Sandbox Code Playgroud)\n

我也尝试安装这个特定的工具链:

\n
\xe2\x9c\x98-1 ~> rustup component add rust-src --toolchain stable-x86_64-unknown-linux-gnu\ninfo: component \'rust-src\' is up to date\n
Run Code Online (Sandbox Code Playgroud)\n

但我仍然遇到同样的错误。

\n

我在互联网上查找了错误,并在 https://github.com/rust-lang/rust-analyzer/issues/14776找到了示例讨论。但是,检查可执行位置会返回

\n
\xe2\x9c\x94 ~> which rust-analyzer\n/home/jrmet/.cargo/bin/rust-analyzer\n
Run Code Online (Sandbox Code Playgroud)\n

这完全在我的路径之内。另外,我可以这样做:

\n
\xe2\x9c\x94 ~> /home/jrmet/.cargo/bin/rust-analyzer\nerror: \'rust-analyzer\' is not installed for the toolchain \'stable-x86_64-unknown-linux-gnu\'\n
Run Code Online (Sandbox Code Playgroud)\n

我还一直在与其他目标合作:

\n
\xe2\x9c\x94 ~> rustup target list | grep installed\nthumbv7em-none-eabihf (installed)\nthumbv8m.main-none-eabihf (installed)\nx86_64-unknown-linux-gnu (installed)\n
Run Code Online (Sandbox Code Playgroud)\n

但我不认为这应该发挥作用?

\n

知道为什么我会遇到这个问题以及如何解决它吗?我有一种感觉,我可能在某种程度上弄乱了目标和工具链,但不知道如何/在哪里/如何修复它。

\n

我使用的是 Ubuntu 22.04。

\n

Zor*_*b29 9

我误解了如何安装 rust-analyzer 的说明:我安装的只是依赖项,而不是 rust-analyzer 本身。

\n

要解决此问题,请按照说明页面操作:

\n
\xe2\x9c\x94 ~> rustup component add rust-analyzer\ninfo: downloading component 'rust-analyzer'\ninfo: installing component 'rust-analyzer'\n\xe2\x9c\x94 ~> rust-analyzer --version\nrust-analyzer 1.73.0 (cc66ad4 2023-10-03)\n
Run Code Online (Sandbox Code Playgroud)\n

我的困惑源于这样一个事实:有一个可执行的 rust-analyzer 被检测到which并自动启动,即使 rust-analyzer 实际上并未安装......

\n

  • 检测到的可执行文件可能是 rustup 提供的包装器,它使用正确的环境变量和标志启动真正的可执行文件。 (2认同)