@@ -3,8 +3,8 @@ use clippy_utils::source::{first_line_of_span, indent_of, reindent_multiline, sn
33use clippy_utils:: ty:: needs_ordered_drop;
44use clippy_utils:: visitors:: for_each_expr;
55use clippy_utils:: {
6- capture_local_usage, eq_expr_value, get_enclosing_block, hash_expr, hash_stmt, if_sequence, is_else_clause ,
7- is_lint_allowed, path_to_local, search_same, ContainsName , HirEqInterExpr , SpanlessEq ,
6+ capture_local_usage, eq_expr_value, find_binding_init , get_enclosing_block, hash_expr, hash_stmt, if_sequence,
7+ is_else_clause , is_lint_allowed, path_to_local, search_same, ContainsName , HirEqInterExpr , SpanlessEq ,
88} ;
99use core:: iter;
1010use core:: ops:: ControlFlow ;
@@ -549,7 +549,27 @@ fn check_for_warn_of_moved_symbol(cx: &LateContext<'_>, symbols: &[(HirId, Symbo
549549
550550/// Implementation of `IFS_SAME_COND`.
551551fn lint_same_cond ( cx : & LateContext < ' _ > , conds : & [ & Expr < ' _ > ] ) {
552- for ( i, j) in search_same ( conds, |e| hash_expr ( cx, e) , |lhs, rhs| eq_expr_value ( cx, lhs, rhs) ) {
552+ for ( i, j) in search_same (
553+ conds,
554+ |e| hash_expr ( cx, e) ,
555+ |lhs, rhs| {
556+ // If any side (ex. lhs) is a method call, and the caller is not mutable,
557+ // then we can ignore side effects?
558+ if let ExprKind :: MethodCall ( _, caller, _, _) = lhs. kind {
559+ if path_to_local ( caller)
560+ . and_then ( |hir_id| find_binding_init ( cx, hir_id) )
561+ . is_some ( )
562+ {
563+ // caller is not declared as mutable
564+ SpanlessEq :: new ( cx) . eq_expr ( lhs, rhs)
565+ } else {
566+ false
567+ }
568+ } else {
569+ eq_expr_value ( cx, lhs, rhs)
570+ }
571+ } ,
572+ ) {
553573 span_lint_and_note (
554574 cx,
555575 IFS_SAME_COND ,
0 commit comments