-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New lint: Pass references when possible for large data types? #4499
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
Comments
As stated here, we already have the opposite lint rust-lang/rust#52274 (comment). The code there should be reusable. Also there was recently a blog post in TWIR or on reddit benchmarking this for small types: https://www.forrestthewoods.com/blog/should-small-rust-structs-be-passed-by-copy-or-by-borrow/ Maybe @forrestthewoods wants to do the same for huge types, so that we get a good default configuration for this lint? 😄 |
I think I'll give this one a go. I'm just now studying the codebase, and will probably need some pointers. What should be the criteria for this? How to tell if a type is large enough? Just not being Copy is not enough, surely. Maybe something like what's on large_enum_variant? |
I think that would be a safe default. The value should be configurable, though. Also, given the destiny of the opposite lint (#5410), I would make this lint pedantic. |
If someone is willing to help a newbie, I'm having trouble getting my lint to actually run. I've generated it with I'm running it with What am I missing? |
@cauebs I think you may be missing registering your new pass here: rust-clippy/clippy_lints/src/lib.rs Line 1130 in 9408c68
A previous comment suggested that code from |
Would it be more appropriate to implement both in the same struct, or separately, just sharing some code from floating functions? edit: figured it out myself. It seems fine to just merge both in the same struct. PR submitted below, any feedback is welcome ;) |
As discussed here, it is often more efficient to pass arguments by reference instead of value.
However, current compiler does not optimize such (and there seems to be good reason for that).
Therefore, it would be appropriate to warn user on such cases.
The text was updated successfully, but these errors were encountered: