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:
commit
59291a75df
3 changed files with 25 additions and 0 deletions
|
|
@ -142,6 +142,7 @@ fn check_let_some_else_return_none(cx: &LateContext<'_>, stmt: &Stmt<'_>) {
|
|||
&& 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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue