rust-lang / rust-lang/rust-analyzer
Type mismatch with `!` on async function
Nobody has claimed this yet.
- 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
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 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