Skip to content

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

Merged
merged 4 commits into from
Apr 5, 2023

Conversation

jplatte
Copy link
Contributor

@jplatte jplatte commented Mar 31, 2023

Continuation of / closes #13467.
Resolves #13230.

r? @Veykril

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 31, 2023
@jplatte jplatte changed the title Convert nested function to closure Convert nested function to closure assist Mar 31, 2023
.ancestors()
.skip(1)
.find_map(ast::Item::cast)
.map_or(false, |it| matches!(it, ast::Item::Fn(_)))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
.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

Copy link
Contributor Author

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 😄

Copy link
Member

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 😶)

Copy link
Contributor Author

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> }? 😂

@Veykril
Copy link
Member

Veykril commented Apr 5, 2023

@bors r+

@bors
Copy link
Contributor

bors commented Apr 5, 2023

📌 Commit bc704e1 has been approved by Veykril

It is now in the queue for this repository.

@Veykril Veykril changed the title Convert nested function to closure assist feat: Convert nested function to closure assist Apr 5, 2023
@bors
Copy link
Contributor

bors commented Apr 5, 2023

⌛ Testing commit bc704e1 with merge e8bad53...

@Veykril
Copy link
Member

Veykril commented Apr 5, 2023

Thanks, to you too of course @mdx97!

@bors
Copy link
Contributor

bors commented Apr 5, 2023

☀️ Test successful - checks-actions
Approved by: Veykril
Pushing e8bad53 to master...

@bors bors merged commit e8bad53 into rust-lang:master Apr 5, 2023
@jplatte jplatte deleted the convert-nested-function-to-closure branch April 5, 2023 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: "convert function to closure" assist
6 participants