@@ -122,11 +122,12 @@ fn check_if_let_some_or_err_and_early_return(cx: &LateContext<'_>, expr: &Expr<'
122
122
let mut applicability = Applicability :: MachineApplicable ;
123
123
let receiver_str = snippet_with_applicability( cx, let_expr. span, ".." , & mut applicability) ;
124
124
let by_ref = matches!( annot, BindingAnnotation :: Ref | BindingAnnotation :: RefMut ) ;
125
+ let requires_semi = matches!( get_parent_node( expr) , Some ( Node :: Stmt ( _) ) ) ;
125
126
let replacement = format!(
126
127
"{}{}?{}" ,
127
128
receiver_str,
128
129
if by_ref { ".as_ref()" } else { "" } ,
129
- if requires_semi( if_then , if_else ) { ";" } else { "" }
130
+ if requires_semi { ";" } else { "" }
130
131
) ;
131
132
offer_suggestion( cx, expr, replacement, applicability) ;
132
133
}
@@ -202,18 +203,6 @@ fn expr_return_none_or_err(
202
203
}
203
204
}
204
205
205
- /// Check whether the fixed code needs semicolon after `?`
206
- ///
207
- /// It will need a semicolon if all block(s) has one.
208
- fn requires_semi ( if_then : & Expr < ' _ > , if_else : Option < & Expr < ' _ > > ) -> bool {
209
- let if_then_kind = & peel_blocks_with_stmt ( if_then) . kind ;
210
- let if_then_is_ret_stmt = matches ! ( if_then_kind, ExprKind :: Ret ( ..) ) ;
211
- if if_else. is_none ( ) || matches ! ( peel_blocks_with_stmt( if_else. unwrap( ) ) . kind, ExprKind :: Ret ( _) ) {
212
- return if_then_is_ret_stmt;
213
- }
214
- false
215
- }
216
-
217
206
fn offer_suggestion ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > , suggestion : String , applicability : Applicability ) {
218
207
if !suggestion. is_empty ( ) {
219
208
span_lint_and_sugg (
0 commit comments