Skip to content

Commit

Permalink
Use if_chain.
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda committed Feb 17, 2020
1 parent d8716f5 commit 8e2dab3
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions clippy_lints/src/doc.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -223,27 +224,26 @@ 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)) {
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) {
span_lint(
cx,
MISSING_ERRORS_DOC,
span,
"docs for function returning `Result` missing `# Errors` section",
);
}
}
}
} 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, &[]);
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,
span,
"docs for function returning `Result` missing `# Errors` section",
);
}
}
}
Expand Down

0 comments on commit 8e2dab3

Please sign in to comment.