rust-analyzer: can't load standard library from sysroot

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

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 15 (1 by maintainers)

Most upvoted comments

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

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

sudo apt install rust-src

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

Hi, The new version 0.3.2308 introduce regression in regard of find std sources: I use nix to provide rust environment, and it worked before this version. Here is my nix configuration:

default.nix

 let
   npins = import ./npins;
   system = builtins.currentSystem;
   pkgs = import npins.nixpkgs { inherit system; config = {}; overlays = []; };
   build = pkgs.callPackage ./build.nix {};
   HOME = builtins.getEnv "HOME";
   PROJECT_ROOT = builtins.toString ./.;
 in
 {
   build = build;
   shell = pkgs.mkShell {
     inputsFrom = [ build ];
     packages = [
      
        pkgs.git
      
        pkgs.rustfmt
      
        pkgs.nixpkgs-fmt
      
     ];
     
     RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}";
     
   };
 }

build.nix

{ lib, rustPlatform, nix-gitignore }:

let
  cargo = fromTOML (builtins.readFile ./Cargo.toml);
in

rustPlatform.buildRustPackage {
  pname = cargo.package.name;
  version = cargo.package.version;

  src = nix-gitignore.gitignoreSource [".git" ".gitignore" "*.nix"] ./.;

  cargoLock = {
    lockFile = ./Cargo.lock;
  };
}

shell.nix

(import ./.).shell

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!!!

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.