Repository: brendanzab/approx (language: rust)

Issue:
[Question] Using a slice of Complex type.
Hi,
I see that you have implemented `assert_relative_eq!` for complex and slices. But somehow, I cannot do a `assert_relative_eq!` on a slice of Complex and I can't find out what is wrong with my code?
This is the output of `cargo run`:

```
  --> src/main.rs:29:5
   |
29 |     assert_relative_eq!(&sh.as_slice().unwrap(), &gt.as_slice().unwrap());
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `[num::Complex<{float}>]` does not have a constant size known at compile-time
   |
   = help: the trait `std::marker::Sized` is not implemented for `[num::Complex<{float}>]`
   = note: required because of the requirements on the impl of `approx::AbsDiffEq` for `&[num::Complex<{float}>]`
   = note: required because it appears within the type `approx::Relative<&&[num::Complex<{float}>]>`
   = note: required by `std::default::Default::default`
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
```

Here is a [gist](https://gist.github.com/czotti/aa59044dfc1c7d85f3358a9d2fd6b400) to reproduce what I'm trying to do.

Thanks for the help.


Discussion / hints:
`assert_relative_eq!` takes a reference internally (like `assert_eq!`). Could you try removing those and posting the type error? ie.

```rust
assert_relative_eq!(sh.as_slice().unwrap(), gt.as_slice().unwrap());
```
I have approximately the same error without the `&`:

```
  --> src/main.rs:29:5
   |
29 |     assert_relative_eq!(sh.as_slice().unwrap(), gt.as_slice().unwrap());
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `[num::Complex<{float}>]` does not have a constant size known at compile-time
   |
   = help: the trait `std::marker::Sized` is not implemented for `[num::Complex<{float}>]`
   = note: required because of the requirements on the impl of `approx::RelativeEq` for `&[num::Complex<{float}>]`
   = note: required by `approx::Relative`
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
```

Fix patch:
diff --git a/src/abs_diff_eq.rs b/src/abs_diff_eq.rs
index bc5dfbb..3eb7bb0 100644
--- a/src/abs_diff_eq.rs
+++ b/src/abs_diff_eq.rs
@@ -87,7 +87,7 @@ impl_signed_abs_diff_eq!(f64, f64::EPSILON);
 // Derived implementations
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-impl<'a, T: AbsDiffEq> AbsDiffEq for &'a T {
+impl<'a, T: AbsDiffEq + ?Sized> AbsDiffEq for &'a T {
     type Epsilon = T::Epsilon;
 
     #[inline]
@@ -101,7 +101,7 @@ impl<'a, T: AbsDiffEq> AbsDiffEq for &'a T {
     }
 }
 
-impl<'a, T: AbsDiffEq> AbsDiffEq for &'a mut T {
+impl<'a, T: AbsDiffEq + ?Sized> AbsDiffEq for &'a mut T {
     type Epsilon = T::Epsilon;
 
     #[inline]
@@ -129,7 +129,7 @@ impl<T: AbsDiffEq + Copy> AbsDiffEq for cell::Cell<T> {
     }
 }
 
-impl<T: AbsDiffEq> AbsDiffEq for cell::RefCell<T> {
+impl<T: AbsDiffEq + ?Sized> AbsDiffEq for cell::RefCell<T> {
     type Epsilon = T::Epsilon;
 
     #[inline]
diff --git a/src/relative_eq.rs b/src/relative_eq.rs
index b4c5927..52b9ea3 100644
--- a/src/relative_eq.rs
+++ b/src/relative_eq.rs
@@ -89,7 +89,7 @@ impl_relative_eq!(f64, i64);
 // Derived implementations
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-impl<'a, T: RelativeEq> RelativeEq for &'a T {
+impl<'a, T: RelativeEq + ?Sized> RelativeEq for &'a T {
     #[inline]
     fn default_max_relative() -> T::Epsilon {
         T::default_max_relative()
@@ -101,7 +101,7 @@ impl<'a, T: RelativeEq> RelativeEq for &'a T {
     }
 }
 
-impl<'a, T: RelativeEq> RelativeEq for &'a mut T {
+impl<'a, T: RelativeEq + ?Sized> RelativeEq for &'a mut T {
     #[inline]
     fn default_max_relative() -> T::Epsilon {
         T::default_max_relative()
@@ -135,7 +135,7 @@ impl<T: RelativeEq + Copy> RelativeEq for cell::Cell<T> {
     }
 }
 
-impl<T: RelativeEq> RelativeEq for cell::RefCell<T> {
+impl<T: RelativeEq + ?Sized> RelativeEq for cell::RefCell<T> {
     #[inline]
     fn default_max_relative() -> T::Epsilon {
         T::default_max_relative()
diff --git a/src/ulps_eq.rs b/src/ulps_eq.rs
index 55eba4d..80efe0e 100644
--- a/src/ulps_eq.rs
+++ b/src/ulps_eq.rs
@@ -66,7 +66,7 @@ impl_ulps_eq!(f64, i64);
 // Derived implementations
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-impl<'a, T: UlpsEq> UlpsEq for &'a T {
+impl<'a, T: UlpsEq + ?Sized> UlpsEq for &'a T {
     #[inline]
     fn default_max_ulps() -> u32 {
         T::default_max_ulps()
@@ -78,7 +78,7 @@ impl<'a, T: UlpsEq> UlpsEq for &'a T {
     }
 }
 
-impl<'a, T: UlpsEq> UlpsEq for &'a mut T {
+impl<'a, T: UlpsEq + ?Sized> UlpsEq for &'a mut T {
     #[inline]
     fn default_max_ulps() -> u32 {
         T::default_max_ulps()
@@ -102,7 +102,7 @@ impl<T: UlpsEq + Copy> UlpsEq for cell::Cell<T> {
     }
 }
 
-impl<T: UlpsEq> UlpsEq for cell::RefCell<T> {
+impl<T: UlpsEq + ?Sized> UlpsEq for cell::RefCell<T> {
     #[inline]
     fn default_max_ulps() -> u32 {
         T::default_max_ulps()


Test patch: