Move more functions to utils::higher

This commit is contained in:
mcarton
2016-06-30 00:08:43 +02:00
parent 92b04129fe
commit 4dff4df577
8 changed files with 46 additions and 47 deletions

View File

@@ -21,7 +21,6 @@ use syntax::ptr::P;
pub mod cargo;
pub mod comparisons;
pub mod conf;
pub mod higher;
mod hir;
pub mod paths;
pub mod sugg;
@@ -82,6 +81,8 @@ macro_rules! if_let_chain {
};
}
pub mod higher;
/// Returns true if the two spans come from differing expansions (i.e. one is from a macro and one
/// isn't).
pub fn differing_macro_contexts(lhs: Span, rhs: Span) -> bool {
@@ -319,19 +320,6 @@ pub fn get_item_name(cx: &LateContext, expr: &Expr) -> Option<Name> {
}
}
/// Checks if a `let` decl is from a `for` loop desugaring.
pub fn is_from_for_desugar(decl: &Decl) -> bool {
if_let_chain! {[
let DeclLocal(ref loc) = decl.node,
let Some(ref expr) = loc.init,
let ExprMatch(_, _, MatchSource::ForLoopDesugar) = expr.node
], {
return true;
}}
false
}
/// Convert a span to a code snippet if available, otherwise use default.
///
/// # Example
@@ -706,25 +694,3 @@ pub fn same_tys<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, a: ty::Ty<'tcx>, b: ty::Ty
infcx.can_equate(&new_a, &new_b).is_ok()
})
}
/// Recover the essential nodes of a desugared for loop:
/// `for pat in arg { body }` becomes `(pat, arg, body)`.
pub fn recover_for_loop(expr: &Expr) -> Option<(&Pat, &Expr, &Expr)> {
if_let_chain! {[
let ExprMatch(ref iterexpr, ref arms, _) = expr.node,
let ExprCall(_, ref iterargs) = iterexpr.node,
iterargs.len() == 1 && arms.len() == 1 && arms[0].guard.is_none(),
let ExprLoop(ref block, _) = arms[0].body.node,
block.stmts.is_empty(),
let Some(ref loopexpr) = block.expr,
let ExprMatch(_, ref innerarms, MatchSource::ForLoopDesugar) = loopexpr.node,
innerarms.len() == 2 && innerarms[0].pats.len() == 1,
let PatKind::TupleStruct(_, ref somepats, _) = innerarms[0].pats[0].node,
somepats.len() == 1
], {
return Some((&somepats[0],
&iterargs[0],
&innerarms[0].body));
}}
None
}