-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
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