rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.24k stars 1.6k forks source link

can't load standard library from sysroot #17113

Closed Avrimuskom closed 5 months ago

Avrimuskom commented 6 months ago

Windows 10 x64 Rust 1.77.2 MS VS Code 1.88.1 After install rust analyzer view error Безымянный

Avrimuskom commented 6 months ago

can't load standard library from sysroot

C:\Program Files\Rust stable MSVC 1.77

(discovered via rustc --print sysroot)

try installing the Rust source the same way you installed rustc

Avrimuskom commented 6 months ago

Solved: Need open file setting.json in dir C:\Users\%User%AppData\Roaming\Code\User\settings.json My example C:\Users\AveN\AppData\Roaming\Code\User\settings.json and change "rust-analyzer.cargo.sysroot": null on "rust-analyzer.cargo.sysroot": "C:/Users/%User%/.rustup/toolchains/stable-x86_64-pc-windows-msvc" on my example "rust-analyzer.cargo.sysroot": "C:/Users/AveN/.rustup/toolchains/stable-x86_64-pc-windows-msvc" image

Veykril commented 6 months ago

That sounds like your rust installation is a bit weird, given we should auto discover the sysroot just fine usually

Avrimuskom commented 6 months ago

first I installed via RUSTUP-INIT.EXE (64-BIT) then https://static.rust-lang.org/dist/rust-1.77.2-x86_64-pc-windows-msvc.msi

devas-37 commented 5 months ago

Solved: Need open file setting.json in dir C:\Users%User%AppData\Roaming\Code\User\settings.json My example C:\Users\AveN\AppData\Roaming\Code\User\settings.json and change "rust-analyzer.cargo.sysroot": null on "rust-analyzer.cargo.sysroot": "C:/Users/%User%/.rustup/toolchains/stable-x86_64-pc-windows-msvc" on my example "rust-analyzer.cargo.sysroot": "C:/Users/AveN/.rustup/toolchains/stable-x86_64-pc-windows-msvc" image

It works for me. Thanks so much!!!

rrrrigel commented 2 months ago

Solved: Need open file setting.json in dir C:\Users%User%AppData\Roaming\Code\User\settings.json My example C:\Users\AveN\AppData\Roaming\Code\User\settings.json and change "rust-analyzer.cargo.sysroot": null on "rust-analyzer.cargo.sysroot": "C:/Users/%User%/.rustup/toolchains/stable-x86_64-pc-windows-msvc" on my example "rust-analyzer.cargo.sysroot": "C:/Users/AveN/.rustup/toolchains/stable-x86_64-pc-windows-msvc" image

Thanks!

rngadam commented 2 months ago

Same error on Ubuntu 22.04.4 LTS, fixed by installing rust-src package:

sudo apt install rust-src
lsignac commented 1 month ago

Same on arch linux. Fixed with pacman -S rust-src

daiyongxuan commented 1 month ago

Same on arch linux. Fixed with pacman -S rust-src

It works for me, Arch WSL2, thanks!

Crispy13 commented 1 week ago

rustup component add rust-src

worked for me.

I installed rust with curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh. I don't know why that happened.

Phascolarctos commented 4 days ago

Solution

  1. get rust-src target url from channel-rust-stable.toml
  2. download rust-src
  3. copy directory src to rustlib directory
  4. example below
    • rustc --print sysroot

    • from: D:\EnvDev\rust-src\lib\rustlib

    • to: D:\EnvDev\Rust\lib\rustlib