|
1 | 1 | use crate::utils::{get_trait_def_id, implements_trait, is_entrypoint_fn, match_type, paths, return_ty, span_lint};
|
| 2 | +use if_chain::if_chain; |
2 | 3 | use itertools::Itertools;
|
3 | 4 | use rustc::lint::in_external_macro;
|
4 | 5 | use rustc::ty::TyKind;
|
@@ -223,27 +224,26 @@ fn lint_for_missing_headers<'a, 'tcx>(
|
223 | 224 | span,
|
224 | 225 | "docs for function returning `Result` missing `# Errors` section",
|
225 | 226 | );
|
226 |
| - } else if let (Some(body_id), Some(future)) = (body_id, get_trait_def_id(cx, &paths::FUTURE)) { |
227 |
| - let def_id = cx.tcx.hir().body_owner_def_id(body_id); |
228 |
| - let mir = cx.tcx.optimized_mir(def_id); |
229 |
| - let ret_ty = mir.return_ty(); |
230 |
| - |
231 |
| - if implements_trait(cx, ret_ty, future, &[]) { |
232 |
| - use TyKind::*; |
233 |
| - |
234 |
| - if let Opaque(_, subs) = ret_ty.kind { |
235 |
| - if let Some(ty) = subs.types().next() { |
236 |
| - if let Generator(_, subs, _) = ty.kind { |
237 |
| - if match_type(cx, subs.as_generator().return_ty(def_id, cx.tcx), &paths::RESULT) { |
238 |
| - span_lint( |
239 |
| - cx, |
240 |
| - MISSING_ERRORS_DOC, |
241 |
| - span, |
242 |
| - "docs for function returning `Result` missing `# Errors` section", |
243 |
| - ); |
244 |
| - } |
245 |
| - } |
246 |
| - } |
| 227 | + } else { |
| 228 | + use TyKind::*; |
| 229 | + if_chain! { |
| 230 | + if let Some(body_id) = body_id; |
| 231 | + if let Some(future) = get_trait_def_id(cx, &paths::FUTURE); |
| 232 | + let def_id = cx.tcx.hir().body_owner_def_id(body_id); |
| 233 | + let mir = cx.tcx.optimized_mir(def_id); |
| 234 | + let ret_ty = mir.return_ty(); |
| 235 | + if implements_trait(cx, ret_ty, future, &[]); |
| 236 | + if let Opaque(_, subs) = ret_ty.kind; |
| 237 | + if let Some(ty) = subs.types().next(); |
| 238 | + if let Generator(_, subs, _) = ty.kind; |
| 239 | + if match_type(cx, subs.as_generator().return_ty(def_id, cx.tcx), &paths::RESULT); |
| 240 | + then { |
| 241 | + span_lint( |
| 242 | + cx, |
| 243 | + MISSING_ERRORS_DOC, |
| 244 | + span, |
| 245 | + "docs for function returning `Result` missing `# Errors` section", |
| 246 | + ); |
247 | 247 | }
|
248 | 248 | }
|
249 | 249 | }
|
|
0 commit comments