fix: impl_generics_with_additional_lifetimes#41
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## trunk #41 +/- ##
==========================================
+ Coverage 39.94% 47.72% +7.77%
==========================================
Files 19 19
Lines 1860 1869 +9
==========================================
+ Hits 743 892 +149
+ Misses 1117 977 -140
... and 5 files with indirect coverage changes Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
VictorKoenders
left a comment
There was a problem hiding this comment.
LGTM, I think the code was like this because it was doing something else before, and this ended up the way it was refactored
Either that or I'm just not smart
Either case this is better!
|
Anything else you want to make a PR of or shall I release 0.0.12 with these changes? |
|
This is no longer adding dependent lifetimes, that are needed at least in my case. The docs have
https://docs.rs/virtue/latest/virtue/generate/struct.Generator.html#method.impl_for_with_lifetimes From my example use, the diff after this change is: -impl < 'de : 'a, 'a > crate :: sshwire :: SSHDecode < 'de > for UserauthPwChangeReq < 'a >
+impl < 'de, 'a > crate :: sshwire :: SSHDecode < 'de > for UserauthPwChangeReq < 'a >(that's for https://github.com/mkj/sunset/blob/c97ff133d51ae482cbb61ae355dafdaa08dd3a34/sshwire-derive/src/lib.rs#L392 targetting struct https://github.com/mkj/sunset/blob/c97ff133d51ae482cbb61ae355dafdaa08dd3a34/src/packets.rs#L164) |
|
I ran into this in bincode as well. I solved it with generator.impl_for_with_lifetimes(format!("{}::BorrowDecode", crate_name), ["__de"])
.modify_generic_constraints(|generics, where_constraints| {
for lt in generics.iter_lifetimes() {
where_constraints.push_parsed_constraint(format!("'__de: '{}", lt.ident))?;
}
Ok(())
})?I'm thinking the new behavior is correct because not everyone will want this behavior, but maybe we can add a helper method that does this? |
|
Thanks, that works for me. I agree it shouldn't be the default. Maybe just adding an example in the |
I'm not entirely sure why this function was originally trying to bound lifetimes, but regardless, what it currently does is very incorrect as it adds copies of every generic for each lifetime passed in.
I don't think any of that is right, so this fixes that, removes the unused helper
as_lifetime, and adds a test to ensure the expected behavior occurs.