1
Fork 0

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 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 itertools::Itertools;
use rustc::lint::in_external_macro; use rustc::lint::in_external_macro;
use rustc::ty::TyKind; use rustc::ty::TyKind;
@ -223,27 +224,26 @@ fn lint_for_missing_headers<'a, 'tcx>(
span, span,
"docs for function returning `Result` missing `# Errors` section", "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 {
let def_id = cx.tcx.hir().body_owner_def_id(body_id); use TyKind::*;
let mir = cx.tcx.optimized_mir(def_id); if_chain! {
let ret_ty = mir.return_ty(); if let Some(body_id) = body_id;
if let Some(future) = get_trait_def_id(cx, &paths::FUTURE);
if implements_trait(cx, ret_ty, future, &[]) { let def_id = cx.tcx.hir().body_owner_def_id(body_id);
use TyKind::*; let mir = cx.tcx.optimized_mir(def_id);
let ret_ty = mir.return_ty();
if let Opaque(_, subs) = ret_ty.kind { if implements_trait(cx, ret_ty, future, &[]);
if let Some(ty) = subs.types().next() { if let Opaque(_, subs) = ret_ty.kind;
if let Generator(_, subs, _) = ty.kind { if let Some(ty) = subs.types().next();
if match_type(cx, subs.as_generator().return_ty(def_id, cx.tcx), &paths::RESULT) { if let Generator(_, subs, _) = ty.kind;
span_lint( if match_type(cx, subs.as_generator().return_ty(def_id, cx.tcx), &paths::RESULT);
cx, then {
MISSING_ERRORS_DOC, span_lint(
span, cx,
"docs for function returning `Result` missing `# Errors` section", MISSING_ERRORS_DOC,
); span,
} "docs for function returning `Result` missing `# Errors` section",
} );
}
} }
} }
} }