Description
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 thanActualT
.- 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 constraintActualT
withCopy
- 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.
- Potentially, but I couldn't pinpoint where, so I still currently believe that the
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
Labels
No labels