Replace if let Some(_) = foo with if foo.is_some()

This commit is contained in:
Aramis Razzaghipour 2021-10-03 23:51:30 +11:00
parent eff195852d
commit f29796da61
No known key found for this signature in database
GPG key ID: F788F7E990136003
6 changed files with 7 additions and 7 deletions

View file

@ -1119,7 +1119,7 @@ impl DefWithBody {
if let ast::Expr::RecordExpr(record_expr) = if let ast::Expr::RecordExpr(record_expr) =
&source_ptr.value.to_node(&root) &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( acc.push(
MissingFields { MissingFields {
file: source_ptr.file_id, file: source_ptr.file_id,
@ -1143,7 +1143,7 @@ impl DefWithBody {
if let Some(expr) = source_ptr.value.as_ref().left() { if let Some(expr) = source_ptr.value.as_ref().left() {
let root = source_ptr.file_syntax(db.upcast()); let root = source_ptr.file_syntax(db.upcast());
if let ast::Pat::RecordPat(record_pat) = expr.to_node(&root) { 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( acc.push(
MissingFields { MissingFields {
file: source_ptr.file_id, file: source_ptr.file_id,

View file

@ -156,7 +156,7 @@ fn rename_to_self(sema: &Semantics<RootDatabase>, local: hir::Local) -> RenameRe
_ => bail!("Cannot rename local to self outside of function"), _ => 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"); bail!("Method already has a self parameter");
} }

View file

@ -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; continue;
} }

View file

@ -44,7 +44,7 @@ pub(crate) fn convert_while_to_loop(acc: &mut Assists, ctx: &AssistContext) -> O
let cond = while_expr.condition()?; let cond = while_expr.condition()?;
// Don't handle while let // Don't handle while let
if let Some(_) = cond.pat() { if cond.pat().is_some() {
return None; return None;
}; };

View file

@ -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 { 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) { if let Some(ident_pat) = name.syntax().parent().and_then(ast::IdentPat::cast) {
cov_mark::hit!(rename_record_pat_field_name_split); cov_mark::hit!(rename_record_pat_field_name_split);
// Foo { ref mut field } -> Foo { new_name: ref mut field } // Foo { ref mut field } -> Foo { new_name: ref mut field }

View file

@ -455,7 +455,7 @@ impl ast::RecordExprField {
/// This will either replace the initializer, or in the case that this is a shorthand convert /// 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. /// the initializer into the name ref and insert the expr as the new initializer.
pub fn replace_expr(&self, expr: ast::Expr) { pub fn replace_expr(&self, expr: ast::Expr) {
if let Some(_) = self.name_ref() { if self.name_ref().is_some() {
match self.expr() { match self.expr() {
Some(prev) => ted::replace(prev.syntax(), expr.syntax()), Some(prev) => ted::replace(prev.syntax(), expr.syntax()),
None => ted::append_child(self.syntax(), expr.syntax()), None => ted::append_child(self.syntax(), expr.syntax()),