-
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
large_enum_variants lint suggests to box variants above a configurable limit #1492
Conversation
4cf08ab
to
82dd50d
Compare
//! lint when there are large variants on an enum | ||
|
||
use rustc::lint::*; | ||
use rustc::hir::*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, fortunately you did not promise 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in my defense, I only rebased this code ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use rustc::ty::TypeFoldable; | ||
use rustc::traits::Reveal; | ||
|
||
/// **What it does:** Checks for large variants on enums. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer “enumeration” or “enum
s”.
LARGE_ENUM_VARIANT, | ||
def.variants[i].span, | ||
&format!("large enum variant found on variant `{}`", variant.name), | ||
"consider boxing the large branches to reduce the total size of the enum"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Make a suggestion if there is only one field?
- s/branch/field
} | ||
|
||
enum LargeEnumGeneric<A: SomeTrait> { | ||
Var(A::Item), // regression test, this used to ICE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You add regression tests even before the PR is merged? 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got tired of fixing multiple commits during rebasing and simply merged them into one
Needs to be documented at https://github.com/Manishearth/rust-clippy/wiki#large_enum_variant |
Also, this lint warns on all variants that exceed 200 bytes in size, as opposed to if the difference between the smallest and largest variant exceeds 200 bytes. Is that intentional? The latter seems to make more sense to me. Edit: From
Edit: This was fixed in https://github.com/Manishearth/rust-clippy/pull/1512 |
Updated the wiki. |
fixes #1127
obsoletes #1187