@@ -4,7 +4,7 @@ use clippy_utils::mir::{enclosing_mir, visit_local_usage};
4
4
use clippy_utils:: source:: snippet;
5
5
use clippy_utils:: ty:: is_type_diagnostic_item;
6
6
use rustc_errors:: Applicability ;
7
- use rustc_hir:: { Expr , ExprKind , Node } ;
7
+ use rustc_hir:: { Expr , ExprKind , Node , PatKind } ;
8
8
use rustc_lint:: LateContext ;
9
9
use rustc_middle:: mir:: { Location , START_BLOCK } ;
10
10
use rustc_span:: sym;
@@ -25,6 +25,11 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, receiver
25
25
&& is_unwrap_call ( cx, unwrap_call_expr)
26
26
&& let parent = cx. tcx . parent_hir_node ( unwrap_call_expr. hir_id )
27
27
&& let Node :: LetStmt ( local) = parent
28
+ && let PatKind :: Binding ( .., ident, _) = local. pat . kind
29
+ // if the binding is prefixed with `_`, it typically means
30
+ // that this guard only exists to protect a section of code
31
+ // rather than the contained data
32
+ && !ident. as_str ( ) . starts_with ( '_' )
28
33
&& let Some ( mir) = enclosing_mir ( cx. tcx , expr. hir_id )
29
34
&& let Some ( ( local, _) ) = mir
30
35
. local_decls
0 commit comments