rust-lang / rust-lang/rust-analyzer

Type mismatch with `!` on async function

Open
#22,853 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

https://github.com/rust-lang/rust-analyzer/pull/22852 fixes https://github.com/rust-lang/rust-analyzer/issues/22847, but a similar code still emit a type mismatch:

async fn test() -> ! {
    test().await;
}

(This code does not compile as-is, you need to Box::pin(test()). However for a test in hir-ty it is enough).

When the function calls itself instead of another function we still fail. I investigated this a bit, and it appears that we fail to normalize <RPIT_opaque as IntoFuture>::Output into ! in time (that is, when inferring the .await). When calling another function, the solver knows it cannot normalize the opaque and so it only uses its bounds and normalizes the projection from them; but when inside the function, we can normalize the opaque but we don't know it yet, which seems to make the solver fail to normalize instead of normalizing via the bounds.

This code however does compile in rustc with -Znext-solver=globally, so it seems the problem is in our code and not in the solver (I didn't check with the same solver version as we use though).

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 in the hir-ty inference tests with the recursive async function example, using Box::pin(test()) as noted in the issue. Compare inference for a self-call with a call to another function, and check rustc with -Znext-solver=globally as a reference. Done means the recursive case no longer reports the type mismatch and the regression is covered by a test.

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
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.