Skip to content

Commit b803f85

Browse files
committed
Cleaned implements_ord helper function in boolean lint file.
1 parent 80728a2 commit b803f85

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

clippy_lints/src/booleans.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,9 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
123123
let negated = match e.node {
124124
ExprBinary(binop, ref lhs, ref rhs) => {
125125

126-
match implements_ord(self.cx, lhs) {
127-
Some(true) => (),
128-
_ => continue,
129-
};
126+
if !implements_ord(self.cx, lhs) {
127+
continue;
128+
}
130129

131130
let mk_expr = |op| {
132131
Expr {
@@ -181,10 +180,9 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
181180
match expr.node {
182181
ExprBinary(binop, ref lhs, ref rhs) => {
183182

184-
match implements_ord(self.cx, lhs) {
185-
Some(true) => (),
186-
_ => return None,
187-
};
183+
if !implements_ord(self.cx, lhs) {
184+
return None;
185+
}
188186

189187
match binop.node {
190188
BiEq => Some(" != "),
@@ -458,12 +456,9 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> {
458456
}
459457

460458

461-
fn implements_ord<'a, 'tcx>(cx: &'a LateContext<'a, 'tcx>, expr: &Expr) -> Option<bool> {
459+
fn implements_ord<'a, 'tcx>(cx: &'a LateContext<'a, 'tcx>, expr: &Expr) -> bool {
462460
let ty = cx.tables.expr_ty(expr);
463-
464-
return if let Some(id) = get_trait_def_id(cx, &paths::ORD) {
465-
Some(implements_trait(cx, ty, id, &[]))
466-
} else {
467-
None
468-
};
461+
get_trait_def_id(cx, &paths::ORD)
462+
.map(|id| implements_trait(cx, ty, id, &[]))
463+
.unwrap_or(false)
469464
}

tests/ui/booleans.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,13 @@ fn warn_for_built_in_methods_with_negation() {
114114
if !res.is_some() { }
115115
if !res.is_none() { }
116116
}
117+
118+
#[allow(neg_cmp_op_on_partial_ord)]
119+
fn dont_warn_for_negated_partial_ord_comparision() {
120+
let a: f64 = unimplemented!();
121+
let b: f64 = unimplemented!();
122+
let _ = !(a < b);
123+
let _ = !(a <= b);
124+
let _ = !(a > b);
125+
let _ = !(a >= b);
126+
}

0 commit comments

Comments
 (0)