@@ -122,11 +122,12 @@ fn check_if_let_some_or_err_and_early_return(cx: &LateContext<'_>, expr: &Expr<'
122122 let mut applicability = Applicability :: MachineApplicable ;
123123 let receiver_str = snippet_with_applicability( cx, let_expr. span, ".." , & mut applicability) ;
124124 let by_ref = matches!( annot, BindingAnnotation :: Ref | BindingAnnotation :: RefMut ) ;
125+ let requires_semi = matches!( get_parent_node( expr) , Some ( Node :: Stmt ( _) ) ) ;
125126 let replacement = format!(
126127 "{}{}?{}" ,
127128 receiver_str,
128129 if by_ref { ".as_ref()" } else { "" } ,
129- if requires_semi( if_then , if_else ) { ";" } else { "" }
130+ if requires_semi { ";" } else { "" }
130131 ) ;
131132 offer_suggestion( cx, expr, replacement, applicability) ;
132133 }
@@ -202,18 +203,6 @@ fn expr_return_none_or_err(
202203 }
203204}
204205
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-
217206fn offer_suggestion ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > , suggestion : String , applicability : Applicability ) {
218207 if !suggestion. is_empty ( ) {
219208 span_lint_and_sugg (
0 commit comments