+ lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers);
+ }
+ }
+}
+
+fn lint_for_missing_headers<'a, 'tcx>(
+ cx: &LateContext<'a, 'tcx>,
+ hir_id: hir::HirId,
+ span: impl Into<MultiSpan> + Copy,
+ sig: &hir::FnSig<'_>,
+ headers: DocHeaders,
+) {
+ if !cx.access_levels.is_exported(hir_id) {
+ return; // Private functions do not require doc comments
+ }
+ if !headers.safety && sig.header.unsafety == hir::Unsafety::Unsafe {
+ span_lint(
+ cx,
+ MISSING_SAFETY_DOC,
+ span,
+ "unsafe function's docs miss `# Safety` section",
+ );
+ }
+ if !headers.errors {
+ if match_type(cx, return_ty(cx, hir_id), &paths::RESULT) {
+ span_lint(
+ cx,
+ MISSING_ERRORS_DOC,
+ span,
+ "docs for function returning `Result` missing `# Errors` section",
+ );
+ } else {
+ let def_id = cx.tcx.hir().local_def_id(hir_id);
+ let mir = cx.tcx.optimized_mir(def_id);
+ if let Some(future) = get_trait_def_id(cx, &paths::FUTURE) {
+ if implements_trait(cx, mir.return_ty(), future, &[]) {
+ use TyKind::*;
+
+ if let Opaque(_, subs) = mir.return_ty().kind {
+ if let Some(ty) = subs.types().next() {
+ if let Generator(_, subs, _) = ty.kind {
+ if match_type(cx, subs.as_generator().return_ty(def_id, cx.tcx), &paths::RESULT) {
+ span_lint(
+ cx,
+ MISSING_ERRORS_DOC,
+ span,
+ "docs for function returning `Result` missing `# Errors` section",
+ );
+ }
+ }
+ }
+ }
+ }