mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-23 02:27:39 +03:00
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:
@@ -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();
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user