Skip to content

Commit 2d9f036

Browse files
authored
Merge pull request #2 from Infineon/filter_test_main
Remove automatically created "main" from test documentation
2 parents 7259832 + 799fc5d commit 2d9f036

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/librustdoc/visit_ast.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,16 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
506506
hir::ItemKind::Mod(ref m) => {
507507
self.enter_mod(item.owner_id.def_id, m, name, renamed, import_id);
508508
}
509-
hir::ItemKind::Fn(..)
510-
| hir::ItemKind::ExternCrate(..)
509+
hir::ItemKind::Fn(fn_sig, _, _) => {
510+
// Don't show auto created function "main" that is not in the source code (empty span) when documenting tests.
511+
if !(self.cx.cache.document_tests
512+
&& fn_sig.span.is_empty()
513+
&& name.as_str() == "main")
514+
{
515+
self.add_to_current_mod(item, renamed, import_id);
516+
}
517+
}
518+
hir::ItemKind::ExternCrate(..)
511519
| hir::ItemKind::Enum(..)
512520
| hir::ItemKind::Struct(..)
513521
| hir::ItemKind::Union(..)

0 commit comments

Comments
 (0)