pub fn potential_return_of_enclosing_body(
cx: &LateContext<'_>,
expr: &Expr<'_>,
) -> bool
Expand description
Checks if expr
may be directly used as the return value of its enclosing body.
The following cases are covered:
expr
as the last expression of the body, or of a block that can be used as the return valuereturn expr
- then or else part of a
if
in return position - arm body of a
match
in a return position break expr
orbreak 'label expr
if the loop or block being exited is used as a return value
Contrary to TyCtxt::hir_get_fn_id_for_return_block()
, if expr
is part of a
larger expression, for example a field expression of a struct
, it will not be
considered as matching the condition and will return false
.
Also, even if expr
is assigned to a variable which is later returned, this function
will still return false
because expr
is not used directly as the return value
as it goes through the intermediate variable.