Skip to content

Commit e286110

Browse files
committed
dont trigger in macro expansions
1 parent 824a039 commit e286110

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

clippy_lints/src/missing_fields_in_debug.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ impl<'tcx> LateLintPass<'tcx> for MissingFieldInDebug {
263263
if let TyKind::Path(QPath::Resolved(_, self_path)) = &self_ty.kind;
264264
if cx.match_def_path(trait_def_id, &[sym::core, sym::fmt, sym::Debug]);
265265

266+
// don't trigger if this impl was derived
267+
if !cx.tcx.has_attr(item.owner_id, sym::automatically_derived);
268+
if !item.span.from_expansion();
269+
266270
// find `Debug::fmt` function
267271
if let Some(fmt_item) = items.iter().find(|i| i.ident.name == sym::fmt);
268272
if let ImplItem { kind: ImplItemKind::Fn(_, body_id), .. } = cx.tcx.hir().impl_item(fmt_item.id);

tests/ui/missing_field_in_debug.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,4 +217,16 @@ impl fmt::Debug for Empty {
217217
}
218218
}
219219

220+
#[derive(Debug)]
221+
struct DerivedStruct {
222+
a: u8,
223+
b: i32,
224+
}
225+
226+
#[derive(Debug)]
227+
enum DerivedEnum {
228+
A(i32),
229+
B { a: String },
230+
}
231+
220232
fn main() {}

0 commit comments

Comments
 (0)