-// 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 {
}
}
-/// 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:
//
// ```
// }
// ```
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;
// // 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
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