Skip to content
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

Merged

Conversation

Kohei316
Copy link
Contributor

@Kohei316 Kohei316 commented May 2, 2024

Fixes #17106
The infer_async_block method calls the infer_block method internally, which returns the never type without coercion when tail_expr is None and ctx.diverges is Diverges::Always.This is the reason for the bug in this issue.

if this.diverges.is_always() {
// we don't even make an attempt at coercion
this.table.new_maybe_never_var()

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 of expr::Closure instead of the infer_block method. That way it will be closer to the infer process of rustc.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 2, 2024
@Kohei316 Kohei316 changed the title Fix coercion of async block Fix: infer type of async block with tail return expr May 2, 2024
@Veykril Veykril added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 13, 2024
@Veykril
Copy link
Member

Veykril commented May 23, 2024

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 of expr::Closure instead of the infer_block method. That way it will be closer to the infer process of rustc.

No I think that is correct, we should in fact handle it more like closures, as really that's what it kind of is.

@Veykril
Copy link
Member

Veykril commented May 23, 2024

Thanks for looking into this!
@bors r+

@bors
Copy link
Collaborator

bors commented May 23, 2024

📌 Commit ac3b2d4 has been approved by Veykril

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented May 23, 2024

⌛ Testing commit ac3b2d4 with merge dec43b6...

@bors
Copy link
Collaborator

bors commented May 23, 2024

☀️ Test successful - checks-actions
Approved by: Veykril
Pushing dec43b6 to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

return inside async blocks hints impl Future<Output = !>
4 participants