fix: incorrect suggestion for async closure Future trait errors#7
Conversation
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 || {}())()`.
tests/ui/suggestions/async-closure-inline-call-suggestion.stderr
Outdated
Show resolved
Hide resolved
compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs
Outdated
Show resolved
Hide resolved
fee1-dead
left a comment
There was a problem hiding this comment.
Overall this LGTM, we can land this and do some followup later.
compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs
Outdated
Show resolved
Hide resolved
|
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.
107c797 to
003064f
Compare
|
Overall I believe this looks good to me, thanks! |
|
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 :) |
When an async closure was used incorrectly (e.g.,
f(async || {}())), the compiler would suggest adding()at the end, producingasync || {}()()which is incorrect.The fix now properly detects async closures by checking for
asyncorasync|prefixes, and correctly suggests wrapping the entire closure:(async || {}())().Closes #5