11use 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;
43use rustc_ast:: Attribute ;
5- use rustc_errors:: Applicability ;
64use rustc_hir:: def_id:: LocalDefId ;
75use rustc_hir:: { Item , ItemKind , VariantData } ;
86use rustc_lint:: { LateContext , LateLintPass } ;
@@ -47,15 +45,15 @@ impl<'tcx> LateLintPass<'tcx> for TrailingZeroSizedArrayWithoutReprC {
4745 fn check_item ( & mut self , cx : & LateContext < ' tcx > , item : & ' tcx Item < ' tcx > ) {
4846 dbg ! ( item. ident) ;
4947 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 — 🦀" )
5957 }
6058 }
6159}
@@ -87,15 +85,16 @@ fn is_struct_with_trailing_zero_sized_array(cx: &LateContext<'tcx>, item: &'tcx
8785fn has_repr_attr ( cx : & LateContext < ' tcx > , def_id : LocalDefId ) -> bool {
8886 let attrs_get_attrs = get_attrs_get_attrs ( cx, def_id) ;
8987 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) ;
9695 dbg ! ( all_same) ;
9796
98- b11
97+ b21
9998}
10099
101100fn 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
108107 hir_map. attrs ( hir_id)
109108}
110109
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
112113fn has_repr_attr_using_adt ( cx : & LateContext < ' tcx > , def_id : LocalDefId ) -> bool {
113114 let ty = cx. tcx . type_of ( def_id. to_def_id ( ) ) ;
114115 if let ty_mod:: Adt ( adt, _) = ty. kind ( ) {
@@ -129,5 +130,7 @@ fn includes_repr_attr_using_sym(attrs: &'tcx [Attribute]) -> bool {
129130}
130131
131132fn 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 ( ) )
133136}
0 commit comments