More if_chain

This commit is contained in:
Josh Holmer 2018-09-03 23:58:10 -04:00
parent 48e6be42d7
commit ed9cd1530d

View file

@ -2271,13 +2271,13 @@ impl<'a, 'tcx> Visitor<'tcx> for VarCollectorVisitor<'a, 'tcx> {
const NEEDLESS_COLLECT_MSG: &str = "avoid using `collect()` when not needed";
fn check_needless_collect<'a, 'tcx>(expr: &'tcx Expr, cx: &LateContext<'a, 'tcx>) {
if let ExprKind::MethodCall(ref method, _, ref args) = expr.node {
if let ExprKind::MethodCall(ref chain_method, _, _) = args[0].node {
if chain_method.ident.name == "collect" &&
match_trait_method(cx, &args[0], &paths::ITERATOR) &&
chain_method.args.is_some() {
let generic_args = chain_method.args.as_ref().unwrap();
if let Some(GenericArg::Type(ref ty)) = generic_args.args.get(0) {
if_chain! {
if let ExprKind::MethodCall(ref method, _, ref args) = expr.node;
if let ExprKind::MethodCall(ref chain_method, _, _) = args[0].node;
if chain_method.ident.name == "collect" && match_trait_method(cx, &args[0], &paths::ITERATOR);
if let Some(ref generic_args) = chain_method.args;
if let Some(GenericArg::Type(ref ty)) = generic_args.args.get(0);
then {
let ty = cx.tables.node_id_to_type(ty.hir_id);
if match_type(cx, ty, &paths::VEC) ||
match_type(cx, ty, &paths::VEC_DEQUE) ||
@ -2323,8 +2323,6 @@ fn check_needless_collect<'a, 'tcx>(expr: &'tcx Expr, cx: &LateContext<'a, 'tcx>
}
}
}
}
}
}
fn shorten_needless_collect_span(expr: &Expr) -> Span {