]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/utils/higher.rs
Auto merge of #3680 - g-bartoszek:needless-bool-else-if-brackets, r=oli-obk
[rust.git] / clippy_lints / src / utils / higher.rs
index 992a3321c70079a615a255d97ebbfbf764b0adba..537cdf55eb146d5fff6cd0933aaa8877bab3db8f 100644 (file)
@@ -1,22 +1,13 @@
-// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
 //! This module contains functions for retrieve the original AST from lowered
 //! `hir`.
 
 #![deny(clippy::missing_docs_in_private_items)]
 
-use crate::rustc::lint::LateContext;
-use crate::rustc::{hir, ty};
-use crate::syntax::ast;
 use crate::utils::{is_expn_of, match_def_path, match_qpath, opt_def_id, paths, resolve_node};
 use if_chain::if_chain;
+use rustc::lint::LateContext;
+use rustc::{hir, ty};
+use syntax::ast;
 
 /// Convert a hir binary operator to the corresponding `ast` type.
 pub fn binop(op: hir::BinOpKind) -> ast::BinOpKind {
@@ -157,8 +148,8 @@ fn get_field<'a>(name: &str, fields: &'a [hir::Field]) -> Option<&'a hir::Expr>
     }
 }
 
-/// Checks if a `let` decl is from a `for` loop desugaring.
-pub fn is_from_for_desugar(decl: &hir::Decl) -> bool {
+/// Checks if a `let` statement is from a `for` loop desugaring.
+pub fn is_from_for_desugar(local: &hir::Local) -> bool {
     // This will detect plain for-loops without an actual variable binding:
     //
     // ```
@@ -167,8 +158,7 @@ pub fn is_from_for_desugar(decl: &hir::Decl) -> bool {
     // }
     // ```
     if_chain! {
-        if let hir::DeclKind::Local(ref loc) = decl.node;
-        if let Some(ref expr) = loc.init;
+        if let Some(ref expr) = local.init;
         if let hir::ExprKind::Match(_, _, hir::MatchSource::ForLoopDesugar) = expr.node;
         then {
             return true;
@@ -183,12 +173,8 @@ pub fn is_from_for_desugar(decl: &hir::Decl) -> bool {
     //     // anything
     // }
     // ```
-    if_chain! {
-        if let hir::DeclKind::Local(ref loc) = decl.node;
-        if let hir::LocalSource::ForLoopDesugar = loc.source;
-        then {
-            return true;
-        }
+    if let hir::LocalSource::ForLoopDesugar = local.source {
+        return true;
     }
 
     false
@@ -204,11 +190,10 @@ pub fn for_loop(expr: &hir::Expr) -> Option<(&hir::Pat, &hir::Expr, &hir::Expr)>
         if let hir::ExprKind::Loop(ref block, _, _) = arms[0].body.node;
         if block.expr.is_none();
         if let [ _, _, ref let_stmt, ref body ] = *block.stmts;
-        if let hir::StmtKind::Decl(ref decl, _) = let_stmt.node;
-        if let hir::DeclKind::Local(ref decl) = decl.node;
-        if let hir::StmtKind::Expr(ref expr, _) = body.node;
+        if let hir::StmtKind::Local(ref local) = let_stmt.node;
+        if let hir::StmtKind::Expr(ref expr) = body.node;
         then {
-            return Some((&*decl.pat, &iterargs[0], expr));
+            return Some((&*local.pat, &iterargs[0], expr));
         }
     }
     None