From 7e63f93d81062fa810eaefe368b38892bf11f909 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sun, 14 Jan 2018 11:35:07 +0530 Subject: [PATCH] Don't warn about missing docs for main() Fixes #2348 --- clippy_lints/src/missing_doc.rs | 12 +++++++++++- tests/ui/missing-doc.stderr | 6 ------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 2a3a4e365a5..ecc8f50d6a0 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -124,7 +124,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc { let desc = match it.node { hir::ItemConst(..) => "a constant", hir::ItemEnum(..) => "an enum", - hir::ItemFn(..) => "a function", + hir::ItemFn(..) => { + // ignore main() + if it.name == "main" { + let def_id = cx.tcx.hir.local_def_id(it.id); + let def_key = cx.tcx.hir.def_key(def_id); + if def_key.parent == Some(hir::def_id::CRATE_DEF_INDEX) { + return; + } + } + "a function" + }, hir::ItemMod(..) => "a module", hir::ItemStatic(..) => "a static", hir::ItemStruct(..) => "a struct", diff --git a/tests/ui/missing-doc.stderr b/tests/ui/missing-doc.stderr index 55eab4f5d69..340a53386f9 100644 --- a/tests/ui/missing-doc.stderr +++ b/tests/ui/missing-doc.stderr @@ -264,9 +264,3 @@ error: missing documentation for a function 191 | fn also_undocumented2() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: missing documentation for a function - --> $DIR/missing-doc.rs:202:1 - | -202 | fn main() {} - | ^^^^^^^^^^^^ -