@@ -11,7 +11,7 @@ use clippy_utils::{
11
11
use core:: iter;
12
12
use core:: ops:: ControlFlow ;
13
13
use rustc_errors:: Applicability ;
14
- use rustc_hir:: { BinOpKind , Block , Expr , ExprKind , HirId , HirIdSet , Stmt , StmtKind , intravisit} ;
14
+ use rustc_hir:: { BinOpKind , Block , Expr , ExprKind , HirId , HirIdSet , LetStmt , Node , Stmt , StmtKind , intravisit} ;
15
15
use rustc_lint:: { LateContext , LateLintPass } ;
16
16
use rustc_middle:: ty:: TyCtxt ;
17
17
use rustc_session:: impl_lint_pass;
@@ -295,7 +295,7 @@ fn lint_branches_sharing_code<'tcx>(
295
295
sugg,
296
296
Applicability :: Unspecified ,
297
297
) ;
298
- if !cx. typeck_results ( ) . expr_ty ( expr) . is_unit ( ) {
298
+ if is_expr_parent_assignment ( cx , expr ) || !cx. typeck_results ( ) . expr_ty ( expr) . is_unit ( ) {
299
299
diag. note ( "the end suggestion probably needs some adjustments to use the expression result correctly" ) ;
300
300
}
301
301
}
@@ -660,3 +660,17 @@ fn lint_same_fns_in_if_cond(cx: &LateContext<'_>, conds: &[&Expr<'_>]) {
660
660
) ;
661
661
}
662
662
}
663
+
664
+ fn is_expr_parent_assignment ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) -> bool {
665
+ let parent = cx. tcx . parent_hir_node ( expr. hir_id ) ;
666
+ if let Node :: LetStmt ( LetStmt { init : Some ( e) , .. } )
667
+ | Node :: Expr ( Expr {
668
+ kind : ExprKind :: Assign ( _, e, _) ,
669
+ ..
670
+ } ) = parent
671
+ {
672
+ return e. hir_id == expr. hir_id ;
673
+ }
674
+
675
+ false
676
+ }
0 commit comments