Auto merge of #7677 - surechen:edit_large_enum_variant, r=camsteffen

fix bug for large_enum_variants

Fix the discussion problem in the issue of https://github.com/rust-lang/rust-clippy/issues/7666#issuecomment-919654291

About the false positive problem of case:
```rust
enum LargeEnum6 {
    A,
    B([u8;255]),
    C([u8;200]),
}
```

changelog: Fix largest_enum_variant wrongly identifying the second largest variant.
This commit is contained in:
bors 2021-09-30 12:45:17 +00:00
commit a893eb993b
3 changed files with 171 additions and 71 deletions

View file

@ -35,6 +35,7 @@ enum LargeEnum2 {
VariantOk(i32, u32),
ContainingLargeEnum(LargeEnum),
}
enum LargeEnum3 {
ContainingMoreThanOneField(i32, [i32; 8000], [i32; 9500]),
VoidVariant,
@ -56,6 +57,23 @@ enum LargeEnumOk {
LargeB([i32; 8001]),
}
enum LargeEnum6 {
A,
B([u8; 255]),
C([u8; 200]),
}
enum LargeEnum7 {
A,
B([u8; 1255]),
C([u8; 200]),
}
enum LargeEnum8 {
VariantOk(i32, u32),
ContainingMoreThanOneField([i32; 8000], [i32; 2], [i32; 9500], [i32; 30]),
}
fn main() {
large_enum_variant!();
}

View file

@ -32,30 +32,45 @@ LL | ContainingLargeEnum(Box<LargeEnum>),
| ~~~~~~~~~~~~~~
error: large size difference between variants
--> $DIR/large_enum_variant.rs:46:5
--> $DIR/large_enum_variant.rs:40:5
|
LL | ContainingMoreThanOneField(i32, [i32; 8000], [i32; 9500]),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this variant is 70004 bytes
|
note: and the second-largest variant is 8 bytes:
--> $DIR/large_enum_variant.rs:42:5
|
LL | StructLikeLittle { x: i32, y: i32 },
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: consider boxing the large fields to reduce the total size of the enum
|
LL | ContainingMoreThanOneField(i32, Box<[i32; 8000]>, Box<[i32; 9500]>),
| ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~
error: large size difference between variants
--> $DIR/large_enum_variant.rs:47:5
|
LL | StructLikeLarge { x: [i32; 8000], y: i32 },
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this variant is 32004 bytes
|
note: and the second-largest variant is 8 bytes:
--> $DIR/large_enum_variant.rs:45:5
--> $DIR/large_enum_variant.rs:46:5
|
LL | VariantOk(i32, u32),
| ^^^^^^^^^^^^^^^^^^^
help: consider boxing the large fields to reduce the total size of the enum
--> $DIR/large_enum_variant.rs:46:5
|
LL | StructLikeLarge { x: [i32; 8000], y: i32 },
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | StructLikeLarge { x: Box<[i32; 8000]>, y: i32 },
| ~~~~~~~~~~~~~~~~
error: large size difference between variants
--> $DIR/large_enum_variant.rs:51:5
--> $DIR/large_enum_variant.rs:52:5
|
LL | StructLikeLarge2 { x: [i32; 8000] },
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this variant is 32000 bytes
|
note: and the second-largest variant is 8 bytes:
--> $DIR/large_enum_variant.rs:50:5
--> $DIR/large_enum_variant.rs:51:5
|
LL | VariantOk(i32, u32),
| ^^^^^^^^^^^^^^^^^^^
@ -64,5 +79,37 @@ help: consider boxing the large fields to reduce the total size of the enum
LL | StructLikeLarge2 { x: Box<[i32; 8000]> },
| ~~~~~~~~~~~~~~~~
error: aborting due to 4 previous errors
error: large size difference between variants
--> $DIR/large_enum_variant.rs:68:5
|
LL | B([u8; 1255]),
| ^^^^^^^^^^^^^ this variant is 1255 bytes
|
note: and the second-largest variant is 200 bytes:
--> $DIR/large_enum_variant.rs:69:5
|
LL | C([u8; 200]),
| ^^^^^^^^^^^^
help: consider boxing the large fields to reduce the total size of the enum
|
LL | B(Box<[u8; 1255]>),
| ~~~~~~~~~~~~~~~
error: large size difference between variants
--> $DIR/large_enum_variant.rs:74:5
|
LL | ContainingMoreThanOneField([i32; 8000], [i32; 2], [i32; 9500], [i32; 30]),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this variant is 70128 bytes
|
note: and the second-largest variant is 8 bytes:
--> $DIR/large_enum_variant.rs:73:5
|
LL | VariantOk(i32, u32),
| ^^^^^^^^^^^^^^^^^^^
help: consider boxing the large fields to reduce the total size of the enum
|
LL | ContainingMoreThanOneField(Box<[i32; 8000]>, [i32; 2], Box<[i32; 9500]>, [i32; 30]),
| ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~
error: aborting due to 7 previous errors