Skip to content

Commit 0b168c6

Browse files
committed
Add Future detection for missing_errors_doc.
1 parent b91ae16 commit 0b168c6

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

clippy_lints/src/doc.rs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::utils::{is_entrypoint_fn, match_type, paths, return_ty, span_lint};
22
use itertools::Itertools;
33
use rustc::lint::in_external_macro;
4+
use rustc::ty::TyKind;
45
use rustc_data_structures::fx::FxHashSet;
56
use rustc_hir as hir;
67
use rustc_lint::{LateContext, LateLintPass};
@@ -213,13 +214,33 @@ fn lint_for_missing_headers<'a, 'tcx>(
213214
"unsafe function's docs miss `# Safety` section",
214215
);
215216
}
216-
if !headers.errors && match_type(cx, return_ty(cx, hir_id), &paths::RESULT) {
217-
span_lint(
218-
cx,
219-
MISSING_ERRORS_DOC,
220-
span,
221-
"docs for function returning `Result` missing `# Errors` section",
222-
);
217+
if !headers.errors {
218+
if match_type(cx, return_ty(cx, hir_id), &paths::RESULT) {
219+
span_lint(
220+
cx,
221+
MISSING_ERRORS_DOC,
222+
span,
223+
"docs for function returning `Result` missing `# Errors` section",
224+
);
225+
} else {
226+
use TyKind::*;
227+
let def_id = cx.tcx.hir().local_def_id(hir_id);
228+
let mir = cx.tcx.optimized_mir(def_id);
229+
if let Opaque(_, subs) = mir.return_ty().kind {
230+
if let Some(ty) = subs.types().next() {
231+
if let Generator(_, subs, _) = ty.kind {
232+
if match_type(cx, subs.as_generator().return_ty(def_id, cx.tcx), &paths::RESULT) {
233+
span_lint(
234+
cx,
235+
MISSING_ERRORS_DOC,
236+
span,
237+
"docs for function returning `Result` missing `# Errors` section",
238+
);
239+
}
240+
}
241+
}
242+
}
243+
}
223244
}
224245
}
225246

0 commit comments

Comments
 (0)