1
1
use clippy_utils:: consts:: { miri_to_const, Constant } ;
2
- use clippy_utils:: diagnostics:: span_lint_and_sugg;
3
- use clippy_utils:: source:: snippet;
2
+ use clippy_utils:: diagnostics:: span_lint_and_help;
4
3
use rustc_ast:: Attribute ;
5
- use rustc_errors:: Applicability ;
6
4
use rustc_hir:: def_id:: LocalDefId ;
7
5
use rustc_hir:: { Item , ItemKind , VariantData } ;
8
6
use rustc_lint:: { LateContext , LateLintPass } ;
@@ -47,15 +45,15 @@ impl<'tcx> LateLintPass<'tcx> for TrailingZeroSizedArrayWithoutReprC {
47
45
fn check_item ( & mut self , cx : & LateContext < ' tcx > , item : & ' tcx Item < ' tcx > ) {
48
46
dbg ! ( item. ident) ;
49
47
if is_struct_with_trailing_zero_sized_array ( cx, item) && !has_repr_attr ( cx, item. def_id ) {
50
- span_lint_and_sugg (
51
- cx,
52
- TRAILING_ZERO_SIZED_ARRAY_WITHOUT_REPR_C ,
53
- item. span ,
54
- "trailing zero-sized array in a struct which is not marked `#[repr(C)]`" ,
55
- "try annotating the struct definition with `#[repr(C)]` (or another `repr` attribute):" ,
56
- format ! ( " #[repr(C)]\n {}" , snippet ( cx , item . span , ".." ) ) ,
57
- Applicability :: MaybeIncorrect ,
58
- ) ;
48
+ // span_lint_and_help (
49
+ // cx,
50
+ // TRAILING_ZERO_SIZED_ARRAY_WITHOUT_REPR_C,
51
+ // item.span,
52
+ // "trailing zero-sized array in a struct which is not marked `#[repr(C)]`",
53
+ // None ,
54
+ // "consider annotating the struct definition with ` #[repr(C)]` (or another `repr` attribute)" ,
55
+ // );
56
+ eprintln ! ( "— consider yourself linted — 🦀" )
59
57
}
60
58
}
61
59
}
@@ -87,15 +85,16 @@ fn is_struct_with_trailing_zero_sized_array(cx: &LateContext<'tcx>, item: &'tcx
87
85
fn has_repr_attr ( cx : & LateContext < ' tcx > , def_id : LocalDefId ) -> bool {
88
86
let attrs_get_attrs = get_attrs_get_attrs ( cx, def_id) ;
89
87
let attrs_hir_map = get_attrs_hir_map ( cx, def_id) ;
90
- let b11 = dbg ! ( includes_repr_attr_using_sym( attrs_get_attrs) ) ;
91
- let b12 = dbg ! ( includes_repr_attr_using_sym( attrs_hir_map) ) ;
92
- let b21 = dbg ! ( includes_repr_attr_using_helper( cx, attrs_get_attrs) ) ;
93
- let b22 = dbg ! ( includes_repr_attr_using_helper( cx, attrs_hir_map) ) ;
94
- let b3 = dbg ! ( has_repr_attr_using_adt( cx, def_id) ) ;
95
- let all_same = b11 && b12 && b21 && b22 && b3;
88
+
89
+ let b11 = includes_repr_attr_using_sym ( attrs_get_attrs) ;
90
+ let b12 = includes_repr_attr_using_sym ( attrs_hir_map) ;
91
+ let b21 = includes_repr_attr_using_helper ( cx, attrs_get_attrs) ;
92
+ let b22 = includes_repr_attr_using_helper ( cx, attrs_hir_map) ;
93
+ let b3 = has_repr_attr_using_adt ( cx, def_id) ;
94
+ let all_same = ( b11 && b12 && b21 && b22 && b3) || ( !b11 && !b12 && !b21 && !b22 && !b3) ;
96
95
dbg ! ( all_same) ;
97
96
98
- b11
97
+ b21
99
98
}
100
99
101
100
fn get_attrs_get_attrs ( cx : & LateContext < ' tcx > , def_id : LocalDefId ) -> & ' tcx [ Attribute ] {
@@ -108,7 +107,9 @@ fn get_attrs_hir_map(cx: &LateContext<'tcx>, def_id: LocalDefId) -> &'tcx [Attri
108
107
hir_map. attrs ( hir_id)
109
108
}
110
109
111
- // Don't like this because it's so dependent on the current list of `repr` flags and it would have to be manually updated if that ever expanded. idk if there's any mechanism in `bitflag!` or elsewhere for requiring that sort of exhaustiveness
110
+ // Don't like this because it's so dependent on the current list of `repr` flags and it would have
111
+ // to be manually updated if that ever expanded. idk if there's any mechanism in `bitflag!` or
112
+ // elsewhere for requiring that sort of exhaustiveness
112
113
fn has_repr_attr_using_adt ( cx : & LateContext < ' tcx > , def_id : LocalDefId ) -> bool {
113
114
let ty = cx. tcx . type_of ( def_id. to_def_id ( ) ) ;
114
115
if let ty_mod:: Adt ( adt, _) = ty. kind ( ) {
@@ -129,5 +130,7 @@ fn includes_repr_attr_using_sym(attrs: &'tcx [Attribute]) -> bool {
129
130
}
130
131
131
132
fn includes_repr_attr_using_helper ( cx : & LateContext < ' tcx > , attrs : & ' tcx [ Attribute ] ) -> bool {
132
- attrs. iter ( ) . any ( |attr| !rustc_attr:: find_repr_attrs ( cx. tcx . sess ( ) , attr) . is_empty ( ) )
133
+ attrs
134
+ . iter ( )
135
+ . any ( |attr| !rustc_attr:: find_repr_attrs ( cx. tcx . sess ( ) , attr) . is_empty ( ) )
133
136
}
0 commit comments