-
Notifications
You must be signed in to change notification settings - Fork 964
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
*: Activate clippy::style
lint group
#2620
Conversation
d8f1d11
to
44d7034
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a fan of clippy myself, happy to move forward with this.
What do you think @mxinden?
protocols/gossipsub/src/behaviour.rs
Outdated
if !self.duplicate_cache.contains(&id) | ||
&& !self.pending_iwant_msgs.contains(&id) | ||
&& self | ||
.peer_score | ||
.as_ref() | ||
.map(|(_, _, _, promises)| !promises.contains(&id)) | ||
.unwrap_or(true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is quite the monster boolean condition now. Perhaps we should extract 3 boolean variables that we can then chain together to make this more readable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For readability, it would make sense, but it would kill the possibility of short-circuiting, which may result in a performance drop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess functions would allow for readability and short-circuiting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, a lambda would do the trick! For the first two conditions I don't think it would help much, i.e. !self.duplicate_cache.contains(&id)
would most likely become duplicate_cache.contains(&id)
. Is it fine for you?
The last one is definitely a monster though and I'd be happy to turn it into a short lambda. Any suggestions on a meaningful name for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably even better would be to do:
impl Gossipsub {
fn want_message(&self, id: ???) -> bool {
if self.duplicate_cache.contains(&id) {
return false;
}
if self.pending_iwant_msgs.contains(&id) {
return false;
}
self.peer_score
.as_ref()
.map(|(_, _, _, promises)| !promises.contains(&id))
.unwrap_or(true)
}
}
Although I think clippy might complain about this one being possible to write as a &&
chain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! I went ahead with similar change. I was a bit confused with a contains
method being mutable for no visible reason so I made them immutable. Maybe pedantic clippy would have caught that before.
big fan of clippy myself, very much in favor of this in general |
f8140ff
to
4a980c2
Compare
4a980c2
to
9d73fcc
Compare
Side-note @LesnyRumcajs : We use squash-merge so please don't force-push :) |
clippy::style
lint group
Sure thing. I was uncertain how it would behave coming from my fork which was a bit outdated so I defaulted to my typical routine. :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one nit pick. Otherwise looks good to me. Thanks for the help!
Description
Enabled clippy style warnings and fixed the corresponding issues. I had to suppress some of them to not break the existing API (we could consider resolving those for a major release).
Links to any relevant issues
#2615
Open Questions
Change checklist