-
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
Use approx_ty_size
for large_enum_variant
#9400
Conversation
r? @llogiq (rust-highfive has picked a reviewer for you, use r? to override) |
I'm just a bit worried that the lint may become really noisy with this change. Anyone up for running lintcheck against this branch? Otherwise this looks good to go. |
I'm a little worried about noise as well. Consider If this is gtg (please review my question wrt |
Running this on a few thousand crates. I'll post the results tonight. |
Results from roughly the top 5000 crates: https://gist.github.com/Jarcho/57c0e4927769c044b0a56544d429027a Don't know how many of these have generic types. |
Only 42 lints, imho all valid or at least debatable. I'm surprised the number is so low. This PR clearly helps with
Unrelated to this PR:
... which comes from #[enum_dispatch]
pub enum Protocol {
Ascii(AsciiProtocol<Stream>),
Binary(BinaryProtocol),
} |
fe895f6
to
f89e72a
Compare
approx_ty_size
for large_enum_variant
approx_ty_size
for large_enum_variant
Force-pushed a new version, the lint is now
which is better imho. LGTM now, happy for comments. I may get to the |
Even if that number is low, for a warn by default lint we should have quite high standards. I'm not opposed to merging this, but I don't feel comfortable r+ing this alone without further discussion. What do you folks think @rust-lang/clippy ? |
We already warn on non generic enums, right? I think this ought to be fine? |
The old behaviour is to ignore variants with generics correct? That means the false positives are for:
I would think for anyone who cares about this lint, a comment explaining why a certain case isn't a problem is reasonable. For everyone else the lint would be an annoyance even before this PR. |
I have suggested a workable explanation of the possible problems to the lint docs. r=me with this applied. |
f89e72a
to
584000a
Compare
Thank you! @bors r+ |
Use `approx_ty_size` for `large_enum_variant` This builds upon #9373 to use the approximate size of each variant for `large_enum_variant`. This allows us to lint in situations where an `enum` contains generics but is still guaranteed to have a large variant on an at-least basis, e.g. with `(T, [u8; 512])`. * I've changed the wording from "is ... bytes" to "contains at least" because * the size is now an approximate lower bound (e.g. `512` in the example above). The actual size is larger due to `T`, including due to `T`'s memory layout. * the discriminant is not taken into account in the message. This comes up with variants like `A(T)`, which are "is at least 0 bytes" otherwise, which may be misleading. * If the second-largest variant has no fields, there is a special case "carries no data" instead of "is at least 0 bytes". * A variant like `A(T)` is "at least 0 bytes", which is technically true, yet we don't distinguish between "indeterminate" and truly "ZST". * The generics-tests that were there before now lint while they didn't lint before. AFAICS this is correct. I guess the above is correct-ish. However, I use the `SubstsRef` that I got via `cx.tcx.type_of(item.def_id)` to solve for generics in the variants. Is this even applicable, since we start from an `ItemKind`?
💔 Test failed - checks-action_test |
@bors retry |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
@llogiq Thanks for the review |
This builds upon #9373 to use the approximate size of each variant for
large_enum_variant
. This allows us to lint in situations where anenum
contains generics but is still guaranteed to have a large variant on an at-least basis, e.g. with(T, [u8; 512])
.512
in the example above). The actual size is larger due toT
, including due toT
's memory layout.A(T)
, which are "is at least 0 bytes" otherwise, which may be misleading.A(T)
is "at least 0 bytes", which is technically true, yet we don't distinguish between "indeterminate" and truly "ZST".I guess the above is correct-ish. However, I use the
SubstsRef
that I got viacx.tcx.type_of(item.def_id)
to solve for generics in the variants. Is this even applicable, since we start from an - [ ]ItemKind
?changelog: none