rust-lang / rust-lang/rust-analyzer

Confusing "no field found" diagnostic

Open
#18,872 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

struct S {
    field: (),
}
fn f(_: impl FnOnce(S)) {}
fn main() {
    let cb = |s| _ = s.field;
    f(cb)
}

Here we report a "no field field on type S" diagnostic on the field access. Now this diagnostic is correct (rustc will fail here as well), the issue is that by the time we try to resolve the field we don't actually yet know what type s has, we only learn about this fact later on when the closure is used and we resolve all outstanding type variables once at the end of inference. This is where we then resolve the unknown type to S within the diagnostic which causes this confusing output. We should prevent the last part from happening.

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 supplied closure example and tracing field-access diagnostic handling through closure inference. Focus on where outstanding type variables are resolved for the diagnostic; done means the diagnostic no longer substitutes the later-resolved S type while the field access remains correctly rejected.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.