Skip to content

fix: incorrect suggestion for async closure Future trait errors#7

Merged
fee1-dead merged 2 commits intoswe-productivity:mainfrom
blueberry-dog:async-closure-future-suggestion
Mar 1, 2026
Merged

fix: incorrect suggestion for async closure Future trait errors#7
fee1-dead merged 2 commits intoswe-productivity:mainfrom
blueberry-dog:async-closure-future-suggestion

Conversation

@blueberry-dog
Copy link

When an async closure was used incorrectly (e.g., f(async || {}())), the compiler would suggest adding () at the end, producing async || {}()() which is incorrect.

The fix now properly detects async closures by checking for async or async| prefixes, and correctly suggests wrapping the entire closure: (async || {}())().

Closes #5

When an async closure was used incorrectly (e.g., `f(async || {}())`),
the compiler would suggest adding `()` at the end, producing
`async || {}()()` which is incorrect.

The fix now properly detects async closures by checking for
`async ` or `async|` prefixes, and correctly suggests wrapping
the entire closure: `(async || {}())()`.
Copy link
Collaborator

@fee1-dead fee1-dead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this only addresses the problem partially, if you do not plan on addressing the other part, please remove the "Closes #5" in the PR description.

@fee1-dead fee1-dead self-assigned this Jan 22, 2026
Copy link
Collaborator

@fee1-dead fee1-dead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this LGTM, we can land this and do some followup later.

@fee1-dead
Copy link
Collaborator

Had a change of mind, so please address #7 (comment) as well as the new review comments before merging :)

When an async closure is already followed by `()` (e.g., `async || {}()`),
suppress the E0277 "use parentheses to call this closure" suggestion as it
would be redundant with the E0618 error that already provides the correct
fix. The E0618 error correctly suggests wrapping the closure: `(async || {})()`.

This commit also adds a test case for the fixed scenario `f(async || {})`,
which now correctly suggests `(async || {})()` to call the closure and
produce a Future.
@blueberry-dog blueberry-dog force-pushed the async-closure-future-suggestion branch from 107c797 to 003064f Compare February 9, 2026 23:15
@fee1-dead
Copy link
Collaborator

Overall I believe this looks good to me, thanks!

@fee1-dead fee1-dead merged commit 524302c into swe-productivity:main Mar 1, 2026
@fee1-dead
Copy link
Collaborator

Since this study is wrapping up, I would say I want to encourage you to be on the look out for issues like this on the main repo. You can normally browse through them at: https://github.com/rust-lang/rust/issues. This will help you find some interesting things to work on if you ever wanted to actually get started on contributing to Rust.

Even though this is simulated in a study, I would like to welcome to the project and I would be glad to see more of your PRs! Unfortunately someone has beaten you to this change at rust-lang#151194, but there are always other issues you can work on. Thank you for the contribution again, and I hope you will continue contributing :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Additional suggestion for returning async closure Future is wrong

2 participants