about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJason Newcomb <jsnewcomb@pm.me>2024-06-12 22:16:47 -0400
committerJason Newcomb <jsnewcomb@pm.me>2024-07-07 16:51:58 -0400
commit430c02cbd0f45d50fd1c4bbefad4d19b5d464984 (patch)
tree80daf5267d4e28bd6d80b2a766071cce5717d39e
parent3092c8a5fd4d715dd58bd8f6843330c3aa8de768 (diff)
downloadrust-430c02cbd0f45d50fd1c4bbefad4d19b5d464984.tar.gz
rust-430c02cbd0f45d50fd1c4bbefad4d19b5d464984.zip
`large_enum_variant`: Delay macro check
-rw-r--r--clippy_lints/src/large_enum_variant.rs17
1 files changed, 6 insertions, 11 deletions
diff --git a/clippy_lints/src/large_enum_variant.rs b/clippy_lints/src/large_enum_variant.rs
index 0bf7389ef9c..85daadcc537 100644
--- a/clippy_lints/src/large_enum_variant.rs
+++ b/clippy_lints/src/large_enum_variant.rs
@@ -77,17 +77,12 @@ impl_lint_pass!(LargeEnumVariant => [LARGE_ENUM_VARIANT]);
 
 impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant {
     fn check_item(&mut self, cx: &LateContext<'tcx>, item: &Item<'tcx>) {
-        if in_external_macro(cx.tcx.sess, item.span) {
-            return;
-        }
-        if let ItemKind::Enum(ref def, _) = item.kind {
-            let ty = cx.tcx.type_of(item.owner_id).instantiate_identity();
-            let ty::Adt(adt, subst) = ty.kind() else {
-                panic!("already checked whether this is an enum")
-            };
-            if adt.variants().len() <= 1 {
-                return;
-            }
+        if let ItemKind::Enum(ref def, _) = item.kind
+            && let ty = cx.tcx.type_of(item.owner_id).instantiate_identity()
+            && let ty::Adt(adt, subst) = ty.kind()
+            && adt.variants().len() > 1
+            && !in_external_macro(cx.tcx.sess, item.span)
+        {
             let variants_size = AdtVariantInfo::new(cx, *adt, subst);
 
             let mut difference = variants_size[0].size - variants_size[1].size;