@@ -6,8 +6,8 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg};
6
6
use clippy_utils:: source:: snippet_with_applicability;
7
7
use clippy_utils:: sugg:: Sugg ;
8
8
use clippy_utils:: {
9
- higher, is_block_like, is_else_clause, is_expn_of, is_parent_stmt, peel_blocks , peel_blocks_with_stmt ,
10
- span_extract_comment, SpanlessEq ,
9
+ get_parent_expr , higher, is_block_like, is_else_clause, is_expn_of, is_parent_stmt, is_receiver_of_method_call ,
10
+ peel_blocks , peel_blocks_with_stmt , span_extract_comment, SpanlessEq ,
11
11
} ;
12
12
use rustc_ast:: ast:: LitKind ;
13
13
use rustc_errors:: Applicability ;
@@ -154,7 +154,10 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBool {
154
154
snip = snip. blockify ( ) ;
155
155
}
156
156
157
- if condition_needs_parentheses ( cond) && is_parent_stmt ( cx, e. hir_id ) {
157
+ if ( condition_needs_parentheses ( cond) && is_parent_stmt ( cx, e. hir_id ) )
158
+ || is_receiver_of_method_call ( cx, e)
159
+ || is_as_argument ( cx, e)
160
+ {
158
161
snip = snip. maybe_par ( ) ;
159
162
}
160
163
@@ -442,3 +445,7 @@ fn fetch_assign<'tcx>(expr: &'tcx Expr<'tcx>) -> Option<(&'tcx Expr<'tcx>, bool)
442
445
None
443
446
}
444
447
}
448
+
449
+ fn is_as_argument ( cx : & LateContext < ' _ > , e : & Expr < ' _ > ) -> bool {
450
+ matches ! ( get_parent_expr( cx, e) . map( |e| e. kind) , Some ( ExprKind :: Cast ( _, _) ) )
451
+ }
0 commit comments