Use ControlFlow
in more visitors
#12829
Labels
performance-project
For issues and PRs related to the Clippy Performance Project
Description
As of "recently" the
Visitor
andTypeVisitor
traits have an optional associatedResult
type that can be used to early exit the visitor, by settingtype Result = ControlFlow<()>
(instead of the implicittype 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 settingtype Result = ControlFlow<()>;
in more places.This seems especially useful for e.g.
for_each_expr
, where a lot of lints already do returnControlFlow
.Version
No response
Additional Labels
No response
The text was updated successfully, but these errors were encountered: