Skip to content

bool_to_enum assist should work on parameters #17400

Closed
@Veykril

Description

@Veykril

https://github.com/rust-lang/rust-analyzer/blob/4af21ffb026c7ec3a97a484ca27b36f703eb5fb1/crates/ide-assists/src/handlers/bool_to_enum.rs currently only works on "local variables, fields, constants, and statics", parameters should be included in the local variables part but that is not the case as we look for LetStmt here

if let Some(let_stmt) = name.syntax().ancestors().find_map(ast::LetStmt::cast) {
let bind_pat = match let_stmt.pat()? {
ast::Pat::IdentPat(pat) => pat,
_ => {
cov_mark::hit!(not_applicable_in_non_ident_pat);
return None;
}
};
let def = ctx.sema.to_def(&bind_pat)?;
if !def.ty(ctx.db()).is_bool() {
cov_mark::hit!(not_applicable_non_bool_local);
return None;
}
Some(BoolNodeData {
target_node: let_stmt.syntax().clone(),
name,
ty_annotation: let_stmt.ty(),
initializer: let_stmt.initializer(),
definition: Definition::Local(def),
})
} else if let Some(const_) = name.syntax().parent().and_then(ast::Const::cast) {
opposed to looking for patterns.

So instead of looking for the statement this should look for the IdentPat directly, then check if that is within a let statement or parameter and act accordingly.

Metadata

Metadata

Assignees

Labels

A-assistsC-featureCategory: feature requestE-has-instructionsIssue has some instructions and pointers to code to get started

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions