about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNathaniel Hamovitz <18648574+nhamovitz@users.noreply.github.com>2021-10-15 00:13:42 -0700
committerNathaniel Hamovitz <18648574+nhamovitz@users.noreply.github.com>2021-10-18 03:05:18 -0700
commitc69387a0d530dccb56ef11d4cd148f9c38904893 (patch)
tree58cc1399a4be7c9c3b9bfd0b167cc3038f34877a
parent797507c58390662098f0d20a9ee89d200f93f11c (diff)
downloadrust-c69387a0d530dccb56ef11d4cd148f9c38904893.tar.gz
rust-c69387a0d530dccb56ef11d4cd148f9c38904893.zip
Well it builds
-rw-r--r--clippy_lints/src/trailing_zero_sized_array_without_repr_c.rs47
-rw-r--r--tests/ui/trailing_zero_sized_array_without_repr_c.rs6
2 files changed, 41 insertions, 12 deletions
diff --git a/clippy_lints/src/trailing_zero_sized_array_without_repr_c.rs b/clippy_lints/src/trailing_zero_sized_array_without_repr_c.rs
index 9aea22af274..507d9b40412 100644
--- a/clippy_lints/src/trailing_zero_sized_array_without_repr_c.rs
+++ b/clippy_lints/src/trailing_zero_sized_array_without_repr_c.rs
@@ -1,5 +1,6 @@
 use clippy_utils::diagnostics::span_lint_and_sugg;
 use rustc_hir::*;
+use rustc_lint::{EarlyContext, EarlyLintPass};
 use rustc_lint::{LateContext, LateLintPass};
 use rustc_session::{declare_lint_pass, declare_tool_lint};
 
@@ -33,26 +34,54 @@ declare_clippy_lint! {
 declare_lint_pass!(TrailingZeroSizedArrayWithoutReprC => [TRAILING_ZERO_SIZED_ARRAY_WITHOUT_REPR_C]);
 
 impl LateLintPass<'_> for TrailingZeroSizedArrayWithoutReprC {
-    fn check_struct_def(&mut self, _: &LateContext<'tcx>, _: &'tcx rustc_hir::VariantData<'tcx>) {}
+    fn check_struct_def(&mut self, cx: &LateContext<'tcx>, data: &'tcx rustc_hir::VariantData<'tcx>) {
+        dbg!("in check_struct_def");
+        if_chain! {
+            if let Some(def) = data.fields().last();
+            if let rustc_hir::TyKind::Array(ty, acost) = def.ty.kind;
+            then {
+                // is the AnonConst `0`
+            }
+        }
 
-    fn check_struct_def_post(&mut self, _: &LateContext<'tcx>, _: &'tcx rustc_hir::VariantData<'tcx>) {}
+        // span_lint_and_sugg(
+        //     cx,
+        //     todo!(),
+        //     todo!(),
+        //     todo!(),
+        //     todo!(),
+        //     todo!(),
+        //     rustc_errors::Applicability::MaybeIncorrect,
+        // )
+    }
     // https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/sty/enum.TyKind.html#variant.Array in latepass
     // or https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/ast/enum.TyKind.html#variant.Array in early pass
 
-    fn check_field_def(&mut self, _: &LateContext<'tcx>, _: &'tcx rustc_hir::FieldDef<'tcx>) {}
+    // fn check_struct_def_post(&mut self, _: &LateContext<'tcx>, _: &'tcx rustc_hir::VariantData<'tcx>)
+    // {}
 
-    fn check_attribute(&mut self, _: &LateContext<'tcx>, _: &'tcx rustc_ast::Attribute) {}
+    // fn check_field_def(&mut self, _: &LateContext<'tcx>, _: &'tcx rustc_hir::FieldDef<'tcx>) {}
 
-    fn enter_lint_attrs(&mut self, _: &LateContext<'tcx>, _: &'tcx [rustc_ast::Attribute]) {}
+    // fn check_attribute(&mut self, _: &LateContext<'tcx>, _: &'tcx rustc_ast::Attribute) {}
 
-    fn exit_lint_attrs(&mut self, _: &LateContext<'tcx>, _: &'tcx [rustc_ast::Attribute]) {}
+    // fn enter_lint_attrs(&mut self, _: &LateContext<'tcx>, _: &'tcx [rustc_ast::Attribute]) {}
+
+    // fn exit_lint_attrs(&mut self, _: &LateContext<'tcx>, _: &'tcx [rustc_ast::Attribute]) {}
 }
 //
 // TODO: Register the lint pass in `clippy_lints/src/lib.rs`,
 //       e.g. store.register_late_pass(||
 // Box::new(trailing_zero_sized_array_without_repr_c::TrailingZeroSizedArrayWithoutReprC));
 
+// fn temp_alert() {}
 
-fn temp_alert() {
-    span_lint_and_sugg(cx, lint, sp, msg, help, sugg, applicability)
-}
\ No newline at end of file
+impl EarlyLintPass for TrailingZeroSizedArrayWithoutReprC {
+    fn check_struct_def(&mut self, cx: &EarlyContext<'_>, data: &rustc_ast::VariantData) {
+        if_chain! {
+            if let rustc_ast::ast::VariantData::Struct(field_defs, some_bool_huh) = data;
+            if let Some(last_field) = field_defs.last();
+            if let rustc_ast::ast::TyKind::Array(_, aconst) = &last_field.ty.kind;            
+            then {dbg!(aconst); return ();}
+        }
+    }
+}
diff --git a/tests/ui/trailing_zero_sized_array_without_repr_c.rs b/tests/ui/trailing_zero_sized_array_without_repr_c.rs
index 2a0f432bc2d..771622178e7 100644
--- a/tests/ui/trailing_zero_sized_array_without_repr_c.rs
+++ b/tests/ui/trailing_zero_sized_array_without_repr_c.rs
@@ -2,17 +2,17 @@
 
 struct RarelyUseful {
     field: i32,
-    last: [SomeType; 0],
+    last: [usize; 0],
 }
 
 #[repr(C)]
 struct GoodReason {
     field: i32,
-    last: [SomeType; 0],
+    last: [usize; 0],
 }
 
 struct OnlyFieldIsZeroSizeArray {
-    first_and_last: [SomeType; 0],
+    first_and_last: [usize; 0],
 }
 
 struct GenericArrayType<T> {