]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/large_enum_variant.rs
Rollup merge of #83092 - petrochenkov:qspan, r=estebank
[rust.git] / clippy_lints / src / large_enum_variant.rs
index 7ac83739be67bd6bb9286db8c705d4a7d0fec3ba..ab4cb33612d380f0cddb11b0d1b5eec75bf4c253 100644 (file)
@@ -4,6 +4,7 @@
 use rustc_errors::Applicability;
 use rustc_hir::{Item, ItemKind, VariantData};
 use rustc_lint::{LateContext, LateLintPass};
+use rustc_middle::lint::in_external_macro;
 use rustc_session::{declare_tool_lint, impl_lint_pass};
 use rustc_target::abi::LayoutOf;
 
@@ -56,11 +57,13 @@ pub fn new(maximum_size_difference_allowed: u64) -> Self {
 
 impl_lint_pass!(LargeEnumVariant => [LARGE_ENUM_VARIANT]);
 
-impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeEnumVariant {
-    fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item<'_>) {
-        let did = cx.tcx.hir().local_def_id(item.hir_id);
+impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant {
+    fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
+        if in_external_macro(cx.tcx.sess, item.span) {
+            return;
+        }
         if let ItemKind::Enum(ref def, _) = item.kind {
-            let ty = cx.tcx.type_of(did);
+            let ty = cx.tcx.type_of(item.def_id);
             let adt = ty.ty_adt_def().expect("already checked whether this is an enum");
 
             let mut largest_variant: Option<(_, _)> = None;
@@ -98,12 +101,12 @@ fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item<'_>) {
                         LARGE_ENUM_VARIANT,
                         def.variants[i].span,
                         "large size difference between variants",
-                        |db| {
-                            db.span_label(
+                        |diag| {
+                            diag.span_label(
                                 def.variants[(largest.1).0].span,
                                 &format!("this variant is {} bytes", largest.0),
                             );
-                            db.span_note(
+                            diag.span_note(
                                 def.variants[(second.1).0].span,
                                 &format!("and the second-largest variant is {} bytes:", second.0),
                             );
@@ -115,7 +118,7 @@ fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item<'_>) {
                                     VariantData::Unit(..) => unreachable!(),
                                 };
                                 if let Some(snip) = snippet_opt(cx, span) {
-                                    db.span_suggestion(
+                                    diag.span_suggestion(
                                         span,
                                         help_text,
                                         format!("Box<{}>", snip),
@@ -124,7 +127,7 @@ fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item<'_>) {
                                     return;
                                 }
                             }
-                            db.span_help(def.variants[i].span, help_text);
+                            diag.span_help(def.variants[i].span, help_text);
                         },
                     );
                 }