-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: Convert nested function to closure assist #14455
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
feat: Convert nested function to closure assist #14455
Conversation
crates/ide-assists/src/handlers/convert_nested_function_to_closure.rs
Outdated
Show resolved
Hide resolved
crates/ide-assists/src/handlers/convert_nested_function_to_closure.rs
Outdated
Show resolved
Hide resolved
crates/ide-assists/src/handlers/convert_nested_function_to_closure.rs
Outdated
Show resolved
Hide resolved
.ancestors() | ||
.skip(1) | ||
.find_map(ast::Item::cast) | ||
.map_or(false, |it| matches!(it, ast::Item::Fn(_))) |
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.
.map_or(false, |it| matches!(it, ast::Item::Fn(_))) | |
.map_or(false, |it| matches!(it, ast::Item::Fn(_) | ast::Item::Static(_) | ast::Item::Const(_))) |
Might as well make it usable in other bodies
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.
I reckon it's extremely uncommon to have a function nested inside a const or static initializer, but sure why not 😄
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.
I'm not going to deny that, but you never know (If we want to be very pedantic, we should actually check for enum variants, const arguments and const parameter defaults as well 😶)
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.
I understand const arguments and const parameter defaults, but enum variants? You mean enum variant numbers, as in you can have a block expression in enum Foo { Bar = <here> }
? 😂
@bors r+ |
Thanks, to you too of course @mdx97! |
☀️ Test successful - checks-actions |
Continuation of / closes #13467.
Resolves #13230.
r? @Veykril