walk_to_expr_usage in clippy_utils - Rust
Description: Walks up the HIR tree from the given expression in an attempt to find where the value is consumed.

Skip to main content

## walk_to_expr_usage

# Function 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.