Skip to content
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

Remove Copy from BlockHeader #1076

Open
Mirko-von-Leipzig opened this issue Jan 17, 2025 · 1 comment
Open

Remove Copy from BlockHeader #1076

Mirko-von-Leipzig opened this issue Jan 17, 2025 · 1 comment
Labels
good first issue Good for newcomers
Milestone

Comments

@Mirko-von-Leipzig
Copy link
Contributor

Passing BlockHeader by value triggers the clippy::large_types_passed_by_value pedantic lint, because it is both Copy and "large" at 334 bytes.

There is a general rust argument that all types can derive Copy, should. The argument goes that the only real distinction from Clone is whether one can continue to use the sender side after passing by value, and therefore Copy is always good if one can derive it trivially.

Something this argument glosses over though, is that Clone marks places which one can audit for expensive copies. The above lint is supposed to catch such instances - however it suppresses this lint for pub fn to avoid api breaking suggestions. This suppression can be disabled by configuring avoid-breaking-exported-api=false.

We should decide whether to:

  1. Remove Copy from large types, or
  2. Enforce the lint and disable api-breakage suppression, or
  3. Do both (1) and (2)

I'd suggest (3) because I like my lints, and I like seeing where large copies happen. I was originally going to suggest (1) only, but I can actually see the ergonomics behind doing just (2). The biggest downside of (2) being that users of our crates have to also opt-in to the lints to get the "benefits".

@PhilippGackstatter
Copy link
Contributor

Nice finding!

I think we should be notified if a type gets too large so we can reevaluate whether Copy makes sense or not. Since we're not at a 1.X yet, I think we can reserve the right to make changes like remove Copy from large types. Even with a 1.X released, we should at least get notified via the lint and then we can always selectively allow it. At that point we should use something like https://github.com/obi1kenobi/cargo-semver-checks anyway to review changes to the public API between PRs so that breaking the API would be hard to do accidentally.

So, basically I think option 3 sounds good to me.

@bobbinth bobbinth added this to the v0.8 milestone Jan 21, 2025
@bobbinth bobbinth added the good first issue Good for newcomers label Feb 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants