1
1
use clippy_utils:: diagnostics:: span_lint_and_sugg;
2
2
use rustc_hir:: * ;
3
+ use rustc_lint:: { EarlyContext , EarlyLintPass } ;
3
4
use rustc_lint:: { LateContext , LateLintPass } ;
4
5
use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
5
6
@@ -33,26 +34,54 @@ declare_clippy_lint! {
33
34
declare_lint_pass ! ( TrailingZeroSizedArrayWithoutReprC => [ TRAILING_ZERO_SIZED_ARRAY_WITHOUT_REPR_C ] ) ;
34
35
35
36
impl LateLintPass < ' _ > for TrailingZeroSizedArrayWithoutReprC {
36
- fn check_struct_def ( & mut self , _: & LateContext < ' tcx > , _: & ' tcx rustc_hir:: VariantData < ' tcx > ) { }
37
+ fn check_struct_def ( & mut self , cx : & LateContext < ' tcx > , data : & ' tcx rustc_hir:: VariantData < ' tcx > ) {
38
+ dbg ! ( "in check_struct_def" ) ;
39
+ if_chain ! {
40
+ if let Some ( def) = data. fields( ) . last( ) ;
41
+ if let rustc_hir:: TyKind :: Array ( ty, acost) = def. ty. kind;
42
+ then {
43
+ // is the AnonConst `0`
44
+ }
45
+ }
37
46
38
- fn check_struct_def_post ( & mut self , _: & LateContext < ' tcx > , _: & ' tcx rustc_hir:: VariantData < ' tcx > ) { }
47
+ // span_lint_and_sugg(
48
+ // cx,
49
+ // todo!(),
50
+ // todo!(),
51
+ // todo!(),
52
+ // todo!(),
53
+ // todo!(),
54
+ // rustc_errors::Applicability::MaybeIncorrect,
55
+ // )
56
+ }
39
57
// https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/sty/enum.TyKind.html#variant.Array in latepass
40
58
// or https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/ast/enum.TyKind.html#variant.Array in early pass
41
59
42
- fn check_field_def ( & mut self , _: & LateContext < ' tcx > , _: & ' tcx rustc_hir:: FieldDef < ' tcx > ) { }
60
+ // fn check_struct_def_post(&mut self, _: &LateContext<'tcx>, _: &'tcx rustc_hir::VariantData<'tcx>)
61
+ // {}
43
62
44
- fn check_attribute ( & mut self , _: & LateContext < ' tcx > , _: & ' tcx rustc_ast :: Attribute ) { }
63
+ // fn check_field_def (&mut self, _: &LateContext<'tcx>, _: &'tcx rustc_hir::FieldDef<'tcx> ) {}
45
64
46
- fn enter_lint_attrs ( & mut self , _: & LateContext < ' tcx > , _: & ' tcx [ rustc_ast:: Attribute ] ) { }
65
+ // fn check_attribute (&mut self, _: &LateContext<'tcx>, _: &'tcx rustc_ast::Attribute) {}
47
66
48
- fn exit_lint_attrs ( & mut self , _: & LateContext < ' tcx > , _: & ' tcx [ rustc_ast:: Attribute ] ) { }
67
+ // fn enter_lint_attrs(&mut self, _: &LateContext<'tcx>, _: &'tcx [rustc_ast::Attribute]) {}
68
+
69
+ // fn exit_lint_attrs(&mut self, _: &LateContext<'tcx>, _: &'tcx [rustc_ast::Attribute]) {}
49
70
}
50
71
//
51
72
// TODO: Register the lint pass in `clippy_lints/src/lib.rs`,
52
73
// e.g. store.register_late_pass(||
53
74
// Box::new(trailing_zero_sized_array_without_repr_c::TrailingZeroSizedArrayWithoutReprC));
54
75
76
+ // fn temp_alert() {}
55
77
56
- fn temp_alert ( ) {
57
- span_lint_and_sugg ( cx, lint, sp, msg, help, sugg, applicability)
58
- }
78
+ impl EarlyLintPass for TrailingZeroSizedArrayWithoutReprC {
79
+ fn check_struct_def ( & mut self , cx : & EarlyContext < ' _ > , data : & rustc_ast:: VariantData ) {
80
+ if_chain ! {
81
+ if let rustc_ast:: ast:: VariantData :: Struct ( field_defs, some_bool_huh) = data;
82
+ if let Some ( last_field) = field_defs. last( ) ;
83
+ if let rustc_ast:: ast:: TyKind :: Array ( _, aconst) = & last_field. ty. kind;
84
+ then { dbg!( aconst) ; return ( ) ; }
85
+ }
86
+ }
87
+ }
0 commit comments