Skip to content

Unable to find definition for hashbrown #17606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fishincat opened this issue Jul 16, 2024 · 15 comments
Closed

Unable to find definition for hashbrown #17606

fishincat opened this issue Jul 16, 2024 · 15 comments
Labels
C-bug Category: bug

Comments

@fishincat
Copy link

fishincat commented Jul 16, 2024

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?

@fishincat fishincat added the C-bug Category: bug label Jul 16, 2024
@fishincat
Copy link
Author

20240716-194643

@Veykril
Copy link
Member

Veykril commented Jul 16, 2024

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

@Veykril Veykril closed this as completed Jul 16, 2024
@fishincat
Copy link
Author

@Veykril I don't know why "rust-analyzer.cargo.sysrootQueryMetadata" doesn't work any more.
image

@fishincat
Copy link
Author

Rustc toolchain was updated to 1.80.1. It's this the problem?
image

@lnicola
Copy link
Member

lnicola commented Sep 3, 2024

See #17795. I think it will start working again in 1.82.

@Veykril
Copy link
Member

Veykril commented Sep 3, 2024

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)

@fishincat
Copy link
Author

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)

Solved my problem, thx very much!

@lnicola
Copy link
Member

lnicola commented Sep 3, 2024

@fishincat wait, so does it work in 1.83.0-nightly (bd53aa3bf 2024-09-02)?

@fishincat
Copy link
Author

@fishincat wait, so does it work in 1.83.0-nightly (bd53aa3bf 2024-09-02)?

YES

@fishincat
Copy link
Author

fishincat commented Sep 3, 2024

@lnicola
It works very well on Mac OS. But I faced a problem on Linux when I use vscode connected to it(Linux remote machine) remotely.

The setting.json is:

{
    "[rust]": {
        "editor.defaultFormatter": "rust-lang.rust-analyzer",
        "editor.formatOnSave": true
    },
    //"rust-analyzer.cargo.target": "x86_64-unknown-linux-gnu",
    "rust-analyzer.cargo.buildScripts.overrideCommand": null,
    "rust-analyzer.debug.engineSettings": {
    },
    "rust-analyzer.check.overrideCommand": null,
    "rust-analyzer.server.extraEnv": null,
    //"rust-analyzer.cargo.sysroot": "discover",
    "rust-analyzer.cargo.sysroot": "/data00/home/my_name/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu",
}

The error is:

Workspace `/data00/home/my_name/code/my_project/Cargo.toml` has sysroot errors: can't find standard library sources in /data00/home/my_name/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu

How should I do?

@lnicola
Copy link
Member

lnicola commented Sep 3, 2024

We actually try to run rustup component add rust-src, I don't know why it doesn't work.

@Veykril
Copy link
Member

Veykril commented Sep 3, 2024

We actually try to run rustup component add rust-src, I don't know why it doesn't work.

We don't run that for explicit sysroot paths, only when set to discover

@fishincat
Copy link
Author

We actually try to run rustup component add rust-src, I don't know why it doesn't work.

We don't run that for explicit sysroot paths, only when set to discover

So is there any way to fix this?

@lnicola
Copy link
Member

lnicola commented Sep 3, 2024

Remove rust-analyzer.cargo.sysroot from your settings or run rustup +nightly component add rust-src.

@fishincat
Copy link
Author

fishincat commented Sep 3, 2024

Remove rust-analyzer.cargo.sysroot from your settings or run rustup +nightly component add rust-src.

Yes, It works.
You guys are really magician!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

3 participants