parent
cb861a1bd1
commit
0b10a41ef3
@ -825,6 +825,12 @@ fn detect_absurd_comparison<'a>(
|
||||
use types::AbsurdComparisonResult::*;
|
||||
use utils::comparisons::*;
|
||||
|
||||
// absurd comparison only makes sense on primitive types
|
||||
// primitive types don't implement comparison operators with each other
|
||||
if cx.tcx.tables().expr_ty(lhs) != cx.tcx.tables().expr_ty(rhs) {
|
||||
return None;
|
||||
}
|
||||
|
||||
let normalized = normalize_comparison(op, lhs, rhs);
|
||||
let (rel, normalized_lhs, normalized_rhs) = if let Some(val) = normalized {
|
||||
val
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#![deny(absurd_extreme_comparisons)]
|
||||
#![allow(unused, eq_op, no_effect, unnecessary_operation)]
|
||||
|
||||
fn main() {
|
||||
const Z: u32 = 0;
|
||||
|
||||
@ -70,3 +71,23 @@ fn main() {
|
||||
// this is handled by unit_cmp
|
||||
() < {}; //~WARNING <-comparison of unit values detected.
|
||||
}
|
||||
|
||||
use std::cmp::{Ordering, PartialEq, PartialOrd};
|
||||
|
||||
#[derive(PartialEq, PartialOrd)]
|
||||
pub struct U(u64);
|
||||
|
||||
impl PartialEq<u32> for U {
|
||||
fn eq(&self, other: &u32) -> bool {
|
||||
self.eq(&U(*other as u64))
|
||||
}
|
||||
}
|
||||
impl PartialOrd<u32> for U {
|
||||
fn partial_cmp(&self, other: &u32) -> Option<Ordering> {
|
||||
self.partial_cmp(&U(*other as u64))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn foo(val: U) -> bool {
|
||||
val > std::u32::MAX
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user