No definition for String::new
rust-analyzer version: rust-analyzer version: 0.3.2490-standalone (9fc1b9076c 2025-06-08)
rustc version: rustc 1.87.0 (17067e9ac 2025-05-09)
editor or extension: VSCode Windows
Version: 1.100.3 (system setup) Commit: 258e40fedc6cb8edf399a463ce3a9d32e7e1f6f3 Date: 2025-06-02T13:30:54.273Z Electron: 34.5.1 ElectronBuildId: 11369351 Chromium: 132.0.6834.210 Node.js: 20.19.0 V8: 13.2.152.41-electron.0 OS: Windows_NT x64 10.0.26100
relevant settings: rust-src installed with $env:RUST_SRC_PATH C:\Users\Aria\\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library set
code snippet to reproduce:
use std::io;
fn main() {
let mut s1 = String::new();
io::stdin().read_line(&mut s1).expect("Failed to read line");
let v1: Vec<&str> = s1.trim().split_whitespace().collect();
println!("{}", v1[0]);
}
It's ok when mouse hang on std::io, hover works fine.
But it doesn't work on String::new.
I've checked the rust-analyzer LSP Trace. Here are the two sceenshots.
First for the io::stdin().read_line, second for the String::new()
what i've done : restart vscode, re-install RA/vscode, switch to Pre-Release RA
You probably have a corrupted sysroot. Try rustup component remove rust-src then rustup component add rust-src.
You probably have a corrupted sysroot. Try
rustup component remove rust-srcthenrustup component add rust-src.
I've tried,it didn't work.
I can find the C:\Users\Aria\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\alloc\src\string.rs where String is defined here.
corrupted sysroot? does it mean that some files are lost?
Does the file have fn new()?
Does the file have
fn new()?
sure.
Seems RA can't locate String but it could find the io.
When i try to use cargo and rustup offline on win10, i put .cargo dir in disk d and .rustup in disk c where the default dir, i get same issue.
But when i move .cargo to disk c where same as .rustup, problem solved
Don not Know why, but RA seem get normal now