Skip to content

Commit

Permalink
Use parent + and_then instead of ancestors
Browse files Browse the repository at this point in the history
  • Loading branch information
Veykril committed Sep 22, 2023
1 parent 25b1b3e commit 93562dd
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions crates/ide-assists/src/handlers/bool_to_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ fn find_bool_node(ctx: &AssistContext<'_>) -> Option<BoolNodeData> {
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);
Expand All @@ -125,7 +125,7 @@ fn find_bool_node(ctx: &AssistContext<'_>) -> Option<BoolNodeData> {
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);
Expand All @@ -140,7 +140,7 @@ fn find_bool_node(ctx: &AssistContext<'_>) -> Option<BoolNodeData> {
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;
}
Expand Down

0 comments on commit 93562dd

Please sign in to comment.