Skip to content

Limitations of the Matcher Trait with Proxy reference type #323

Closed
@bjacotg

Description

@bjacotg

See this playground for a minimal example.

While implementing matchers for the Rust protobuf library, I stumbled on an issue with the lifetime requirement of the Matcher trait. The lifetime issue still did not click right in my head, so forgive me if what I say is not exactly what is happening. But, as far as I currently understand it, the Matcher trait accepts &ActualT with any lifetime even though ActualT may be bounded, which makes the impl Matcher not able to access most functions of ActualT.

I see a few options to solve this issue:

  • Add a lifetime requirement on &ActualT to have a lifetime smaller than ActualT.
    • Not sure if this will work. In my current set up with the protobuf, I managed to get it work, but of course all the other matchers do not work and will need to be updated.
  • Accept ActualT and not &ActualT in matcher, and constraint ActualT with Copy
    • Not sure if this will work either. Same as above, it fixes the current issue, but it may break other use cases.
  • Do not support this pattern. Or the library is buggy
    • Potentially, but I couldn't pinpoint where, so I still currently believe that the Matcher trait is just not right.

This reminds me of the issue we currently have with property!() and string slices as it was also a reference lifetime issue.

I will add more details while debugging further.

Current leads:

  • Adding the lifetime bound on the Matcher trait and see where it takes us
  • Constraining on Copy and see where it takes us
  • Changing the return lifetime of get_a_field() in the example from '_ to 'a seems to work, so maybe there is an issue in the library

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions