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
## Synopsis
At the moment, `derive_more::Debug` fails to work with `?Sized`
generics:
```rust
#[derive(derive_more::Debug)]
struct UnnamedGenericStructUnsized<T: ?Sized>(T);
```
And generates the following error:
```
error[E0277]: the size for values of type `T` cannot be known at compilation time
--> tests/debug.rs:845:14
|
845 | #[derive(Debug)]
| ^^^^^ doesn't have a size known at compile-time
846 | struct UnnamedGenericStructUnsized<T: ?Sized>(T);
| - this type parameter needs to be `std::marker::Sized`
|
= note: required for the cast from `&T` to `&dyn Debug`
= note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider borrowing the value, since `&&T` can be coerced into `&dyn Debug`
|
845 | #[derive(&Debug)]
| +
help: consider removing the `?Sized` bound to make the type parameter `Sized`
|
846 - struct UnnamedGenericStructUnsized<T: ?Sized>(T);
846 + struct UnnamedGenericStructUnsized<T>(T);
|
```
At the same moment, `std::Debug` works OK:
```rust
#[derive(std::Debug)]
struct UnnamedGenericStructUnsized<T: ?Sized>(T);
```
If we look at its expansion:
```rust
#[automatically_derived]
impl<T: ::core::fmt::Debug + ?Sized> ::core::fmt::Debug for
UnnamedGenericStructUnsized<T> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"UnnamedGenericStructUnsized", &&self.0)
}
}
```
We can see that `std::Debug` always uses fields as `&&self.0`, while we
in our `derive_more::Debug` expansion [use `&self.0`
only](https://github.com/JelteF/derive_more/blob/v1.0.0-beta.3/impl/src/fmt/debug.rs#L80).
## Solution
Simply use double-ref in the expansion, as the error suggests, and
`std::Debug` does.
0 commit comments