1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#![allow(clippy::eq_op)]
#[cfg(feature = "use_core")]
extern crate core;
#[macro_use]
extern crate derivative;
#[derive(Derivative, PartialEq)]
#[derivative(Eq)]
#[repr(C, packed)]
struct Foo {
foo: u8
}
#[derive(Derivative)]
#[derivative(Eq)]
#[repr(C, packed)]
struct WithPtr<T: ?Sized> {
#[derivative(Eq(bound=""))]
foo: *const T
}
impl<T: ?Sized> PartialEq for WithPtr<T> {
fn eq(&self, other: &Self) -> bool {
self.foo == other.foo
}
}
#[derive(Derivative)]
#[derivative(PartialEq, Eq)]
#[repr(C, packed)]
struct Generic<T>(T);
trait SomeTrait {}
#[derive(Clone, Copy, PartialEq, Eq)]
struct SomeType {
#[allow(dead_code)]
foo: u8
}
impl SomeTrait for SomeType {}
fn assert_eq<T: Eq>(_: T) {}
#[test]
fn main() {
assert!(Foo { foo: 7 } == Foo { foo: 7 });
assert!(Foo { foo: 7 } != Foo { foo: 42 });
assert_eq(Foo { foo: 7 });
let ptr1: *const dyn SomeTrait = &SomeType { foo: 0 };
let ptr2: *const dyn SomeTrait = &SomeType { foo: 1 };
assert!(WithPtr { foo: ptr1 } == WithPtr { foo: ptr1 });
assert!(WithPtr { foo: ptr1 } != WithPtr { foo: ptr2 });
assert_eq(WithPtr { foo: ptr1 });
assert!(Generic(SomeType { foo: 0 }) == Generic(SomeType { foo: 0 }));
assert_eq(Generic(SomeType { foo: 0 }));
}
|