rust-lang / rust-lang/rust-analyzer
Confusing "no field found" diagnostic
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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