rust-lang / rust-lang/rust-analyzer

Type inference recovery can infer unsized locals

Open
#22,518 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Bit of a weird one and might be pointless to think about but in the following erroneous snippet


trait DynT {}
fn f(_: &dyn DynT) {}
fn main() {
    let unresolved = unresolved;
    f(&unresolved);
    unresolved.foo();
}

we assign dyn DynT to unresolved. I feel like this is a bad recovery, since we can't have unsized locals, imo it would be better in this case to fallback to an error type? Interestingly enough if we assign an error type reference to unresolved we also fall back to the same type instead of assigning an error type to the local, probably because unification takes over still.

cc @ChayimFriedman2 idk if you have opinions on this, if you think this is fine as is feel free to close :)

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 erroneous Rust snippet from the issue and tracing type inference recovery around the unresolved local, trait-object argument, and later method call. No source file or test is named; done means reaching an agreed recovery behavior and adding coverage for the demonstrated case.

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
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.