mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-03 18:43:38 +00:00
Allows neg_cmp_op_on_partial_ord for external macros (fixes #2856).
The macro always negates the result of the given comparison in its internal check which automatically triggered the lint. As its an external macro there was no chance to do anything about it which lead to a white listing of all external macros to prevent further issues.
This commit is contained in:
parent
e4d31ab86c
commit
fedd3ef711
@ -1,7 +1,7 @@
|
||||
use rustc::hir::*;
|
||||
use rustc::lint::*;
|
||||
|
||||
use crate::utils::{self, paths};
|
||||
use crate::utils::{self, paths, span_lint, in_external_macro};
|
||||
|
||||
/// **What it does:**
|
||||
/// Checks for the usage of negated comparision operators on types which only implement
|
||||
@ -53,6 +53,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NoNegCompOpForPartialOrd {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
if_chain! {
|
||||
|
||||
if !in_external_macro(cx, expr.span);
|
||||
if let Expr_::ExprUnary(UnOp::UnNot, ref inner) = expr.node;
|
||||
if let Expr_::ExprBinary(ref op, ref left, _) = inner.node;
|
||||
if let BinOp_::BiLe | BinOp_::BiGe | BinOp_::BiLt | BinOp_::BiGt = op.node;
|
||||
@ -78,7 +79,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NoNegCompOpForPartialOrd {
|
||||
};
|
||||
|
||||
if implements_partial_ord && !implements_ord {
|
||||
cx.span_lint(
|
||||
span_lint(
|
||||
cx,
|
||||
NEG_CMP_OP_ON_PARTIAL_ORD,
|
||||
expr.span,
|
||||
"The use of negated comparision operators on partially orded \
|
||||
|
@ -1,6 +1,6 @@
|
||||
/// This test case utilizes `f64` an easy example for `PartialOrd` only types
|
||||
/// but the lint itself actually validates any expression where the left
|
||||
/// operand implements `PartialOrd` but not `Ord`.
|
||||
//! This test case utilizes `f64` an easy example for `PartialOrd` only types
|
||||
//! but the lint itself actually validates any expression where the left
|
||||
//! operand implements `PartialOrd` but not `Ord`.
|
||||
|
||||
use std::cmp::Ordering;
|
||||
|
||||
@ -54,5 +54,14 @@ fn main() {
|
||||
let _ = a_value <= another_value;
|
||||
let _ = a_value > another_value;
|
||||
let _ = a_value >= another_value;
|
||||
}
|
||||
|
||||
// --- regression tests ---
|
||||
|
||||
// Issue 2856: False positive on assert!()
|
||||
//
|
||||
// The macro always negates the result of the given comparision in its
|
||||
// internal check which automatically triggered the lint. As it's an
|
||||
// external macro there was no chance to do anything about it which lead
|
||||
// to a whitelisting of all external macros.
|
||||
assert!(a_value < another_value);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user