Skip to content
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

Rust-analyzer cannot infer types in a simple HashMap example #17262

Open
uv-xiao opened this issue May 20, 2024 · 2 comments
Open

Rust-analyzer cannot infer types in a simple HashMap example #17262

uv-xiao opened this issue May 20, 2024 · 2 comments
Labels
C-bug Category: bug

Comments

@uv-xiao
Copy link

uv-xiao commented May 20, 2024

rust-analyzer version: rust-analyzer version: 0.4.1960-standalone

rustc version: rustc 1.77.0-nightly (7ffc697ce 2024-01-24)

editor or extension: VSCode

relevant settings:

code snippet to reproduce:

#[derive(Debug)]
struct Value;

#[derive(Default)]
struct Container {
  map: HashMap<u64, Value>,
}

#[test]
fn test() {
  let mut container = Container::default();
  container.map.insert(0, Value);
  let value = container.map.get(&0);
  println!("{:?}", value);
}

description: In the code above, rust-analyzer cannot determine the type of the value variable and the map field of the container variable, showing {unknown} for both.

image

However, if I give a type signature for value manually as follows, no errors will be reported, and rust-analyzer will present fields and methods of value in a correct way.

let value: Option<&Value> = container.map.get(&0);
println!("{:?}", value);

image

@uv-xiao uv-xiao added the C-bug Category: bug label May 20, 2024
@Veykril
Copy link
Member

Veykril commented May 20, 2024

This is fixed in the latest version and in fact works fine for me

@Veykril Veykril closed this as completed May 20, 2024
@Veykril Veykril reopened this May 20, 2024
@uv-xiao
Copy link
Author

uv-xiao commented May 20, 2024

This is fixed in the latest version and in fact works fine for me

Thanks a lot for your rapid reply, @Veykril.

However, the VSCode extension rust-analyzer doesn't show any available updates for me. Could you please show me the version that fixed the issue?

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

2 participants