]> git.lizzy.rs Git - rust.git/blobdiff - crates/ide_assists/src/handlers/pull_assignment_up.rs
Merge #11481
[rust.git] / crates / ide_assists / src / handlers / pull_assignment_up.rs
index f07b8a6c0d53de5c25a9ac4e78eed97912a656ec..d142397c24f0b525df9277698d3f1afbf5e26f73 100644 (file)
@@ -39,7 +39,7 @@ pub(crate) fn pull_assignment_up(acc: &mut Assists, ctx: &AssistContext) -> Opti
     let assign_expr = ctx.find_node_at_offset::<ast::BinExpr>()?;
 
     let op_kind = assign_expr.op_kind()?;
-    if op_kind != ast::BinOp::Assignment {
+    if op_kind != (ast::BinaryOp::Assignment { op: None }) {
         cov_mark::hit!(test_cant_pull_non_assignments);
         return None;
     }
@@ -127,12 +127,9 @@ fn collect_if(&mut self, if_expr: &ast::IfExpr) -> Option<()> {
         }
     }
     fn collect_block(&mut self, block: &ast::BlockExpr) -> Option<()> {
-        let last_expr = block.tail_expr().or_else(|| {
-            if let ast::Stmt::ExprStmt(stmt) = block.statements().last()? {
-                stmt.expr()
-            } else {
-                None
-            }
+        let last_expr = block.tail_expr().or_else(|| match block.statements().last()? {
+            ast::Stmt::ExprStmt(stmt) => stmt.expr(),
+            ast::Stmt::Item(_) | ast::Stmt::LetStmt(_) => None,
         })?;
 
         if let ast::Expr::BinExpr(expr) = last_expr {
@@ -143,7 +140,7 @@ fn collect_block(&mut self, block: &ast::BlockExpr) -> Option<()> {
     }
 
     fn collect_expr(&mut self, expr: &ast::BinExpr) -> Option<()> {
-        if expr.op_kind()? == ast::BinOp::Assignment
+        if expr.op_kind()? == (ast::BinaryOp::Assignment { op: None })
             && is_equivalent(self.sema, &expr.lhs()?, &self.common_lhs)
         {
             self.assignments.push((expr.clone(), expr.rhs()?));
@@ -173,8 +170,8 @@ fn is_equivalent(
             }
         }
         (ast::Expr::PrefixExpr(prefix0), ast::Expr::PrefixExpr(prefix1))
-            if prefix0.op_kind() == Some(ast::PrefixOp::Deref)
-                && prefix1.op_kind() == Some(ast::PrefixOp::Deref) =>
+            if prefix0.op_kind() == Some(ast::UnaryOp::Deref)
+                && prefix1.op_kind() == Some(ast::UnaryOp::Deref) =>
         {
             cov_mark::hit!(test_pull_assignment_up_deref);
             if let (Some(prefix0), Some(prefix1)) = (prefix0.expr(), prefix1.expr()) {