mirror of https://github.com/astral-sh/ruff
Use dyn dispatch for `any_over_*` (#6912)
This commit is contained in:
parent
3f3494ad44
commit
7c480236e0
|
|
@ -114,10 +114,7 @@ where
|
||||||
|
|
||||||
/// Call `func` over every `Expr` in `expr`, returning `true` if any expression
|
/// Call `func` over every `Expr` in `expr`, returning `true` if any expression
|
||||||
/// returns `true`..
|
/// returns `true`..
|
||||||
pub fn any_over_expr<F>(expr: &Expr, func: &F) -> bool
|
pub fn any_over_expr(expr: &Expr, func: &dyn Fn(&Expr) -> bool) -> bool {
|
||||||
where
|
|
||||||
F: Fn(&Expr) -> bool,
|
|
||||||
{
|
|
||||||
if func(expr) {
|
if func(expr) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -248,10 +245,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn any_over_type_param<F>(type_param: &TypeParam, func: &F) -> bool
|
pub fn any_over_type_param(type_param: &TypeParam, func: &dyn Fn(&Expr) -> bool) -> bool {
|
||||||
where
|
|
||||||
F: Fn(&Expr) -> bool,
|
|
||||||
{
|
|
||||||
match type_param {
|
match type_param {
|
||||||
TypeParam::TypeVar(ast::TypeParamTypeVar { bound, .. }) => bound
|
TypeParam::TypeVar(ast::TypeParamTypeVar { bound, .. }) => bound
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
|
@ -261,10 +255,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn any_over_pattern<F>(pattern: &Pattern, func: &F) -> bool
|
pub fn any_over_pattern(pattern: &Pattern, func: &dyn Fn(&Expr) -> bool) -> bool {
|
||||||
where
|
|
||||||
F: Fn(&Expr) -> bool,
|
|
||||||
{
|
|
||||||
match pattern {
|
match pattern {
|
||||||
Pattern::MatchValue(ast::PatternMatchValue { value, range: _ }) => {
|
Pattern::MatchValue(ast::PatternMatchValue { value, range: _ }) => {
|
||||||
any_over_expr(value, func)
|
any_over_expr(value, func)
|
||||||
|
|
@ -300,10 +291,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn any_over_stmt<F>(stmt: &Stmt, func: &F) -> bool
|
pub fn any_over_stmt(stmt: &Stmt, func: &dyn Fn(&Expr) -> bool) -> bool {
|
||||||
where
|
|
||||||
F: Fn(&Expr) -> bool,
|
|
||||||
{
|
|
||||||
match stmt {
|
match stmt {
|
||||||
Stmt::FunctionDef(ast::StmtFunctionDef {
|
Stmt::FunctionDef(ast::StmtFunctionDef {
|
||||||
parameters,
|
parameters,
|
||||||
|
|
@ -526,10 +514,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn any_over_body<F>(body: &[Stmt], func: &F) -> bool
|
pub fn any_over_body(body: &[Stmt], func: &dyn Fn(&Expr) -> bool) -> bool {
|
||||||
where
|
|
||||||
F: Fn(&Expr) -> bool,
|
|
||||||
{
|
|
||||||
body.iter().any(|stmt| any_over_stmt(stmt, func))
|
body.iter().any(|stmt| any_over_stmt(stmt, func))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue