]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/large_enum_variant.rs
Replace some std::iter::repeat with str::repeat
[rust.git] / clippy_lints / src / large_enum_variant.rs
index 5bc3234e3252f2a3ca8ef5e323cd40da30f76096..f166748d86b81a021822759440e66456206309b5 100644 (file)
@@ -1,9 +1,11 @@
 //! lint when there is a large size difference between variants on an enum
 
-use crate::utils::{snippet_opt, span_lint_and_then};
+use clippy_utils::diagnostics::span_lint_and_then;
+use clippy_utils::source::snippet_opt;
 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 +58,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;
@@ -109,7 +113,7 @@ fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item<'_>) {
                             );
                             if variant.fields.len() == 1 {
                                 let span = match def.variants[i].data {
-                                    VariantData::Struct(ref fields, ..) | VariantData::Tuple(ref fields, ..) => {
+                                    VariantData::Struct(fields, ..) | VariantData::Tuple(fields, ..) => {
                                         fields[0].ty.span
                                     },
                                     VariantData::Unit(..) => unreachable!(),