rust-lang / rust-lang/rust-analyzer

rust_analyzer fails to resolve type information if custom deref implementation exists

Open
#23,329 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

rust-analyzer version: (eg. output of "rust-analyzer: Show RA Version" command, accessible in VSCode via Ctrl/⌘+Shift+P)
rust-analyzer 0.3.3041-standalone

rustc version: (eg. output of rustc -V)
rustc 1.98.1 (48a229cea 2026-09-01)

editor or extension: (eg. VSCode, Vim, Emacs, etc. For VSCode users, specify your extension version; for users of other editors, provide the distribution if applicable)
Neovim with custom config, though the same happens in fresh LazyVim config with rust_analyzer LSP installed via :Mason

relevant settings: (eg. client settings, or environment variables like CARGO, RUSTC, RUSTUP_HOME or CARGO_HOME)
I set nothing that I'm aware of

repository link (if public, optional): (eg. rust-analyzer)
See link in reproduction section below

code snippet to reproduce:
See reproduction project here: https://github.com/Linus045/rust_analyzer_bug

First up, I'm not that experienced with rust so this my be an oversight on my part and not an issue with rust_analyzer, though it seems weird to me that I get not type info at all.

I was working with tauri and used a rather complex type from the mdns_sd crate inside a struct that I then used inside a tauri::State struct (see commented out code at the beginning, line 25 in example1()).
For some reason, as soon as I added the ServiceDaemon type in the Test struct, the autocompletion for the state object broke. It shows up as red underlines in my editor (see the inner() and lock() function calls in the image) and when I try to hover over the type it shows {unknown}.

I investigated and tracked the issue down to the the Deref trait implementation for tauri::State.
I copied the tauri State struct and created my own TestState which showed the same issue: If I comment out the Deref impl the type resolution works (see line 48in the example main.rs) but as soon as I add it back in it fails.

I'm not familiar enough with rust to reduce the example code any further but I hope someone else can maybe help with that.
Also I tried to check existing issues but its hard to search for as I don't even exactly know what to search for, so sorry if this is a duplicate.

Additional info:

  • cargo check shows no errors or warnings.

  • there is some differnt behavior using .0 or .inner() with multiple let definitions, see example2(), example3() and example4() which I don't fully understand

  • I don't fully understand lifetimes and deref behavior yet so maybe this might be an error with the tauri::State implementation?

  • dependencies used:

[dependencies]
tokio = { version = "1.53.1", features = ["macros", "rt-multi-thread", "sync"] }
tauri = { version = "2", features = [] }
mdns-sd = "0.19.1"

See reproduction project here: https://github.com/Linus045/rust_analyzer_bug
Image

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 with the linked reproduction project and inspect src/main.rs, especially example1() through example4() and the copied TestState Deref implementation. Compare rust-analyzer's type information and completion with Deref enabled and disabled, then verify the behavior against the tauri::State example; done means the state object's types and method calls resolve correctly while cargo check remains clean.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, tauri
Domain
developer-experience, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.