Fix clippy::question_mark on let-else with cfg (#15082)

Fixes rust-lang/rust-clippy#13642

changelog: Fix false positive in [`question_mark`] when else branch of
let-else contains `#[cfg]`
This commit is contained in:
Samuel Tardieu
2025-06-19 20:34:05 +00:00
committed by GitHub
3 changed files with 25 additions and 0 deletions
+1
View File
@@ -142,6 +142,7 @@ fn init_expr_can_use_question_mark(cx: &LateContext<'_>, init_expr: &Expr<'_>) -
&& let Some(ret) = find_let_else_ret_expression(els)
&& let Some(inner_pat) = pat_and_expr_can_be_question_mark(cx, pat, ret)
&& !span_contains_comment(cx.tcx.sess.source_map(), els.span)
&& !span_contains_cfg(cx, els.span)
{
let mut applicability = Applicability::MaybeIncorrect;
let init_expr_str = Sugg::hir_with_applicability(cx, init_expr, "..", &mut applicability).maybe_paren();
+12
View File
@@ -453,3 +453,15 @@ fn const_in_pattern(x: Option<(i32, i32)>) -> Option<()> {
None
}
fn issue_13642(x: Option<i32>) -> Option<()> {
let Some(x) = x else {
#[cfg(false)]
panic!();
#[cfg(true)]
return None;
};
None
}
+12
View File
@@ -549,3 +549,15 @@ fn const_in_pattern(x: Option<(i32, i32)>) -> Option<()> {
None
}
fn issue_13642(x: Option<i32>) -> Option<()> {
let Some(x) = x else {
#[cfg(false)]
panic!();
#[cfg(true)]
return None;
};
None
}