Repository: intellij-rust/intellij-rust
Issue: Formatting makes code to comment

```rust
        if num[0] == 2 && num[1] == 2 {
            let (p1, p2) =
            // 1 1 2 2 3
                if values[3]!=values[4] { (values[0], values[2]) }
            // 1 2 2 3 3
                else if values[0]!=values[1] { (values[1], values[3]) }
            // 1 1 2 3 3
                else { (values[0], values[4]) };

            return (3, p1.max(p2) as u32*15 + p1.min(p2) as u32, highest);
        }
```
is formatted to
```rust
        if num[0] == 2 && num[1] == 2 {
            let (p1, p2) =
            // 1 1 2 2 3
                if values[3] != values[4] { (values[0], values[2]) }
                    // 1 2 2 3 3 else if values[0] != values[1] { (values[1], values[3]) }
                    // 1 1 2 3 3 else { (values[0], values[4]) };

            return (3, p1.max(p2) as u32 * 15 + p1.min(p2) as u32, highest);
        }
```

Changed files:
src/test/kotlin/org/rust/ide/formatter/RsFormatterLineBreaksTest.kt, src/main/kotlin/org/rust/ide/formatter/impl/indent.kt, src/main/kotlin/org/rust/ide/formatter/impl/spacing.kt, src/test/kotlin/org/rust/ide/formatter/RsAutoIndentTest.kt

diff --git a/src/main/kotlin/org/rust/ide/formatter/impl/indent.kt b/src/main/kotlin/org/rust/ide/formatter/impl/indent.kt
index a0335915d..161a46e73 100644
--- a/src/main/kotlin/org/rust/ide/formatter/impl/indent.kt
+++ b/src/main/kotlin/org/rust/ide/formatter/impl/indent.kt
@@ -11,6 +11,7 @@ import org.rust.ide.formatter.RsFmtContext
 import org.rust.ide.formatter.blocks.RsFmtBlock
 import org.rust.lang.core.psi.RsElementTypes.*
 import org.rust.lang.core.psi.RsExpr
+import org.rust.lang.core.psi.RsIfExpr
 
 fun RsFmtBlock.computeIndent(child: ASTNode, childCtx: RsFmtContext): Indent? {
     val parentType = node.elementType
@@ -39,15 +40,21 @@ fun RsFmtBlock.computeIndent(child: ASTNode, childCtx: RsFmtContext): Indent? {
                 Indent.getNoneIndent()
             }
 
-    //     let_ =
+    //  Indent let declarations
+        parentType == LET_DECL -> Indent.getContinuationWithoutFirstIndent()
+
+    //     let _ =
     //     92;
     // =>
     //     let _ =>
     //         92;
-        childPsi is RsExpr && (parentType == MATCH_ARM || parentType == LET_DECL || parentType == CONSTANT) ->
+        childPsi is RsExpr && (parentType == MATCH_ARM || parentType == CONSTANT) ->
             Indent.getNormalIndent()
 
-    // Indent expressions (chain calls, binary expressions, ...)
+    // Indent if-expressions
+        parentPsi is RsIfExpr -> Indent.getNoneIndent()
+
+    // Indent other expressions (chain calls, binary expressions, ...)
         parentPsi is RsExpr -> Indent.getContinuationWithoutFirstIndent()
 
     // Where clause bounds
diff --git a/src/main/kotlin/org/rust/ide/formatter/impl/spacing.kt b/src/main/kotlin/org/rust/ide/formatter/impl/spacing.kt
index 5f347cdef..6ac4700d4 100644
--- a/src/main/kotlin/org/rust/ide/formatter/impl/spacing.kt
+++ b/src/main/kotlin/org/rust/ide/formatter/impl/spacing.kt
@@ -133,7 +133,7 @@ fun createSpacingBuilder(commonSettings: CommonCodeStyleSettings, rustSettings:
         .beforeInside(LBRACK, INDEX_EXPR).spaces(0)
         .afterInside(VALUE_PARAMETER_LIST, LAMBDA_EXPR).spacing(1, 1, 0, true, 1)
         .between(MATCH_ARM, MATCH_ARM).spacing(1, 1, if (rustSettings.ALLOW_ONE_LINE_MATCH) 0 else 1, true, 1)
-        .before(ELSE_BRANCH).spacing(1, 1, 0, false, 0)
+        .between(BLOCK, ELSE_BRANCH).spacing(1, 1, 0, false, 0)
         .betweenInside(ELSE, BLOCK, ELSE_BRANCH).spacing(1, 1, 0, false, 0)
 
         //== macros
diff --git a/src/test/kotlin/org/rust/ide/formatter/RsAutoIndentTest.kt b/src/test/kotlin/org/rust/ide/formatter/RsAutoIndentTest.kt
index 405f95374..34434934f 100644
--- a/src/test/kotlin/org/rust/ide/formatter/RsAutoIndentTest.kt
+++ b/src/test/kotlin/org/rust/ide/formatter/RsAutoIndentTest.kt
@@ -120,7 +120,7 @@ class RsAutoIndentTest : RsTypingTestBase() {
         fn main() {
             let moo = foo().bar().baz()
                            .moo()
-            /*caret*/;
+                /*caret*/;
         }
     """)
 
diff --git a/src/test/kotlin/org/rust/ide/formatter/RsFormatterLineBreaksTest.kt b/src/test/kotlin/org/rust/ide/formatter/RsFormatterLineBreaksTest.kt
index dca9020b5..df90c2cb3 100644
--- a/src/test/kotlin/org/rust/ide/formatter/RsFormatterLineBreaksTest.kt
+++ b/src/test/kotlin/org/rust/ide/formatter/RsFormatterLineBreaksTest.kt
@@ -246,4 +246,34 @@ class RsFormatterLineBreaksTest : RsFormatterTestBase() {
             };
         }
 """)
+
+    fun `test if-expressions`() = doTextTest("""
+        fn main() {
+            let _ =
+                if (true) { true }
+                else if (false) { false }
+                else { true };
+
+            let _ =
+                // comment 1
+                if (true) { true }
+                // comment 2
+                else if (false) { false }
+                // comment 3
+                else { true };
+        }
+    """, """
+        fn main() {
+            let _ =
+                if (true) { true } else if (false) { false } else { true };
+
+            let _ =
+                // comment 1
+                if (true) { true }
+                // comment 2
+                else if (false) { false }
+                // comment 3
+                else { true };
+        }
+""")
 }