Auto merge of #11802 - dswij:issue-11765, r=xFrednet
`needless_return_with_question_mark` ignore let-else Fixes #11765 This PR makes `needless_return_with_question_mark` to ignore expr inside let-else. changelog: [`needless_return_with_question_mark`] ignore let-else
This commit is contained in:
commit
7ad3373bb1
5 changed files with 84 additions and 2 deletions
|
|
@ -2,7 +2,7 @@ use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then, span_lin
|
|||
use clippy_utils::source::{snippet_opt, snippet_with_context};
|
||||
use clippy_utils::sugg::has_enclosing_paren;
|
||||
use clippy_utils::visitors::{for_each_expr_with_closures, Descend};
|
||||
use clippy_utils::{fn_def_id, is_from_proc_macro, path_to_local_id, span_find_starting_semi};
|
||||
use clippy_utils::{fn_def_id, is_from_proc_macro, is_inside_let_else, path_to_local_id, span_find_starting_semi};
|
||||
use core::ops::ControlFlow;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::intravisit::FnKind;
|
||||
|
|
@ -170,6 +170,7 @@ impl<'tcx> LateLintPass<'tcx> for Return {
|
|||
&& let ItemKind::Fn(_, _, body) = item.kind
|
||||
&& let block = cx.tcx.hir().body(body).value
|
||||
&& let ExprKind::Block(block, _) = block.kind
|
||||
&& !is_inside_let_else(cx.tcx, expr)
|
||||
&& let [.., final_stmt] = block.stmts
|
||||
&& final_stmt.hir_id != stmt.hir_id
|
||||
&& !is_from_proc_macro(cx, expr)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue