Rust-analyzer showing "{unknown}" for all std types, members

Our rust-toolchain.toml has specified the 1.80.0 toolchain for a long time now and everything has been working fine with rust-analyzer and VSCode. We get code completion, tooltip help, etc. Today, however, none of that was working for anything in std. Types defined by std (and wrapped by std example Option<T>) just show "{unknown}" for type info and no completion. I tried deleting target/ and rebuilding a couple times to no avail.

My first thought was to check that the rust-src or rust-std were installed for 1.80.0. They were. I even tried removing and re-adding them. I even tried https://github.com/rust-lang/rust-analyzer/issues/17759#issuecomment-2270679715:

cd $(rustc --print sysroot)/lib/rustlib/src/rust/library && __CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS=nightly cargo metadata

This worked fine for stable (1.85 as of this post) but for 1.80 said that Cargo.toml wasn't found.

I had used cache clean last week - though things seemed to work still after that - and accidentally installed rust via homebrew to compile a formula, so I uninstalled that and deleted both ~/.rustup and ~/.cargo, re-installed rust, installed my toolchains again and...

Same thing! No Cargo.toml found for 1.80, and rust-analyzer not showing info for std. It does for types, members in our workspace as well as third-party crates like tokio. I updated our rust-toolchian.toml file to the "stable" channel and rust-analyzer works just fine again.

What happened, or better, how do I fix it? I mean, we could consider upgrading our baseline channel - 1.80 is pretty old, but we're trying to target as low as we can go and that's what we can do for now - but how my machine even get in this state I wonder? I ran rustup update right after 1.85 came out but it's been a (Short) while and everything was working. It's almost as if my rust-src or something got obliterated, but after deleting - full rm -rf ~/.rustup (and .cargo) - rust and re-installing the toolchains and components, how is it still not working?

1 Like

At some point std was reorganized into a workspace and RA might have had trouble with that. Does your problem go away if you remove the rust-src workspace Cargo.toml?

The command above said no Cargo.toml was found already. Was there some other manifest I should try removing?

The weirdest part of this was that nothing should've changed on my machine, apart from if cargo cache deleting any files that put something in a partial state, but why didn't removing ~/.rustup and ~/.cargo and reinstalling everything not fix it? I very much doubt they "patched" 1.80.0's rust-src to remove files that were there.

The rust-analyzer VSCode extension just got updated and now shows this, which probably explains why it wasn't working the night before:

So we'll either need to update our rust-toolchain.toml - but not necessarily our MSRV - or just drop the channel entirely. We're a workspace containing all lib crates, so is declaring a channel even worth it? Our test pipelines still test on our MSRV (1.80.0), stable, and nightly.

your toolchain version is not supported by the bundled rust-analyzer from the vscode extension, you can still use the rust-analyzer component installed by the command rustup component add rust-analyzer. you just need to tell vscode to use it instead of the bundled one: put this setting in your settings.json (workspace scope setting or user scope setting, which ever you prefer)

// .vscode/settings.json
{
	//...
	"rust-analyzer.server.path": "${userHome}/.cargo/bin/rust-analyzer",
	//...
}

2 Likes