-
-
Notifications
You must be signed in to change notification settings - Fork 298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding additional lifetime constraints to a trait impl #90
Comments
I would love to make this better. I agree with you that there must be a way. Two things that might help in this case are a way to parse generics from a string: let arg_matches_generics = parse_generics("<'_a, '_b: '_a>").unwrap(); and a way to combine two generics: let generics = arg_matches_generics.merge(ast.generics); But even with both of those, your conceptually simple code would still be tricky to write correctly so I think we can do even better. Let's both keep thinking. |
This is somewhat better in the upcoming 0.12 release. let mut generics = ast.generics.clone();
generics.params.push(parse_quote!('_a));
generics.params.push(parse_quote!('_b: '_a)); |
If In 0.11 and the early days of 0.12, It could still work if So it seems the easiest way is to create a new |
I'd also be open to doing some error correction work in the In general we try not to let well-formed syn syntax trees produce malformed rust syntax when calling ToTokens. |
(0.12.4 has |
About the question of lifetime hygiene, is there a good way to guarantee that the added lifetimes do not conflict with existing ones? I guess I could just go over |
I am going to call this done as of Syn 0.15 and recommend the approach in #90 (comment). Lifetimes now get printed before type parameters even if you push them on the end of the parameter list (fixed in #321). |
I just tried implementing
std::convert::From
for a reference to a struct that has a lifetime parameter in aproc_macro_derive
, it took a while, but I eventually came up with something that "worked"I feel like there must be a better way to do this, maybe some kind of enhanced
split_for_impl
that supports injecting extra lifetimes. (I also just realised this would probably fail if the struct passed in had a'a
or'b
lifetime, I assume there's no hygiene inproc_macro_derive
s at all 😮)The text was updated successfully, but these errors were encountered: