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

"large enum variant" lint should report sizes of variants #5459

Closed
osa1 opened this issue Apr 13, 2020 · 0 comments · Fixed by #5466
Closed

"large enum variant" lint should report sizes of variants #5459

osa1 opened this issue Apr 13, 2020 · 0 comments · Fixed by #5466
Assignees
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages

Comments

@osa1
Copy link
Contributor

osa1 commented Apr 13, 2020

clippy version: clippy 0.0.212 (d342cee 2020-04-07) (installed via rustup)

First of all, this lint seems useful, thanks for adding it.

I recently run this lint on my code base and it reported this warning:

warning: large size difference between variants
  --> libtiny_client/src/stream.rs:35:5
   |
35 |     TlsStream(TlsStream<TcpStream>),
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(clippy::large_enum_variant)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant
help: consider boxing the large fields to reduce the total size of the enum
   |
35 |     TlsStream(Box<TlsStream<TcpStream>>),
   |               ^^^^^^^^^^^^^^^^^^^^^^^^^

The first question I asked when I see this is "OK, but how much is the difference, and what is the sizes of variants currently". I think this information is useful to decide whether to box the variant or not. For example, if one variant is one word and the other is 5, I probably wouldn't refactor this as 5 words is still not large enough for my purposes. But if one is one word and the other is 100 words then this is probably with refactoring.

I checked the link in the warning message, but couldn't see anything about when is a variant considered too different than others.

@phansch phansch self-assigned this Apr 13, 2020
@flip1995 flip1995 added the C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages label Apr 15, 2020
@bors bors closed this as completed in 071a590 Apr 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants