diff --git a/src/types.rs b/src/types.rs index 948e8fd063d..9adc2cc5680 100644 --- a/src/types.rs +++ b/src/types.rs @@ -679,6 +679,7 @@ fn detect_absurd_comparison<'a>(cx: &LateContext, op: BinOp_, lhs: &'a Expr, rhs _ => return None, } } + Rel::Ne | Rel::Eq => return None, }) } @@ -914,14 +915,20 @@ fn upcast_comparison_bounds_err( if let Some(nlb) = lhs_bounds { if let Some(norm_rhs_val) = node_as_const_fullint(cx, rhs) { - if match rel { + if rel == Rel::Eq || rel == Rel::Ne { + if norm_rhs_val < nlb.0 || norm_rhs_val > nlb.0 { + err_upcast_comparison(cx, &span, lhs, rel == Rel::Ne); + } + } else if match rel { Rel::Lt => if invert { norm_rhs_val < nlb.0 } else { nlb.1 < norm_rhs_val }, Rel::Le => if invert { norm_rhs_val <= nlb.0 } else { nlb.1 <= norm_rhs_val }, + Rel::Eq | Rel::Ne => unreachable!(), } { err_upcast_comparison(cx, &span, lhs, true) } else if match rel { Rel::Lt => if invert { norm_rhs_val >= nlb.1 } else { nlb.0 >= norm_rhs_val }, Rel::Le => if invert { norm_rhs_val > nlb.1 } else { nlb.0 > norm_rhs_val }, + Rel::Eq | Rel::Ne => unreachable!(), } { err_upcast_comparison(cx, &span, lhs, false) } diff --git a/src/utils/comparisons.rs b/src/utils/comparisons.rs index 2222c31a4f9..a9181b35b38 100644 --- a/src/utils/comparisons.rs +++ b/src/utils/comparisons.rs @@ -4,6 +4,8 @@ use rustc_front::hir::{BinOp_, Expr}; pub enum Rel { Lt, Le, + Eq, + Ne, } /// Put the expression in the form `lhs < rhs` or `lhs <= rhs`. @@ -14,6 +16,8 @@ pub fn normalize_comparison<'a>(op: BinOp_, lhs: &'a Expr, rhs: &'a Expr) BinOp_::BiLe => Some((Rel::Le, lhs, rhs)), BinOp_::BiGt => Some((Rel::Lt, rhs, lhs)), BinOp_::BiGe => Some((Rel::Le, rhs, lhs)), + BinOp_::BiEq => Some((Rel::Eq, rhs, lhs)), + BinOp_::BiNe => Some((Rel::Ne, rhs, lhs)), _ => None, } }