@@ -64,35 +64,42 @@ impl<'tcx> LateLintPass<'tcx> for TrailingZeroSizedArrayWithoutReprC {
6464}
6565
6666fn is_struct_with_trailing_zero_sized_array ( cx : & LateContext < ' tcx > , item : & ' tcx Item < ' tcx > ) -> bool {
67- if_chain ! {
68- // First check if last field is an array
69- if let ItemKind :: Struct ( data , _) = & item . kind ;
70- if let VariantData :: Struct ( field_defs , _ ) = data ;
71- if let Some ( last_field ) = field_defs . last ( ) ;
72- if let rustc_hir :: TyKind :: Array ( _ , length ) = last_field . ty . kind ;
67+ // First check if last field is an array
68+ if let ItemKind :: Struct ( data , _ ) = & item . kind {
69+ if let VariantData :: Struct ( field_defs , _) = data {
70+ if let Some ( last_field ) = field_defs . last ( ) {
71+ if let rustc_hir :: TyKind :: Array ( _ , length ) = last_field . ty . kind {
72+ // Then check if that that array zero-sized
7373
74- // Then check if that that array zero-sized
74+ // This is pretty much copied from `enum_clike.rs` and I don't fully understand it, so let me know
75+ // if there's a better way. I tried `Const::from_anon_const` but it didn't fold in the values
76+ // on the `ZeroSizedWithConst` and `ZeroSizedWithConstFunction` tests.
7577
76- // This is pretty much copied from `enum_clike.rs` and I don't fully understand it, so let me know
77- // if there's a better way. I tried `Const::from_anon_const` but it didn't fold in the values
78- // on the `ZeroSizedWithConst` and `ZeroSizedWithConstFunction` tests.
79-
80- // This line in particular seems convoluted.
81- let length_did = cx. tcx. hir( ) . body_owner_def_id( length. body) . to_def_id( ) ;
82- let length_ty = cx. tcx. type_of( length_did) ;
83- let length = cx
84- . tcx
85- . const_eval_poly( length_did)
86- . ok( )
87- . map( |val| Const :: from_value( cx. tcx, val, length_ty) )
88- . and_then( miri_to_const) ;
89- if let Some ( Constant :: Int ( length) ) = length;
90- if length == 0 ;
91- then {
92- true
78+ // This line in particular seems convoluted.
79+ let length_did = cx. tcx . hir ( ) . body_owner_def_id ( length. body ) . to_def_id ( ) ;
80+ let length_ty = cx. tcx . type_of ( length_did) ;
81+ let length = cx
82+ . tcx
83+ . const_eval_poly ( length_did)
84+ . ok ( )
85+ . map ( |val| Const :: from_value ( cx. tcx , val, length_ty) )
86+ . and_then ( miri_to_const) ;
87+ if let Some ( Constant :: Int ( length) ) = length {
88+ length == 0
89+ } else {
90+ false
91+ }
92+ } else {
93+ false
94+ }
95+ } else {
96+ false
97+ }
9398 } else {
9499 false
95100 }
101+ } else {
102+ false
96103 }
97104}
98105
0 commit comments