From 91a06226a1bb0fdee3ab2c12225ba7b901659383 Mon Sep 17 00:00:00 2001 From: Quang Duong Nguyen Date: Mon, 24 Mar 2025 06:13:14 -0400 Subject: [PATCH] move the implementation under check_def_field --- clippy_lints/src/missing_doc.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 3ac9adfa4f33..5d228f7ea436 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -91,14 +91,6 @@ impl MissingDoc { article: &'static str, desc: &'static str, ) { - // Skip checking if the item starts with underscore and allow_unused is enabled - if self.allow_unused { - if let Some(name) = cx.tcx.opt_item_name(def_id.to_def_id()) { - if name.as_str().starts_with('_') { - return; - } - } - } // If we're building a test harness, then warning about // documentation is probably not really relevant right now. if cx.sess().opts.test { @@ -272,6 +264,12 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { fn check_field_def(&mut self, cx: &LateContext<'tcx>, sf: &'tcx hir::FieldDef<'_>) { if !sf.is_positional() { + // Skip checking if the field starts with underscore and allow_unused is enabled + if self.allow_unused && sf.ident.as_str().starts_with('_') { + self.prev_span = Some(sf.span); + return; + } + let attrs = cx.tcx.hir_attrs(sf.hir_id); if !is_from_proc_macro(cx, sf) { self.check_missing_docs_attrs(cx, sf.def_id, attrs, sf.span, "a", "struct field");