@@ -697,7 +697,6 @@ impl LateLintPass for VariantSizeDifferences {
697
697
fn check_item ( & mut self , cx : & LateContext , it : & hir:: Item ) {
698
698
if let hir:: ItemEnum ( ref enum_definition, ref gens) = it. node {
699
699
if gens. ty_params . is_empty ( ) { // sizes only make sense for non-generic types
700
- let mut sizes = vec ! [ ] ;
701
700
let t = cx. tcx . node_id_to_type ( it. id ) ;
702
701
let layout = cx. tcx . normalizing_infer_ctxt ( ProjectionMode :: Any ) . enter ( |infcx| {
703
702
t. layout ( & infcx) . unwrap_or_else ( |e| {
@@ -710,26 +709,28 @@ impl LateLintPass for VariantSizeDifferences {
710
709
711
710
debug ! ( "enum `{}` is {} bytes large" , t, size. bytes( ) ) ;
712
711
713
- for ( variant, variant_layout) in enum_definition. variants . iter ( ) . zip ( variants) {
714
- // Subtract the size of the enum discriminant
715
- let bytes = variant_layout. min_size ( ) . bytes ( ) . saturating_sub ( discr_size) ;
716
- sizes. push ( bytes) ;
717
-
718
- debug ! ( "- variant `{}` is {} bytes large" , variant. node. name, bytes) ;
719
- }
720
-
721
- let ( largest, slargest, largest_index) = sizes. iter ( )
722
- . enumerate ( )
723
- . fold ( ( 0 , 0 , 0 ) ,
724
- |( l, s, li) , ( idx, & size) |
725
- if size > l {
726
- ( size, l, idx)
727
- } else if size > s {
728
- ( l, size, li)
729
- } else {
730
- ( l, s, li)
731
- }
732
- ) ;
712
+ let ( largest, slargest, largest_index) = enum_definition. variants
713
+ . iter ( )
714
+ . zip ( variants)
715
+ . map ( |( variant, variant_layout) | {
716
+ // Subtract the size of the enum discriminant
717
+ let bytes = variant_layout. min_size ( ) . bytes ( )
718
+ . saturating_sub ( discr_size) ;
719
+
720
+ debug ! ( "- variant `{}` is {} bytes large" , variant. node. name, bytes) ;
721
+ bytes
722
+ } )
723
+ . enumerate ( )
724
+ . fold ( ( 0 , 0 , 0 ) ,
725
+ |( l, s, li) , ( idx, size) |
726
+ if size > l {
727
+ ( size, l, idx)
728
+ } else if size > s {
729
+ ( l, size, li)
730
+ } else {
731
+ ( l, s, li)
732
+ }
733
+ ) ;
733
734
734
735
// we only warn if the largest variant is at least thrice as large as
735
736
// the second-largest.
0 commit comments