-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: infer type of async block with tail return expr #17174
Fix: infer type of async block with tail return expr #17174
Conversation
No I think that is correct, we should in fact handle it more like closures, as really that's what it kind of is. |
Thanks for looking into this! |
☀️ Test successful - checks-actions |
Fixes #17106
The
infer_async_block
method calls theinfer_block
method internally, which returns the never type without coercion whentail_expr
isNone
andctx.diverges
isDiverges::Always
.This is the reason for the bug in this issue.rust-analyzer/crates/hir-ty/src/infer/expr.rs
Lines 1411 to 1413 in cfce2bb
This PR solves the bug by adding a process to coerce after calling
infer_block
method.This code passes all the tests, including tests I added for this isuue, however, I am not sure if this solution is right. I think that this solution is an ad hoc solution. So, I would appreciate to have your review.
I apologize if I'm off the mark, but
infer_async_block
method should be rewritten to share code with the process of infering type ofexpr::Closure
instead of theinfer_block
method. That way it will be closer to the infer process of rustc.