# Function clippy_utils::walk_to_expr_usage

source ·

    pub fn walk_to_expr_usage<'tcx, T>(
        cx: &LateContext<'tcx>,
        e: &Expr<'tcx>,
        f: impl FnMut(HirId, Node<'tcx>, HirId) -> ControlFlow<T>,
    ) -> Option<ControlFlow<T, (Node<'tcx>, HirId)>>

Expand description

Walks up the HIR tree from the given expression in an attempt to find where the value is consumed.

Termination has three conditions:

- The given function returns `Break`. This function will return the value.
- The consuming node is found. This function will return `Continue(use_node, child_id)`.
- No further parent nodes are found. This will trigger a debug assert or return `None`.

This allows walking through `if`, `match`, `break`, and block expressions to find where the value produced by the expression is consumed.