Swap for_each_expr and for_each_expr_with_closures
This commit is contained in:
parent
680256f3ce
commit
e6040437ef
34 changed files with 81 additions and 81 deletions
|
|
@ -126,7 +126,7 @@ use visitors::Visitable;
|
|||
use crate::consts::{constant, mir_to_const, Constant};
|
||||
use crate::higher::Range;
|
||||
use crate::ty::{adt_and_variant_of_res, can_partially_move_ty, expr_sig, is_copy, is_recursively_primitive_type};
|
||||
use crate::visitors::for_each_expr;
|
||||
use crate::visitors::for_each_expr_without_closures;
|
||||
|
||||
use rustc_middle::hir::nested_filter;
|
||||
|
||||
|
|
@ -1313,7 +1313,7 @@ pub fn contains_name<'tcx>(name: Symbol, expr: &'tcx Expr<'_>, cx: &LateContext<
|
|||
|
||||
/// Returns `true` if `expr` contains a return expression
|
||||
pub fn contains_return<'tcx>(expr: impl Visitable<'tcx>) -> bool {
|
||||
for_each_expr(expr, |e| {
|
||||
for_each_expr_without_closures(expr, |e| {
|
||||
if matches!(e.kind, ExprKind::Ret(..)) {
|
||||
ControlFlow::Break(())
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#![allow(clippy::similar_names)] // `expr` and `expn`
|
||||
|
||||
use crate::visitors::{for_each_expr, Descend};
|
||||
use crate::visitors::{for_each_expr_without_closures, Descend};
|
||||
|
||||
use arrayvec::ArrayVec;
|
||||
use rustc_ast::{FormatArgs, FormatArgument, FormatPlaceholder};
|
||||
|
|
@ -323,7 +323,7 @@ fn find_assert_args_inner<'a, const N: usize>(
|
|||
Some(inner_name) => find_assert_within_debug_assert(cx, expr, expn, Symbol::intern(inner_name))?,
|
||||
};
|
||||
let mut args = ArrayVec::new();
|
||||
let panic_expn = for_each_expr(expr, |e| {
|
||||
let panic_expn = for_each_expr_without_closures(expr, |e| {
|
||||
if args.is_full() {
|
||||
match PanicExpn::parse(e) {
|
||||
Some(expn) => ControlFlow::Break(expn),
|
||||
|
|
@ -349,7 +349,7 @@ fn find_assert_within_debug_assert<'a>(
|
|||
expn: ExpnId,
|
||||
assert_name: Symbol,
|
||||
) -> Option<(&'a Expr<'a>, ExpnId)> {
|
||||
for_each_expr(expr, |e| {
|
||||
for_each_expr_without_closures(expr, |e| {
|
||||
if !e.span.from_expansion() {
|
||||
return ControlFlow::Continue(Descend::No);
|
||||
}
|
||||
|
|
@ -397,7 +397,7 @@ impl FormatArgsStorage {
|
|||
///
|
||||
/// See also [`find_format_arg_expr`]
|
||||
pub fn get(&self, cx: &LateContext<'_>, start: &Expr<'_>, expn_id: ExpnId) -> Option<&FormatArgs> {
|
||||
let format_args_expr = for_each_expr(start, |expr| {
|
||||
let format_args_expr = for_each_expr_without_closures(start, |expr| {
|
||||
let ctxt = expr.span.ctxt();
|
||||
if ctxt.outer_expn().is_descendant_of(expn_id) {
|
||||
if macro_backtrace(expr.span)
|
||||
|
|
@ -439,7 +439,7 @@ pub fn find_format_arg_expr<'hir, 'ast>(
|
|||
parent: _,
|
||||
} = target.expr.span.data();
|
||||
|
||||
for_each_expr(start, |expr| {
|
||||
for_each_expr_without_closures(start, |expr| {
|
||||
// When incremental compilation is enabled spans gain a parent during AST to HIR lowering,
|
||||
// since we're comparing an AST span to a HIR one we need to ignore the parent field
|
||||
let data = expr.span.data();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::source::snippet;
|
||||
use crate::visitors::{for_each_expr, Descend};
|
||||
use crate::visitors::{for_each_expr_without_closures, Descend};
|
||||
use crate::{path_to_local_id, strip_pat_refs};
|
||||
use core::ops::ControlFlow;
|
||||
use rustc_hir::{Body, BodyId, ExprKind, HirId, PatKind};
|
||||
|
|
@ -31,7 +31,7 @@ fn extract_clone_suggestions<'tcx>(
|
|||
body: &'tcx Body<'_>,
|
||||
) -> Option<Vec<(Span, Cow<'static, str>)>> {
|
||||
let mut spans = Vec::new();
|
||||
for_each_expr(body, |e| {
|
||||
for_each_expr_without_closures(body, |e| {
|
||||
if let ExprKind::MethodCall(seg, recv, [], _) = e.kind
|
||||
&& path_to_local_id(recv, id)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::visitors::{for_each_expr, for_each_expr_with_closures, Descend, Visitable};
|
||||
use crate::visitors::{for_each_expr, for_each_expr_without_closures, Descend, Visitable};
|
||||
use crate::{self as utils, get_enclosing_loop_or_multi_call_closure};
|
||||
use core::ops::ControlFlow;
|
||||
use hir::def::Res;
|
||||
|
|
@ -145,7 +145,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BindingUsageFinder<'a, 'tcx> {
|
|||
}
|
||||
|
||||
pub fn contains_return_break_continue_macro(expression: &Expr<'_>) -> bool {
|
||||
for_each_expr(expression, |e| {
|
||||
for_each_expr_without_closures(expression, |e| {
|
||||
match e.kind {
|
||||
ExprKind::Ret(..) | ExprKind::Break(..) | ExprKind::Continue(..) => ControlFlow::Break(()),
|
||||
// Something special could be done here to handle while or for loop
|
||||
|
|
@ -159,7 +159,7 @@ pub fn contains_return_break_continue_macro(expression: &Expr<'_>) -> bool {
|
|||
}
|
||||
|
||||
pub fn local_used_in<'tcx>(cx: &LateContext<'tcx>, local_id: HirId, v: impl Visitable<'tcx>) -> bool {
|
||||
for_each_expr_with_closures(cx, v, |e| {
|
||||
for_each_expr(cx, v, |e| {
|
||||
if utils::path_to_local_id(e, local_id) {
|
||||
ControlFlow::Break(())
|
||||
} else {
|
||||
|
|
@ -184,7 +184,7 @@ pub fn local_used_after_expr(cx: &LateContext<'_>, local_id: HirId, after: &Expr
|
|||
let loop_start = get_enclosing_loop_or_multi_call_closure(cx, after).map(|e| e.hir_id);
|
||||
|
||||
let mut past_expr = false;
|
||||
for_each_expr_with_closures(cx, block, |e| {
|
||||
for_each_expr(cx, block, |e| {
|
||||
if past_expr {
|
||||
if utils::path_to_local_id(e, local_id) {
|
||||
ControlFlow::Break(())
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ visitable_ref!(Stmt, visit_stmt);
|
|||
|
||||
/// Calls the given function once for each expression contained. This does not enter any bodies or
|
||||
/// nested items.
|
||||
pub fn for_each_expr<'tcx, B, C: Continue>(
|
||||
pub fn for_each_expr_without_closures<'tcx, B, C: Continue>(
|
||||
node: impl Visitable<'tcx>,
|
||||
f: impl FnMut(&'tcx Expr<'tcx>) -> ControlFlow<B, C>,
|
||||
) -> Option<B> {
|
||||
|
|
@ -134,7 +134,7 @@ pub fn for_each_expr<'tcx, B, C: Continue>(
|
|||
|
||||
/// Calls the given function once for each expression contained. This will enter bodies, but not
|
||||
/// nested items.
|
||||
pub fn for_each_expr_with_closures<'tcx, B, C: Continue>(
|
||||
pub fn for_each_expr<'tcx, B, C: Continue>(
|
||||
cx: &LateContext<'tcx>,
|
||||
node: impl Visitable<'tcx>,
|
||||
f: impl FnMut(&'tcx Expr<'tcx>) -> ControlFlow<B, C>,
|
||||
|
|
@ -181,7 +181,7 @@ pub fn for_each_expr_with_closures<'tcx, B, C: Continue>(
|
|||
|
||||
/// returns `true` if expr contains match expr desugared from try
|
||||
fn contains_try(expr: &Expr<'_>) -> bool {
|
||||
for_each_expr(expr, |e| {
|
||||
for_each_expr_without_closures(expr, |e| {
|
||||
if matches!(e.kind, ExprKind::Match(_, _, hir::MatchSource::TryDesugar(_))) {
|
||||
ControlFlow::Break(())
|
||||
} else {
|
||||
|
|
@ -286,7 +286,7 @@ where
|
|||
|
||||
/// Checks if the given resolved path is used in the given body.
|
||||
pub fn is_res_used(cx: &LateContext<'_>, res: Res, body: BodyId) -> bool {
|
||||
for_each_expr_with_closures(cx, cx.tcx.hir().body(body).value, |e| {
|
||||
for_each_expr(cx, cx.tcx.hir().body(body).value, |e| {
|
||||
if let ExprKind::Path(p) = &e.kind {
|
||||
if cx.qpath_res(p, e.hir_id) == res {
|
||||
return ControlFlow::Break(());
|
||||
|
|
@ -299,7 +299,7 @@ pub fn is_res_used(cx: &LateContext<'_>, res: Res, body: BodyId) -> bool {
|
|||
|
||||
/// Checks if the given local is used.
|
||||
pub fn is_local_used<'tcx>(cx: &LateContext<'tcx>, visitable: impl Visitable<'tcx>, id: HirId) -> bool {
|
||||
for_each_expr_with_closures(cx, visitable, |e| {
|
||||
for_each_expr(cx, visitable, |e| {
|
||||
if path_to_local_id(e, id) {
|
||||
ControlFlow::Break(())
|
||||
} else {
|
||||
|
|
@ -757,7 +757,7 @@ pub fn for_each_local_assignment<'tcx, B>(
|
|||
}
|
||||
|
||||
pub fn contains_break_or_continue(expr: &Expr<'_>) -> bool {
|
||||
for_each_expr(expr, |e| {
|
||||
for_each_expr_without_closures(expr, |e| {
|
||||
if matches!(e.kind, ExprKind::Break(..) | ExprKind::Continue(..)) {
|
||||
ControlFlow::Break(())
|
||||
} else {
|
||||
|
|
@ -776,7 +776,7 @@ pub fn local_used_once<'tcx>(
|
|||
) -> Option<&'tcx Expr<'tcx>> {
|
||||
let mut expr = None;
|
||||
|
||||
let cf = for_each_expr_with_closures(cx, visitable, |e| {
|
||||
let cf = for_each_expr(cx, visitable, |e| {
|
||||
if path_to_local_id(e, id) && expr.replace(e).is_some() {
|
||||
ControlFlow::Break(())
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue