rust-analyzer icon indicating copy to clipboard operation
rust-analyzer copied to clipboard

No definition for String::new

Open Iolop opened this issue 10 months ago • 4 comments

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.

Image

But it doesn't work on String::new.

Image

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()

Image

Image

what i've done : restart vscode, re-install RA/vscode, switch to Pre-Release RA

Iolop avatar Jun 11 '25 18:06 Iolop

You probably have a corrupted sysroot. Try rustup component remove rust-src then rustup component add rust-src.

ChayimFriedman2 avatar Jun 11 '25 20:06 ChayimFriedman2

You probably have a corrupted sysroot. Try rustup component remove rust-src then rustup 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?

Iolop avatar Jun 12 '25 01:06 Iolop

Does the file have fn new()?

ChayimFriedman2 avatar Jun 12 '25 02:06 ChayimFriedman2

Does the file have fn new()?

sure.

Image

Seems RA can't locate String but it could find the io.

Iolop avatar Jun 12 '25 02:06 Iolop

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

DeadPoetSpoon avatar Jun 27 '25 03:06 DeadPoetSpoon