@@ -9,7 +9,7 @@ use rustc_span::sym;
9
9
use clippy_utils:: diagnostics:: span_lint_and_sugg;
10
10
use clippy_utils:: source:: snippet_opt;
11
11
use clippy_utils:: ty:: implements_trait;
12
- use clippy_utils:: { in_constant, is_default_equivalent} ;
12
+ use clippy_utils:: { in_constant, is_default_equivalent, peel_blocks_with_stmt } ;
13
13
14
14
declare_clippy_lint ! {
15
15
/// ### What it does
@@ -119,11 +119,11 @@ fn handle_match<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> bool {
119
119
// We now get the bodies for both the `Some` and `None` arms.
120
120
&& let Some ( ( ( body_some, binding_id) , body_none) ) = get_some_and_none_bodies ( cx, arm1, arm2)
121
121
// We check that the `Some(x) => x` doesn't do anything apart "returning" the value in `Some`.
122
- && let ExprKind :: Path ( QPath :: Resolved ( _, path) ) = body_some . peel_blocks ( ) . kind
122
+ && let ExprKind :: Path ( QPath :: Resolved ( _, path) ) = peel_blocks_with_stmt ( body_some ) . kind
123
123
&& let Res :: Local ( local_id) = path. res
124
124
&& local_id == binding_id
125
125
// We now check the `None` arm is calling a method equivalent to `Default::default`.
126
- && let body_none = body_none . peel_blocks ( )
126
+ && let body_none = peel_blocks_with_stmt ( body_none )
127
127
&& is_default_equivalent ( cx, body_none)
128
128
&& let Some ( receiver) = Sugg :: hir_opt ( cx, match_expr) . map ( Sugg :: maybe_par)
129
129
{
@@ -134,7 +134,7 @@ fn handle_match<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> bool {
134
134
"match can be simplified with `.unwrap_or_default()`" ,
135
135
"replace it with" ,
136
136
format ! ( "{receiver}.unwrap_or_default()" ) ,
137
- Applicability :: MachineApplicable ,
137
+ Applicability :: MaybeIncorrect ,
138
138
) ;
139
139
}
140
140
true
@@ -150,11 +150,11 @@ fn handle_if_let<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
150
150
&& implements_trait ( cx, match_ty, default_trait_id, & [ ] )
151
151
&& let Some ( binding_id) = get_some ( cx, let_. pat )
152
152
// We check that the `Some(x) => x` doesn't do anything apart "returning" the value in `Some`.
153
- && let ExprKind :: Path ( QPath :: Resolved ( _, path) ) = if_block . peel_blocks ( ) . kind
153
+ && let ExprKind :: Path ( QPath :: Resolved ( _, path) ) = peel_blocks_with_stmt ( if_block ) . kind
154
154
&& let Res :: Local ( local_id) = path. res
155
155
&& local_id == binding_id
156
156
// We now check the `None` arm is calling a method equivalent to `Default::default`.
157
- && let body_else = else_expr . peel_blocks ( )
157
+ && let body_else = peel_blocks_with_stmt ( else_expr )
158
158
&& is_default_equivalent ( cx, body_else)
159
159
&& let Some ( if_let_expr_snippet) = snippet_opt ( cx, let_. init . span )
160
160
{
@@ -165,7 +165,7 @@ fn handle_if_let<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
165
165
"if let can be simplified with `.unwrap_or_default()`" ,
166
166
"replace it with" ,
167
167
format ! ( "{if_let_expr_snippet}.unwrap_or_default()" ) ,
168
- Applicability :: MachineApplicable ,
168
+ Applicability :: MaybeIncorrect ,
169
169
) ;
170
170
}
171
171
}
0 commit comments