Skip to content

Conversation

@Veykril
Copy link
Member

@Veykril Veykril commented Nov 6, 2020

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)

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()? {
Copy link

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?

Copy link
Member Author

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 😅

@matklad
Copy link
Contributor

matklad commented Nov 6, 2020

bors r+

@bors
Copy link
Contributor

bors bot commented Nov 6, 2020

@bors bors bot merged commit cdddcae into rust-lang:master Nov 6, 2020
@Veykril Veykril deleted the ty-ret branch November 27, 2020 18:19
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.

3 participants