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;
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;
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),
);
VariantData::Unit(..) => unreachable!(),
};
if let Some(snip) = snippet_opt(cx, span) {
- db.span_suggestion(
+ diag.span_suggestion(
span,
help_text,
format!("Box<{}>", snip),
return;
}
}
- db.span_help(def.variants[i].span, help_text);
+ diag.span_help(def.variants[i].span, help_text);
},
);
}