@@ -82,7 +82,7 @@ enum IfBlockType<'hir> {
8282/// ```
8383///
8484/// If it matches, it will suggest to use the question mark operator instead
85- fn check_is_none_or_err_and_early_return ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) {
85+ fn check_is_none_or_err_and_early_return < ' tcx > ( cx : & LateContext < ' tcx > , expr : & Expr < ' tcx > ) {
8686 if_chain ! {
8787 if let Some ( higher:: If { cond, then, r#else } ) = higher:: If :: hir( expr) ;
8888 if !is_else_clause( cx. tcx, expr) ;
@@ -109,7 +109,7 @@ fn check_is_none_or_err_and_early_return(cx: &LateContext<'_>, expr: &Expr<'_>)
109109 }
110110}
111111
112- fn check_if_let_some_or_err_and_early_return ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) {
112+ fn check_if_let_some_or_err_and_early_return < ' tcx > ( cx : & LateContext < ' tcx > , expr : & Expr < ' tcx > ) {
113113 if_chain ! {
114114 if let Some ( higher:: IfLet { let_pat, let_expr, if_then, if_else } ) = higher:: IfLet :: hir( cx, expr) ;
115115 if !is_else_clause( cx. tcx, expr) ;
@@ -120,6 +120,11 @@ fn check_if_let_some_or_err_and_early_return(cx: &LateContext<'_>, expr: &Expr<'
120120 if ( is_early_return( sym:: Option , cx, & if_block) && path_to_local_id( peel_blocks( if_then) , bind_id) )
121121 || is_early_return( sym:: Result , cx, & if_block) ;
122122 then {
123+ if let Some ( else_expr) = if_else {
124+ if eq_expr_value( cx, let_expr, peel_blocks( else_expr) ) {
125+ return ;
126+ }
127+ }
123128 let mut applicability = Applicability :: MachineApplicable ;
124129 let receiver_str = snippet_with_applicability( cx, let_expr. span, ".." , & mut applicability) ;
125130 let by_ref = matches!( annot, BindingAnnotation :: Ref | BindingAnnotation :: RefMut ) ;
0 commit comments