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