Skip to content
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

Use ControlFlow in more visitors #12829

Open
y21 opened this issue May 21, 2024 · 1 comment · May be fixed by #12830
Open

Use ControlFlow in more visitors #12829

y21 opened this issue May 21, 2024 · 1 comment · May be fixed by #12830
Assignees
Labels
performance-project For issues and PRs related to the Clippy Performance Project

Comments

@y21
Copy link
Member

y21 commented May 21, 2024

Description

As of "recently" the Visitor and TypeVisitor traits have an optional associated Result type that can be used to early exit the visitor, by setting type Result = ControlFlow<()> (instead of the implicit type Result = ()).

A lot of lints (and utils) use visitors to search for something in HIR nodes and try to avoid doing a bunch of extra work by storing something like a bool for "done" and then ignore any visit_* calls when set to true, but rustc will still keep calling into the visitor (for e.g. the remaining statements in a block), so it seems like a good idea to make use of this associated type by setting type Result = ControlFlow<()>; in more places.

This seems especially useful for e.g. for_each_expr, where a lot of lints already do return ControlFlow.

Version

No response

Additional Labels

No response

@blyxyas
Copy link
Member

blyxyas commented May 21, 2024

@rustbot claim

@blyxyas blyxyas added the performance-project For issues and PRs related to the Clippy Performance Project label May 21, 2024
@blyxyas blyxyas linked a pull request May 21, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance-project For issues and PRs related to the Clippy Performance Project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants