Skip to content

CI: use latest nightly, refactor derive trait bounds#56

Merged
ascjones merged 8 commits intomasterfrom
aj-use-latest-nightly
Jan 28, 2021
Merged

CI: use latest nightly, refactor derive trait bounds#56
ascjones merged 8 commits intomasterfrom
aj-use-latest-nightly

Conversation

@ascjones
Copy link
Contributor

@ascjones ascjones commented Jan 27, 2021

  • uses latest nightly with the required components
  • includes a refactoring of derive/trait_bounds in order to make clippy happy 📎

@dvdplm
Copy link
Contributor

dvdplm commented Jan 27, 2021

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.

@ascjones
Copy link
Contributor Author

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

@ascjones
Copy link
Contributor Author

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

@ascjones
Copy link
Contributor Author

ascjones commented Jan 27, 2021

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.

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.

.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)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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(|| {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

@ascjones ascjones Jan 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ascjones ascjones changed the title CI: use latest nightly CI: use latest nightly, refactor derive trait bounds Jan 27, 2021
Comment on lines +78 to +79
let (_, ty_generics, _) = ast.generics.split_for_impl();
let where_clause = trait_bounds::make_where_clause(ident, &ast.generics, &ast.data)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I like it.

@ascjones ascjones merged commit 31b9f34 into master Jan 28, 2021
@ascjones ascjones deleted the aj-use-latest-nightly branch January 28, 2021 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants