CI: use latest nightly, refactor derive trait bounds#56
Conversation
|
I think Clippy is wrong-ish here, or rather I remember trying to sort out those warnings and failing to come up with something better. |
I think it was on to something |
Oh maybe not now I have made it happy but broken the implementation - now I remember |
Just for my own entertainment I made a refactoring that satisfied clippy. Let me know what you think @dvdplm, and whether you think it is any better. |
derive/src/lib.rs
Outdated
| .for_each(|l| *l = parse_quote!('static)); | ||
|
|
||
| let (_, ty_generics, where_clause) = ast.generics.split_for_impl(); | ||
| let (ty_generics, where_clause) = trait_bounds::add(ident, &ast.generics, &ast.data)?; |
There was a problem hiding this comment.
This is where it looks a bit odd, we call add() and get back more stuff than I'd expect just from reading the method name and arguments. It's fine, better than before even, but just looks a bit odd.
I wonder what this would look like if we just went against orthodoxy and in-lined the whole trait_bounds::add function here directly. It would be long, yes, but perhaps more straight forward to read at the end of the day?
There was a problem hiding this comment.
Yes it does look odd now I have a fresh look. I have pushed some further refactoring to hopefully make it a bit more understandable.
derive/src/trait_bounds.rs
Outdated
| data: &'a syn::Data, | ||
| ) -> Result<(TypeGenerics<'a>, WhereClause)> { | ||
| let (_, ty_generics, where_clause) = generics.split_for_impl(); | ||
| let mut where_clause = where_clause.cloned().unwrap_or_else(|| { |
There was a problem hiding this comment.
I don't remember exactly what the problem was but I think I had something similar. I found no way around having to clone things either.
There was a problem hiding this comment.
The main thing was not using the built in generics.make_where_clause() which requires &mut self, and just copying what it does without requiring an exclusive reference.
| let (_, ty_generics, _) = ast.generics.split_for_impl(); | ||
| let where_clause = trait_bounds::make_where_clause(ident, &ast.generics, &ast.data)?; |
derive/trait_boundsin order to make clippy happy 📎