From 93562dd5bdec82c70b8eff05c59badb4314c90c8 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Fri, 22 Sep 2023 08:53:24 +0200 Subject: [PATCH] Use parent + and_then instead of ancestors --- crates/ide-assists/src/handlers/bool_to_enum.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/ide-assists/src/handlers/bool_to_enum.rs b/crates/ide-assists/src/handlers/bool_to_enum.rs index b9dbd6e98fc..85b0b87d0c9 100644 --- a/crates/ide-assists/src/handlers/bool_to_enum.rs +++ b/crates/ide-assists/src/handlers/bool_to_enum.rs @@ -111,7 +111,7 @@ fn find_bool_node(ctx: &AssistContext<'_>) -> Option { initializer: let_stmt.initializer(), definition: Definition::Local(def), }) - } else if let Some(const_) = name.syntax().ancestors().find_map(ast::Const::cast) { + } else if let Some(const_) = name.syntax().parent().and_then(ast::Const::cast) { let def = ctx.sema.to_def(&const_)?; if !def.ty(ctx.db()).is_bool() { cov_mark::hit!(not_applicable_non_bool_const); @@ -125,7 +125,7 @@ fn find_bool_node(ctx: &AssistContext<'_>) -> Option { initializer: const_.body(), definition: Definition::Const(def), }) - } else if let Some(static_) = name.syntax().ancestors().find_map(ast::Static::cast) { + } else if let Some(static_) = name.syntax().parent().and_then(ast::Static::cast) { let def = ctx.sema.to_def(&static_)?; if !def.ty(ctx.db()).is_bool() { cov_mark::hit!(not_applicable_non_bool_static); @@ -140,7 +140,7 @@ fn find_bool_node(ctx: &AssistContext<'_>) -> Option { definition: Definition::Static(def), }) } else { - let field = name.syntax().ancestors().find_map(ast::RecordField::cast)?; + let field = name.syntax().parent().and_then(ast::RecordField::cast)?; if field.name()? != name { return None; }