diff --git a/clippy_lints/src/needless_bool.rs b/clippy_lints/src/needless_bool.rs index b3aa1a7286a9..fa5afcc00874 100644 --- a/clippy_lints/src/needless_bool.rs +++ b/clippy_lints/src/needless_bool.rs @@ -3,7 +3,7 @@ use clippy_utils::source::snippet_with_applicability; use clippy_utils::sugg::Sugg; use clippy_utils::{ SpanlessEq, get_parent_expr, higher, is_block_like, is_else_clause, is_expn_of, is_parent_stmt, - is_receiver_of_method_call, peel_blocks, peel_blocks_with_stmt, span_extract_comment, sym, + is_receiver_of_method_call, peel_blocks, peel_blocks_with_stmt, span_contains_comment, sym, }; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; @@ -128,14 +128,13 @@ fn condition_needs_parentheses(e: &Expr<'_>) -> bool { impl<'tcx> LateLintPass<'tcx> for NeedlessBool { fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { use self::Expression::{Bool, RetBool}; - if e.span.from_expansion() || !span_extract_comment(cx.tcx.sess.source_map(), e.span).is_empty() { - return; - } - if let Some(higher::If { - cond, - then, - r#else: Some(r#else), - }) = higher::If::hir(e) + if !e.span.from_expansion() + && let Some(higher::If { + cond, + then, + r#else: Some(else_expr), + }) = higher::If::hir(e) + && !span_contains_comment(cx.tcx.sess.source_map(), e.span) { let reduce = |ret, not| { let mut applicability = Applicability::MachineApplicable; @@ -167,7 +166,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBool { applicability, ); }; - if let Some((a, b)) = fetch_bool_block(then).and_then(|a| Some((a, fetch_bool_block(r#else)?))) { + if let Some((a, b)) = fetch_bool_block(then).and_then(|a| Some((a, fetch_bool_block(else_expr)?))) { match (a, b) { (RetBool(true), RetBool(true)) | (Bool(true), Bool(true)) => { span_lint( @@ -193,7 +192,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBool { } } if let Some((lhs_a, a)) = fetch_assign(then) - && let Some((lhs_b, b)) = fetch_assign(r#else) + && let Some((lhs_b, b)) = fetch_assign(else_expr) && SpanlessEq::new(cx).eq_expr(lhs_a, lhs_b) { let mut applicability = Applicability::MachineApplicable;