rust-analyzer: Unable to find definition for `hashbrown`
I have describe this at stackoverflow: https://stackoverflow.com/questions/78754358/vscode-rust-analyzer-can-not-find-definition-of-hashbrown
here is my code:
main.rs
use std::collections::HashMap;
fn main() {
let _ = HashMap::<i32, i32>::new();
println!("Hello, world!")
}
Cargo.toml
[package]
name = "world_hello"
version = "0.1.0"
edition = "2021"
[dependencies]
rust-analyzer version is: v0.3.2037 (actually no version works)
rust version
Default host: x86_64-apple-darwin
rustup home: /Users/fishincat/.rustup
installed toolchains
--------------------
stable-x86_64-apple-darwin (default)
nightly-2023-12-28-x86_64-apple-darwin
nightly-2024-01-26-x86_64-apple-darwin
nightly-x86_64-apple-darwin
active toolchain
----------------
stable-x86_64-apple-darwin (default)
rustc 1.77.2 (25ef9e3d8 2024-04-09)
rustup component list --installed
cargo-x86_64-apple-darwin
clippy-x86_64-apple-darwin
rust-docs-x86_64-apple-darwin
rust-src
rust-std-x86_64-apple-darwin
rustc-x86_64-apple-darwin
rustfmt-x86_64-apple-darwin
my problem is:
When I jump to the definition of HashMap:
...
use hashbrown::hash_map as base;
...
pub struct HashMap<K, V, S = RandomState> {
base: base::HashMap<K, V, S>,
}
I can not go deep to the definition of base(hashbrown), it shows:
No Definition found for hashbrown
how to solve this?
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (7 by maintainers)
Remove
rust-analyzer.cargo.sysrootfrom your settings or runrustup +nightly component add rust-src.We don’t run that for explicit sysroot paths, only when set to
discoverYES
Sorry I was a bit eager with dropping that flag 😅 Any toolchain version 1.82 and beyond will work (so you could use the current beta now as well I think, or in a week)
See https://github.com/rust-lang/rust-analyzer/pull/17795. I think it will start working again in 1.82.
You will have to enable the
"rust-analyzer.cargo.sysrootQueryMetadata": true,config for this to work, but note that this means r-a will create and delete a lockfile in your toolchain’s sysroot when you start a rust-analyze session. This is due to shortcoming in cargo