-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
feat(clippy): add needless_pass_by_value
#9197
Conversation
2b67d01
to
3244c90
Compare
primary_tx: &impl DbTx, | ||
secondary_tx: &impl DbTx, |
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'm fine with this for the perf improvement, and imo the flexibility of having impl T
instead of &impl T
is rarely used, may break some public api though, so anywhere we should allow this @mattsse ?
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.
&impl looks very horrible
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 very invasive and I don't want to let clippy decide how function signatures should look like.
I believe there are a few instances where the suggestions are valid, but I'm not a fan of this lint overall
@mattsse Tell me what you want to do, I have the impression that all the suggestions are more or less relevant and there is no false postive I have the impression. From what I saw it removed unnecessary memory allocations due to cloning and made certain implementations more flexible in my opinion. I feel like this is a good guideline to follow for implementations when you're not sure whether to put a reference or a value. On the other hand I noticed that it never altered the functioning of a function and no change other than passing by reference instead of by value was necessary. For the &impl, I agree that it's horrible, if it's only in this place the problem, we can put an allow. I also saw https://rust-lang.github.io/rust-clippy/master/#/needless_pass_by_ref_mut which can be a good addition to this to counterbalance. But if there are too many places where this lint bothers you then it's not worth putting allows everywhere. |
I even wanted to open an issue for fixing this is several places where we copy a 64 byte |
|
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 would rather deal with unnecessary pass by value w.r.t. clones on a case by case basis. While this can be helpful, it is still in the pedantic group of clippy lints. I personally prefer to have more control on APIs, since it sometimes makes sense to use pass by value
My preference would be to not add this lint, and instead only change the signature in places where we do have unnecessary clones or copies. This lint can be used locally anyways to catch these types of issues
pub fn check_and_decrypt(self, keys: &RLPxSymmetricKeys) -> Result<&'a mut [u8], ECIESError> { | ||
self.check_integrity(keys)?; | ||
Ok(self.decrypt(keys)) |
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 would prefer this consume the keys for example
@Rjected I have the impression that if we do it on a case by case basis it will be difficult to maintain and very difficult for us to find the faulty elements, right? Also I would say that if we apply the lint locally, this will slightly destructure our current classification which aims to apply the lints globally by registering them in the root cargo.toml right? |
closing, @tcoratger feel free to recycle some of the code to change signatures in places identified as meaningful to pass by ref, for example
|
Should close #8886