@@ -6,8 +6,8 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg};
66use clippy_utils:: source:: snippet_with_applicability;
77use clippy_utils:: sugg:: Sugg ;
88use 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 ,
1111} ;
1212use rustc_ast:: ast:: LitKind ;
1313use rustc_errors:: Applicability ;
@@ -154,7 +154,10 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBool {
154154 snip = snip. blockify ( ) ;
155155 }
156156
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+ {
158161 snip = snip. maybe_par ( ) ;
159162 }
160163
@@ -442,3 +445,7 @@ fn fetch_assign<'tcx>(expr: &'tcx Expr<'tcx>) -> Option<(&'tcx Expr<'tcx>, bool)
442445 None
443446 }
444447}
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