derive_more icon indicating copy to clipboard operation
derive_more copied to clipboard

Bugfix/double reference

Open yfcai opened this issue 1 year ago • 0 comments
trafficstars

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:

  1. In binding generation, generate let _0 = self.0 instead of let _0 = &self.0 in case the field self.0 is already a reference type.

  2. In body generation, add & before #ident in the call derive_more::core::fmt::#trait_ident::fmt(#ident, __derive_more_f), because the function fmt dereferences.

  3. In bounds generation, strip & in the bounded type for traits other than Pointer because the fmt function of those traits dereferences exhaustively.

Open questions

  1. All previous test function names are assert. The tests added in this PR have distinct names so that they can be executed alone via cargo test <substring-of-test-function-name>. Is there a reason for the naming convention assert? If so I'd rename the new tests.

  2. Are the improvements to tests in #328 important? I can incorporate them if needed.

  3. 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)

yfcai avatar May 08 '24 10:05 yfcai