Skip to content

Commit

Permalink
Replace if let Some(_) = foo with if let foo.is_some()
Browse files Browse the repository at this point in the history
  • Loading branch information
lunacookies committed Oct 3, 2021
1 parent eff1958 commit f3d30c2
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions crates/hir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@ impl DefWithBody {
if let ast::Expr::RecordExpr(record_expr) =
&source_ptr.value.to_node(&root)
{
if let Some(_) = record_expr.record_expr_field_list() {
if record_expr.record_expr_field_list().is_some() {
acc.push(
MissingFields {
file: source_ptr.file_id,
Expand All @@ -1143,7 +1143,7 @@ impl DefWithBody {
if let Some(expr) = source_ptr.value.as_ref().left() {
let root = source_ptr.file_syntax(db.upcast());
if let ast::Pat::RecordPat(record_pat) = expr.to_node(&root) {
if let Some(_) = record_pat.record_pat_field_list() {
if record_pat.record_pat_field_list().is_some() {
acc.push(
MissingFields {
file: source_ptr.file_id,
Expand Down
2 changes: 1 addition & 1 deletion crates/ide/src/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ fn rename_to_self(sema: &Semantics<RootDatabase>, local: hir::Local) -> RenameRe
_ => bail!("Cannot rename local to self outside of function"),
};

if let Some(_) = fn_def.self_param(sema.db) {
if fn_def.self_param(sema.db).is_some() {
bail!("Method already has a self parameter");
}

Expand Down
2 changes: 1 addition & 1 deletion crates/ide/src/syntax_highlighting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ fn traverse(
}
}

if let Some(_) = macro_highlighter.highlight(element_to_highlight.clone()) {
if macro_highlighter.highlight(element_to_highlight.clone()).is_some() {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion crates/ide_assists/src/handlers/convert_while_to_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub(crate) fn convert_while_to_loop(acc: &mut Assists, ctx: &AssistContext) -> O
let cond = while_expr.condition()?;

// Don't handle while let
if let Some(_) = cond.pat() {
if cond.pat().is_some() {
return None;
};

Expand Down
2 changes: 1 addition & 1 deletion crates/ide_db/src/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ pub fn source_edit_from_references(
}

fn source_edit_from_name(edit: &mut TextEditBuilder, name: &ast::Name, new_name: &str) -> bool {
if let Some(_) = ast::RecordPatField::for_field_name(name) {
if ast::RecordPatField::for_field_name(name).is_some() {
if let Some(ident_pat) = name.syntax().parent().and_then(ast::IdentPat::cast) {
cov_mark::hit!(rename_record_pat_field_name_split);
// Foo { ref mut field } -> Foo { new_name: ref mut field }
Expand Down
2 changes: 1 addition & 1 deletion crates/syntax/src/ast/edit_in_place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ impl ast::RecordExprField {
/// This will either replace the initializer, or in the case that this is a shorthand convert
/// the initializer into the name ref and insert the expr as the new initializer.
pub fn replace_expr(&self, expr: ast::Expr) {
if let Some(_) = self.name_ref() {
if self.name_ref().is_some() {
match self.expr() {
Some(prev) => ted::replace(prev.syntax(), expr.syntax()),
None => ted::append_child(self.syntax(), expr.syntax()),
Expand Down

0 comments on commit f3d30c2

Please sign in to comment.