derive_more
derive_more copied to clipboard
Bugfix/double reference
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.0instead oflet _0 = &self.0in case the fieldself.0is already a reference type. -
In body generation, add
&before#identin the callderive_more::core::fmt::#trait_ident::fmt(#ident, __derive_more_f), because the functionfmtdereferences. -
In bounds generation, strip
&in the bounded type for traits other thanPointerbecause thefmtfunction 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
- [ ] Documentation is updated (if required)
- [x] Tests are added/updated (if required)
- [ ] CHANGELOG entry is added (if required)