-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add infer_function_return_type assist #6477
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
Conversation
| fn extract_tail(expr: ast::Expr) -> Option<(ast::Expr, SyntaxToken, bool)> { | ||
| let (ret_ty, tail_expr, insert_pos, wrap_expr) = | ||
| if let Some(closure) = expr.syntax().ancestors().find_map(ast::ClosureExpr::cast) { | ||
| let (tail_expr, wrap_expr) = match closure.body()? { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey--commenting out of curiosity but would this always infer function types for lambdas? Is that something that's wanted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would give you the option to have this assist explicitly annotate the closure return type if you are in the last expression of the closure. This is an action the user would have to trigger. So the user has to trigger the assist to have it annotate the closure with its explicit return type.
The assist name is poorly chosen I think but I couldn't come up with a better name 😅
|
bors r+ |
This adds an assist to insert a functions return type if it hasn't been specified yet by inferring it from the functions tail expression. This assist only becomes active if the cursor is on the tail expression. See #6303 (comment)