Function clippy_utils::macros::first_node_in_macro

source ·
pub fn first_node_in_macro(
    cx: &LateContext<'_>,
    node: &impl HirNode
) -> Option<ExpnId>
Expand description

If node is the “first node” in a macro expansion, returns Some with the ExpnId of the macro call site (i.e. the parent of the macro expansion). This generally means that node is the outermost node of an entire macro expansion, but there are some caveats noted below. This is useful for finding macro calls while visiting the HIR without processing the macro call at every node within its expansion.

If you already have immediate access to the parent node, it is simpler to just check the context of that span directly (e.g. parent.span.from_expansion()).

If a macro call is in statement position, it expands to one or more statements. In that case, each statement and their immediate descendants will all yield Some with the ExpnId of the containing block.

A node may be the “first node” of multiple macro calls in a macro backtrace. The expansion of the outermost macro call site is returned in such cases.