Cleaned implements_ord helper function in boolean lint file.

This commit is contained in:
Bruno Kirschner 2018-06-03 18:46:11 +02:00
parent 80728a2201
commit 28f735bb26
2 changed files with 19 additions and 15 deletions

View file

@ -123,10 +123,9 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
let negated = match e.node { let negated = match e.node {
ExprBinary(binop, ref lhs, ref rhs) => { ExprBinary(binop, ref lhs, ref rhs) => {
match implements_ord(self.cx, lhs) { if !implements_ord(self.cx, lhs) {
Some(true) => (), continue;
_ => continue, }
};
let mk_expr = |op| { let mk_expr = |op| {
Expr { Expr {
@ -181,10 +180,9 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
match expr.node { match expr.node {
ExprBinary(binop, ref lhs, ref rhs) => { ExprBinary(binop, ref lhs, ref rhs) => {
match implements_ord(self.cx, lhs) { if !implements_ord(self.cx, lhs) {
Some(true) => (), return None;
_ => return None, }
};
match binop.node { match binop.node {
BiEq => Some(" != "), BiEq => Some(" != "),
@ -458,12 +456,8 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> {
} }
fn implements_ord<'a, 'tcx>(cx: &'a LateContext<'a, 'tcx>, expr: &Expr) -> Option<bool> { fn implements_ord<'a, 'tcx>(cx: &'a LateContext<'a, 'tcx>, expr: &Expr) -> bool {
let ty = cx.tables.expr_ty(expr); let ty = cx.tables.expr_ty(expr);
get_trait_def_id(cx, &paths::ORD)
return if let Some(id) = get_trait_def_id(cx, &paths::ORD) { .map_or(false, |id| implements_trait(cx, ty, id, &[]))
Some(implements_trait(cx, ty, id, &[]))
} else {
None
};
} }

View file

@ -114,3 +114,13 @@ fn warn_for_built_in_methods_with_negation() {
if !res.is_some() { } if !res.is_some() { }
if !res.is_none() { } if !res.is_none() { }
} }
#[allow(neg_cmp_op_on_partial_ord)]
fn dont_warn_for_negated_partial_ord_comparision() {
let a: f64 = unimplemented!();
let b: f64 = unimplemented!();
let _ = !(a < b);
let _ = !(a <= b);
let _ = !(a > b);
let _ = !(a >= b);
}