rust-clippy/clippy_tests/examples/should_assert_eq.rs

33 lines
661 B
Rust
Raw Normal View History

#![feature(plugin)]
#![plugin(clippy)]
#![allow(needless_pass_by_value)]
#![warn(should_assert_eq)]
#[derive(PartialEq, Eq)]
struct NonDebug(i32);
#[derive(Debug, PartialEq, Eq)]
struct Debug(i32);
fn main() {
assert!(1 == 2);
assert!(Debug(1) == Debug(2));
assert!(NonDebug(1) == NonDebug(1)); // ok
assert!(Debug(1) != Debug(2));
assert!(NonDebug(1) != NonDebug(2)); // ok
2017-02-17 10:59:52 +00:00
test_generic(1, 2, 3, 4);
2017-05-15 20:49:20 +00:00
debug_assert!(4 == 5);
debug_assert!(4 != 6);
2017-02-17 10:59:52 +00:00
}
fn test_generic<T: std::fmt::Debug + Eq, U: Eq>(x: T, y: T, z: U, w: U) {
assert!(x == y);
assert!(z == w); // ok
assert!(x != y);
assert!(z != w); // ok
}