Closed yfcai closed 5 months ago
The approach in this PR does not handle non-reference types that implement Pointer.
Another approach is defining a newtype for bindings _0
, _1
etc that transparently delegate Pointer
and other Display
traits to the underlying type. While implementing Deref
makes the newtype a transparent reference for method and function calls, it does not work for operators including user implementations of traits in std::ops
.
In conclusion, the approach in #328 is better.
Resolves #328
Part of #328
Synopsis
This is an alternative solution to the double reference problem reported in #328.
Solution
Instead of dereferencing macro-generated bindings such as
_0
at the use sites, do the the following:In binding generation, generate
let _0 = self.0
instead oflet _0 = &self.0
in case the fieldself.0
is already a reference type.In body generation, add
&
before#ident
in the callderive_more::core::fmt::#trait_ident::fmt(#ident, __derive_more_f)
, because the functionfmt
dereferences.In bounds generation, strip
&
in the bounded type for traits other thanPointer
because thefmt
function of those traits dereferences exhaustively.Open questions
All previous test function names are
assert
. The tests added in this PR have distinct names so that they can be executed alone viacargo test <substring-of-test-function-name>
. Is there a reason for the naming conventionassert
? If so I'd rename the new tests.Are the improvements to tests in #328 important? I can incorporate them if needed.
Are there any breaking changes? I'm not 100% sure.
Checklist