|
1 | 1 | use crate::utils::{is_entrypoint_fn, match_type, paths, return_ty, span_lint};
|
2 | 2 | use itertools::Itertools;
|
3 | 3 | use rustc::lint::in_external_macro;
|
| 4 | +use rustc::ty::TyKind; |
4 | 5 | use rustc_data_structures::fx::FxHashSet;
|
5 | 6 | use rustc_hir as hir;
|
6 | 7 | use rustc_lint::{LateContext, LateLintPass};
|
@@ -213,13 +214,33 @@ fn lint_for_missing_headers<'a, 'tcx>(
|
213 | 214 | "unsafe function's docs miss `# Safety` section",
|
214 | 215 | );
|
215 | 216 | }
|
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 | + } |
223 | 244 | }
|
224 | 245 | }
|
225 | 246 |
|
|
0 commit comments