rust-lang / rust-lang/rust-analyzer

Rust detecting most types as "unknown" or outright getting types wrong all of the sudden

Open
#12,748 16 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

rust-analyzer version: rust-analyzer version: 0.0.0 (5342f47f4 2022-07-09)

rustc version: rustc 1.61.0 (fe5b13d68 2022-05-18)

relevant settings: (eg. client settings, or environment variables like CARGO, RUSTUP_HOME or CARGO_HOME): No relevant environment variables, but I do have Rust running inside a Nix environment.

I have issues recently that appeared out of nowhere with Rust-Analyzer suddenly being unable to infer many types, often setting them to unknown or just outright getting them wrong, even in very simple cases. For example, I have a struct that's being parsed with clap, and originally the type inference worked when I did:

let data = example_struct::Parse()

originally it would correctly infer the type correctly as :example_struct but now it is {unknown}

When creating a new instance of a struct via an asynchronous function in one file it is able to infer the type:
let result = result_struct::new().await and will successfully label the type as result_struct but then in a similar file that uses that same identical line of code, it will simply say {unknown}

Or, when calling a random function I made called restore rust-analyzer was originally able to type it successfully as an anyhow result type of Result<()> but now rust-analyzer feels it is of ?Sized impl
and even weirder the rust-analyzer will often triple list the types, so rather than it just listing the types once it will repeat it 3 times so it shows as ?Sized impl ?Sized impl ?Sized impl

I thought perhaps this (even though it was initially working) out of nowhere loss in functionality was brought about by me using rust-analyzer with the local installation of Rust rather than the Nix one, but I tried launching VSCode from within the Nix repo, and even tried the nix environment switcher plugin and got the same strange analyzer results. I even tried running cargo clean and that also achieved nothing. Does this issue sound familiar to anyone?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported type-inference failures with rust-analyzer 0.0.0 and rustc 1.61.0, using the simple struct, async constructor, and anyhow Result examples from the report. Compare behavior inside and outside the Nix environment after the reported cargo clean; done means identifying the cause and restoring correct, non-duplicated inferred types.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.