Repository: intellij-rust/intellij-rust
Issue: Leading `|` in nested patterns are incorrectly rejected

## Environment

* **IntelliJ Rust plugin version:** `0.4.173.4714-221`
* **Rust toolchain version:** `1.63.0-nightly`
* **IDE name and version:** CLion 2022.1.3
* **Operating system:** Windows 11 + WSL2 (development in WSL2)

## Problem description

Intellij-rust does not accept leading `|` in nested patterns, even though it is legal syntax.

## Steps to reproduce

The following code is valid rust code:
```rust
fn main() {
    match Some(5) {
        Some(
            | 6
            | 7
        ) => true,
        | None
        | None => false,
        _ => false,
    };
}
```
[Playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=a015e1ba7ea626c2b15014b8d5cbcc26)

But intellij-rust emits an error

```
a leading `|` is only allowed in a top-level pattern
```

Changed files:
src/main/kotlin/org/rust/ide/annotator/RsErrorAnnotator.kt, src/test/kotlin/org/rust/ide/annotator/RsErrorAnnotatorTest.kt

diff --git a/src/main/kotlin/org/rust/ide/annotator/RsErrorAnnotator.kt b/src/main/kotlin/org/rust/ide/annotator/RsErrorAnnotator.kt
index 282bf0e59..1fa6c5249 100644
--- a/src/main/kotlin/org/rust/ide/annotator/RsErrorAnnotator.kt
+++ b/src/main/kotlin/org/rust/ide/annotator/RsErrorAnnotator.kt
@@ -197,17 +197,6 @@ class RsErrorAnnotator : AnnotatorBase(), HighlightRangeExtension {
     private fun checkOrPat(holder: RsAnnotationHolder, orPat: RsOrPat) {
         val parent = orPat.context
 
-        if (parent is RsPat) {
-            val firstChild = orPat.firstChild
-            if (firstChild?.elementType == RsElementTypes.OR) {
-                holder.createErrorAnnotation(
-                    firstChild,
-                    "a leading `|` is only allowed in a top-level pattern",
-                    RemoveElementFix(firstChild)
-                )
-            }
-        }
-
         if (parent !is RsCondition && parent !is RsMatchArm) {
             OR_PATTERNS.check(holder, orPat, "or-patterns syntax")
         }
diff --git a/src/test/kotlin/org/rust/ide/annotator/RsErrorAnnotatorTest.kt b/src/test/kotlin/org/rust/ide/annotator/RsErrorAnnotatorTest.kt
index 8a63029ed..2a384179e 100644
--- a/src/test/kotlin/org/rust/ide/annotator/RsErrorAnnotatorTest.kt
+++ b/src/test/kotlin/org/rust/ide/annotator/RsErrorAnnotatorTest.kt
@@ -2217,8 +2217,22 @@ class RsErrorAnnotatorTest : RsAnnotatorTestBase(RsErrorAnnotator::class) {
         }
     """)
 
+    @MockRustcVersion("1.53.0")
+    fun `test non top level or patterns E0658 3`() = checkErrors("""
+        enum Option<T> { None, Some(T) }
+        enum V { V1(i32), V2(i32) }
+        fn foo(y: V) {
+            if let Option::Some(V::V1(x) | V::V2(x)) = y {}
+            while let Option::Some(V::V1(x) | V::V2(x)) = y {}
+            match y {
+                Option::Some(V::V1(x) | V::V2(x)) => {},
+                _ => {}
+            }
+        }
+    """)
+
     @MockRustcVersion("1.38.0-nightly")
-    fun `test leading vertical bar in or patterns 1`() = checkErrors("""
+    fun `test leading vertical bar in toplevel or patterns`() = checkErrors("""
         #![feature(or_patterns)]
         enum V { V1(i32), V2(i32) }
         fn foo(y: V, z: V) {
@@ -2229,20 +2243,17 @@ class RsErrorAnnotatorTest : RsAnnotatorTestBase(RsErrorAnnotator::class) {
         }
     """)
 
-    @MockRustcVersion("1.38.0-nightly")
-    fun `test leading vertical bar in or patterns 2`() = checkFixByText("Remove `|`", """
-        #![feature(or_patterns)]
-        enum Option<T> { None, Some(T) }
-        enum V { V1(i32), V2(i32) }
-        fn foo(y: Option<V>) {
-            while let Option::Some(<error descr="a leading `|` is only allowed in a top-level pattern">|/*caret*/</error> V::V1(x) | V::V2(x)) = y {}
-        }
-    """, """
-        #![feature(or_patterns)]
+    @MockRustcVersion("1.53.0")
+    fun `test leading vertical bar in nested or patterns`() = checkErrors("""
         enum Option<T> { None, Some(T) }
         enum V { V1(i32), V2(i32) }
         fn foo(y: Option<V>) {
-            while let Option::Some(/*caret*/V::V1(x) | V::V2(x)) = y {}
+            while let Option::Some(|/*caret*/ V::V1(x) | V::V2(x)) = &y {}
+            if let (| Option::None | Option::Some(_), _) = (&y, &y) {}
+            match &[y] {
+                [.., | Option::None | Option::Some(_)] => {},
+                _ => {}
+            }
         }
     """)