You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[ineffective_bit_mask](https://github.com/Manishearth/rust-clippy/wiki#ineffective_bit_mask) | warn | expressions where a bit mask will be rendered useless by a comparison, e.g. `(x | 1) > 2`
69
69
[inline_always](https://github.com/Manishearth/rust-clippy/wiki#inline_always) | warn | `#[inline(always)]` is a bad idea in most cases
[invalid_upcast_comparisons](https://github.com/Manishearth/rust-clippy/wiki#invalid_upcast_comparisons) | warn | a comparison involving an upcast which is always true or false
71
72
[items_after_statements](https://github.com/Manishearth/rust-clippy/wiki#items_after_statements) | warn | finds blocks where an item comes after a statement
72
73
[iter_next_loop](https://github.com/Manishearth/rust-clippy/wiki#iter_next_loop) | warn | for-looping over `_.next()` which is probably not intended
73
74
[len_without_is_empty](https://github.com/Manishearth/rust-clippy/wiki#len_without_is_empty) | warn | traits and impls that have `.len()` but not `.is_empty()`
@@ -778,3 +777,178 @@ impl LateLintPass for AbsurdExtremeComparisons {
778
777
}
779
778
}
780
779
}
780
+
781
+
/// **What it does:** This lint checks for comparisons where the relation is always either true or false, but where one side has been upcast so that the comparison is necessary. Only integer types are checked.
782
+
///
783
+
/// **Why is this bad?** An expression like `let x : u8 = ...; (x as u32) > 300` will mistakenly imply that it is possible for `x` to be outside the range of `u8`.
784
+
///
785
+
/// **Known problems:** None
786
+
///
787
+
/// **Example:** `let x : u8 = ...; (x as u32) > 300`
788
+
declare_lint!{
789
+
pubINVALID_UPCAST_COMPARISONS,Warn,
790
+
"a comparison involving an upcast which is always true or false"
791
+
}
792
+
793
+
pubstructInvalidUpcastComparisons;
794
+
795
+
implLintPassforInvalidUpcastComparisons{
796
+
fnget_lints(&self) -> LintArray{
797
+
lint_array!(INVALID_UPCAST_COMPARISONS)
798
+
}
799
+
}
800
+
801
+
#[derive(Copy,Clone,Debug,Eq)]
802
+
enumFullInt{
803
+
S(i64),
804
+
U(u64),
805
+
}
806
+
807
+
implFullInt{
808
+
#[allow(cast_sign_loss)]
809
+
fncmp_s_u(s:i64,u:u64) -> Ordering{
810
+
if s < 0{
811
+
Ordering::Less
812
+
}elseif u > (i64::max_value()asu64){
813
+
Ordering::Greater
814
+
}else{
815
+
(s asu64).cmp(&u)
816
+
}
817
+
}
818
+
}
819
+
820
+
implPartialEqforFullInt{
821
+
fneq(&self,other:&Self) -> bool{
822
+
self.partial_cmp(other).expect("partial_cmp only returns Some(_)") == Ordering::Equal
0 commit comments