@@ -38,7 +38,6 @@ declare_lint_pass!(TrailingZeroSizedArrayWithoutReprC => [TRAILING_ZERO_SIZED_AR
38
38
39
39
impl < ' tcx > LateLintPass < ' tcx > for TrailingZeroSizedArrayWithoutReprC {
40
40
fn check_item ( & mut self , cx : & LateContext < ' tcx > , item : & ' tcx Item < ' tcx > ) {
41
- dbg ! ( item. ident) ;
42
41
if is_struct_with_trailing_zero_sized_array ( cx, item) {
43
42
// NOTE: This is to include attributes on the definition when we print the lint. If the convention
44
43
// is to not do that with struct definitions (I'm not sure), then this isn't necessary. (note: if
@@ -66,24 +65,18 @@ impl<'tcx> LateLintPass<'tcx> for TrailingZeroSizedArrayWithoutReprC {
66
65
}
67
66
68
67
fn is_struct_with_trailing_zero_sized_array ( cx : & LateContext < ' tcx > , item : & ' tcx Item < ' tcx > ) -> bool {
68
+ // TODO: when finalized, replace with an `if_chain`. I have it like this because my rust-analyzer doesn't work when it's an `if_chain`
69
69
// First check if last field is an array
70
70
if let ItemKind :: Struct ( data, _) = & item. kind {
71
- if let VariantData :: Struct ( field_defs, _) = data {
72
- if let Some ( last_field) = field_defs. last ( ) {
73
- if let rustc_hir:: TyKind :: Array ( _, length) = last_field. ty . kind {
74
- // Then check if that that array zero-sized
75
- let length_ldid = cx. tcx . hir ( ) . local_def_id ( length. hir_id ) ;
76
- let length = Const :: from_anon_const ( cx. tcx , length_ldid) ;
77
- let length = length. try_eval_usize ( cx. tcx , cx. param_env ) ;
78
- // if let Some((Constant::Int(length), _)) = length {
79
- if let Some ( length) = length {
80
- length == 0
81
- } else {
82
- false
83
- }
84
- } else {
85
- false
86
- }
71
+ let field_defs = data. fields ( ) ;
72
+ if let Some ( last_field) = field_defs. last ( ) {
73
+ if let rustc_hir:: TyKind :: Array ( _, length) = last_field. ty . kind {
74
+ // Then check if that that array zero-sized
75
+ let length_ldid = cx. tcx . hir ( ) . local_def_id ( length. hir_id ) ;
76
+ let length = Const :: from_anon_const ( cx. tcx , length_ldid) ;
77
+ let length = length. try_eval_usize ( cx. tcx , cx. param_env ) ;
78
+ // if let Some((Constant::Int(length), _)) = length {
79
+ if let Some ( length) = length { length == 0 } else { false }
87
80
} else {
88
81
false
89
82
}
0 commit comments