Skip to content

Commit 2f62d80

Browse files
authored
Merge pull request #2349 from rust-lang-nursery/no-main-doc
Don't warn about missing docs for main()
2 parents cc9008b + 7e63f93 commit 2f62d80

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

clippy_lints/src/missing_doc.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
124124
let desc = match it.node {
125125
hir::ItemConst(..) => "a constant",
126126
hir::ItemEnum(..) => "an enum",
127-
hir::ItemFn(..) => "a function",
127+
hir::ItemFn(..) => {
128+
// ignore main()
129+
if it.name == "main" {
130+
let def_id = cx.tcx.hir.local_def_id(it.id);
131+
let def_key = cx.tcx.hir.def_key(def_id);
132+
if def_key.parent == Some(hir::def_id::CRATE_DEF_INDEX) {
133+
return;
134+
}
135+
}
136+
"a function"
137+
},
128138
hir::ItemMod(..) => "a module",
129139
hir::ItemStatic(..) => "a static",
130140
hir::ItemStruct(..) => "a struct",

tests/ui/missing-doc.stderr

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,3 @@ error: missing documentation for a function
264264
191 | fn also_undocumented2() {}
265265
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
266266

267-
error: missing documentation for a function
268-
--> $DIR/missing-doc.rs:202:1
269-
|
270-
202 | fn main() {}
271-
| ^^^^^^^^^^^^
272-

0 commit comments

Comments
 (0)