Repository: rust-pretty-assertions/rust-pretty-assertions (Rust)

Issue:
Unsized values
```rust
let a: &[u8] = b"1";
assert_eq!(*a, *a);
pretty_assertions::assert_eq!(*a, *a);
```
Regular assertions work with unsized values, but pretty_assertions give an error:
The following code gives an error:
```
4  |     pretty_assertions::assert_eq!(*a, *a);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
```



Discussion:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 62d3a82..8759bcf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
 # Unreleased
 
+## Added
+
+- Support for unsized values (#42, @stanislav-tkach)
+
 ## Internal
 
 - Test Windows targets in CI (#46, @tommilligan)
diff --git a/src/lib.rs b/src/lib.rs
index 2f1b3a2..402e8be 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -93,9 +93,12 @@ fn init() {
 pub struct Comparison(Changeset);
 
 impl Comparison {
-    pub fn new<TLeft: Debug, TRight: Debug>(left: &TLeft, right: &TRight) -> Comparison {
-        let left_dbg = format!("{:#?}", *left);
-        let right_dbg = format!("{:#?}", *right);
+    pub fn new<TLeft: Debug + ?Sized, TRight: Debug + ?Sized>(
+        left: &TLeft,
+        right: &TRight,
+    ) -> Comparison {
+        let left_dbg = format!("{:#?}", &*left);
+        let right_dbg = format!("{:#?}", &*right);
         let changeset = Changeset::new(&left_dbg, &right_dbg, "\n");
 
         Comparison(changeset)
@@ -157,8 +160,8 @@ macro_rules! assert_ne {
         match (&($left), &($right)) {
             (left_val, right_val) => {
                 if *left_val == *right_val {
-                  let left_dbg = format!("{:?}", *left_val);
-                  let right_dbg = format!("{:?}", *right_val);
+                  let left_dbg = format!("{:?}", &*left_val);
+                  let right_dbg = format!("{:?}", &*right_val);
                   if left_dbg != right_dbg {
 
                       panic!("assertion failed: `(left != right)`{}{}\


Test patch:
diff --git a/tests/assert_eq.rs b/tests/assert_eq.rs
index cadab93..5541dd1 100644
--- a/tests/assert_eq.rs
+++ b/tests/assert_eq.rs
@@ -1,3 +1,5 @@
+#![allow(clippy::eq_op)]
+
 #[allow(unused_imports)]
 use pretty_assertions::{assert_eq, assert_ne};
 extern crate difference;
@@ -193,3 +195,25 @@ fn assert_eq_custom_trailing_comma() {
 
     assert_eq!(x, y, "custom panic message",);
 }
+
+#[test]
+fn assert_eq_unsized() {
+    let a: &[u8] = b"e";
+    assert_eq!(*a, *a);
+}
+
+#[test]
+#[should_panic(expected = r#"assertion failed: `(left == right)`
+
+[1mDiff[0m [31m< left[0m / [32mright >[0m :
+ [
+     101,
+[32m>    101,
+[0m ]
+
+"#)]
+fn assert_eq_unsized_panic() {
+    let a: &[u8] = b"e";
+    let b: &[u8] = b"ee";
+    assert_eq!(*a, *b);
+}
diff --git a/tests/assert_ne.rs b/tests/assert_ne.rs
index b5d7b08..5760e94 100644
--- a/tests/assert_ne.rs
+++ b/tests/assert_ne.rs
@@ -174,3 +174,24 @@ fn assert_ne_custom_trailing_comma() {
 
     assert_ne!(x, x, "custom panic message",);
 }
+
+#[test]
+fn assert_ne_unsized() {
+    let a: &[u8] = b"e";
+    let b: &[u8] = b"ee";
+    assert_ne!(*a, *b);
+}
+
+#[test]
+#[should_panic(expected = r#"assertion failed: `(left != right)`
+
+[1mBoth sides[0m:
+[
+    101,
+]
+
+"#)]
+fn assert_ne_unsized_panic() {
+    let a: &[u8] = b"e";
+    assert_ne!(*a, *a);
+}