Skip to content

Commit

Permalink
Don't use double ref vars in Debug derive (#380, #289, #382)
Browse files Browse the repository at this point in the history
## Synopsis

While looking into #328 I realized the current situation around Pointer
derives
and references was even weirder because we store a double-reference to
the
fields in the local variables for Debug, but not for Display. The reason
we
were doing this was because of #289.


## Solution

This stops storing a double-reference, and only adds the additional
reference
in the places where its needed.
  • Loading branch information
JelteF committed Jul 4, 2024
1 parent c165945 commit 974824a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions impl/src/fmt/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fn expand_struct(
.ident
.clone()
.map_or_else(|| syn::Member::Unnamed(i.into()), syn::Member::Named);
quote! { let #var = &&self.#member; }
quote! { let #var = &self.#member; }
});

let body = quote! {
Expand Down Expand Up @@ -275,7 +275,7 @@ impl<'a> Expansion<'a> {
None => {
let ident = format_ident!("_{i}");
Ok(quote! {
derive_more::__private::DebugTuple::field(#out, #ident)
derive_more::__private::DebugTuple::field(#out, &#ident)
})
}
},
Expand Down Expand Up @@ -316,7 +316,7 @@ impl<'a> Expansion<'a> {
)
}),
None => Ok(quote! {
derive_more::core::fmt::DebugStruct::field(#out, #field_str, #field_ident)
derive_more::core::fmt::DebugStruct::field(#out, #field_str, &#field_ident)
}),
}
})?;
Expand Down

0 comments on commit 974824a

Please sign in to comment.