@@ -4,7 +4,7 @@ use clippy_utils::mir::{enclosing_mir, visit_local_usage};
44use clippy_utils:: source:: snippet;
55use clippy_utils:: ty:: is_type_diagnostic_item;
66use rustc_errors:: Applicability ;
7- use rustc_hir:: { Expr , ExprKind , Node } ;
7+ use rustc_hir:: { Expr , ExprKind , Node , PatKind } ;
88use rustc_lint:: LateContext ;
99use rustc_middle:: mir:: { Location , START_BLOCK } ;
1010use rustc_span:: sym;
@@ -25,6 +25,11 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, receiver
2525 && is_unwrap_call ( cx, unwrap_call_expr)
2626 && let parent = cx. tcx . parent_hir_node ( unwrap_call_expr. hir_id )
2727 && 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 ( '_' )
2833 && let Some ( mir) = enclosing_mir ( cx. tcx , expr. hir_id )
2934 && let Some ( ( local, _) ) = mir
3035 . local_decls
0 commit comments