-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Is needless_pass_by_value behaving properly? #3031
Comments
Note that warnings for This match alg {
Algorithm::Scalar => foo(o),
Algorithm::Simd => bar(o),
}
let x = alg; // you can still use `alg` Try adding non- |
That might be a philosophical question, but this is how fn drop<T>(_: T) {} Does It does not use it, but that's why it uses an underscore for the argument name. Changing |
Please just add |
@sinkuu that's what I meant with "this lint is not trying to catch ''bugs'' but to make APIs better" but if that's its objective, then it might make sense to make it apply only to public items at least by default (and make the private item version a restriction lint). If this happens in code that you control, and you need to call |
Yeah, that's a nice idea. Sorry for out-of-focus replay, OP I read was at the edition ended with "... Or what am I missing?`" and haven't scroll up since then... |
Don't worries, I was out-of-focus as well. I think the actionable things we could do here are:
No idea of what would be best here, and no idea yet of whether splitting this for pub / private items is worth doing. I'm unconvinced. |
I had a similar problem however slightly different. I have some api types that are just wrappers around a reference, so they are both Copy and 8 bytes. Which means that taking a reference has no other effect than just adding another layer of indirection. This can of course be fixed by adding #[allow(clippy::needless_pass_by_value)] above the functions affected, but that would mean that these functions would not have the benefit of other arguments being checked by the lint. Could it be possible to make the lint only apply to non-copy types? Or split it into several lints, one for non copy types, and maybe another one for arguments which would be smaller if you took them by reference instead of copying them? (Turns out the type wasn't Copy, nevermind) |
The lint documentation says "Taking arguments by reference is more flexible...". I think this is sufficiently clear and Clippy is right to lint the case in the OP. |
This (playground):
errors with
but it appears to me that both errors are incorrect?
o
is consumed in the body, in the calls tofoo
andbar
, andalg
is consumed by thematch
? Or what am I missing?Or is the lint telling me that the intent of
foo
,bar
, andrun
might not be to dropo
andalg
? None of these types isCopy
, so from the API signature, that's pretty much what the intent appears to be to me.Making this change requires you to also change all callers of these functions to pass a reference
&
, or to make the types implementCopy
which would break the use case where the intent is to ensure that they are used once, so these are not very clear cut suggestions either.So what's the intent of this lint ? It doesn't appear to be to catch any bugs, because all possible issues would be compiler errors, and the code has to compile before clippy can be called (typically).
So maybe it is to improve APIs, but then this lint should only apply to
pub
exported items or something, and even then, I am skeptical.The text was updated successfully, but these errors were encountered: