Use if_chain.

This commit is contained in:
daxpedda 2020-02-17 12:18:00 +01:00
parent d8716f5a3f
commit 8e2dab3b3c
No known key found for this signature in database
GPG Key ID: 43D62A3EA388E46F

View File

@ -1,4 +1,5 @@
use crate::utils::{get_trait_def_id, implements_trait, is_entrypoint_fn, match_type, paths, return_ty, span_lint};
use if_chain::if_chain;
use itertools::Itertools;
use rustc::lint::in_external_macro;
use rustc::ty::TyKind;
@ -223,18 +224,20 @@ fn lint_for_missing_headers<'a, 'tcx>(
span,
"docs for function returning `Result` missing `# Errors` section",
);
} else if let (Some(body_id), Some(future)) = (body_id, get_trait_def_id(cx, &paths::FUTURE)) {
} else {
use TyKind::*;
if_chain! {
if let Some(body_id) = body_id;
if let Some(future) = get_trait_def_id(cx, &paths::FUTURE);
let def_id = cx.tcx.hir().body_owner_def_id(body_id);
let mir = cx.tcx.optimized_mir(def_id);
let ret_ty = mir.return_ty();
if implements_trait(cx, ret_ty, future, &[]) {
use TyKind::*;
if let Opaque(_, subs) = ret_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) {
if implements_trait(cx, ret_ty, future, &[]);
if let Opaque(_, subs) = ret_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);
then {
span_lint(
cx,
MISSING_ERRORS_DOC,
@ -246,9 +249,6 @@ fn lint_for_missing_headers<'a, 'tcx>(
}
}
}
}
}
}
/// Cleanup documentation decoration (`///` and such).
///