Fix needless_bool.rs
This commit is contained in:
parent
09a93291ec
commit
da8b56d99a
@ -3,7 +3,7 @@
|
|||||||
//! This lint is **warn** by default
|
//! This lint is **warn** by default
|
||||||
|
|
||||||
use crate::utils::sugg::Sugg;
|
use crate::utils::sugg::Sugg;
|
||||||
use crate::utils::{in_macro, span_lint, span_lint_and_sugg};
|
use crate::utils::{higher, in_macro, span_lint, span_lint_and_sugg};
|
||||||
use rustc::hir::*;
|
use rustc::hir::*;
|
||||||
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||||
use rustc::{declare_lint_pass, declare_tool_lint};
|
use rustc::{declare_lint_pass, declare_tool_lint};
|
||||||
@ -59,7 +59,7 @@ declare_lint_pass!(NeedlessBool => [NEEDLESS_BOOL]);
|
|||||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBool {
|
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBool {
|
||||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
|
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
|
||||||
use self::Expression::*;
|
use self::Expression::*;
|
||||||
if let ExprKind::If(ref pred, ref then_block, Some(ref else_expr)) = e.node {
|
if let Some((ref pred, ref then_block, Some(ref else_expr))) = higher::if_block(&e) {
|
||||||
let reduce = |ret, not| {
|
let reduce = |ret, not| {
|
||||||
let mut applicability = Applicability::MachineApplicable;
|
let mut applicability = Applicability::MachineApplicable;
|
||||||
let snip = Sugg::hir_with_applicability(cx, pred, "<predicate>", &mut applicability);
|
let snip = Sugg::hir_with_applicability(cx, pred, "<predicate>", &mut applicability);
|
||||||
@ -119,7 +119,7 @@ fn parent_node_is_if_expr<'a, 'b>(expr: &Expr, cx: &LateContext<'a, 'b>) -> bool
|
|||||||
let parent_node = cx.tcx.hir().get_by_hir_id(parent_id);
|
let parent_node = cx.tcx.hir().get_by_hir_id(parent_id);
|
||||||
|
|
||||||
if let rustc::hir::Node::Expr(e) = parent_node {
|
if let rustc::hir::Node::Expr(e) = parent_node {
|
||||||
if let ExprKind::If(_, _, _) = e.node {
|
if higher::if_block(&e).is_some() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user