pub fn pat_and_expr_can_be_question_mark<'a, 'hir>(
cx: &LateContext<'_>,
pat: &'a Pat<'hir>,
else_body: &Expr<'_>,
) -> Option<&'a Pat<'hir>>Expand description
Returns whether the given let pattern and else body can be turned into the ? operator
For this example:
ⓘ
let FooBar { a, b } = if let Some(a) = ex { a } else { return None };We get as parameters:
ⓘ
pat: Some(a)
else_body: return NoneAnd for this example:
ⓘ
let Some(FooBar { a, b }) = ex else { return None };We get as parameters:
ⓘ
pat: Some(FooBar { a, b })
else_body: return NoneWe output Some(a) in the first instance, and Some(FooBar { a, b }) in the second, because
the ? operator is applicable here. Callers have to check whether we are in a constant or not.