Unnamed repository; edit this file 'description' to name the repository.
fix: add parenthesis for or-pattern
roife 2024-09-09
parent 5caa56e · commit 5c97361
-rw-r--r--crates/hir-def/src/body/pretty.rs2
-rw-r--r--crates/ide/src/hover/tests.rs17
2 files changed, 18 insertions, 1 deletions
diff --git a/crates/hir-def/src/body/pretty.rs b/crates/hir-def/src/body/pretty.rs
index 3333956adb..64d0c16f52 100644
--- a/crates/hir-def/src/body/pretty.rs
+++ b/crates/hir-def/src/body/pretty.rs
@@ -599,12 +599,14 @@ impl Printer<'_> {
w!(self, ")");
}
Pat::Or(pats) => {
+ w!(self, "(");
for (i, pat) in pats.iter().enumerate() {
if i != 0 {
w!(self, " | ");
}
self.print_pat(*pat);
}
+ w!(self, ")");
}
Pat::Record { path, args, ellipsis } => {
match path {
diff --git a/crates/ide/src/hover/tests.rs b/crates/ide/src/hover/tests.rs
index d1e51a2d28..1a97d99f05 100644
--- a/crates/ide/src/hover/tests.rs
+++ b/crates/ide/src/hover/tests.rs
@@ -8743,7 +8743,6 @@ fn foo() {
);
}
-
#[test]
fn test_hover_function_with_pat_param() {
check(
@@ -8856,4 +8855,20 @@ fn test_hover_function_with_pat_param() {
```
"#]],
);
+
+ // Test case with Enum and Or pattern
+ check(
+ r#"enum MyEnum { A(i32), B(i32) } fn test_8$0((MyEnum::A(x) | MyEnum::B(x)): MyEnum) {}"#,
+ expect![[r#"
+ *test_8*
+
+ ```rust
+ test
+ ```
+
+ ```rust
+ fn test_8((MyEnum::A(x) | MyEnum::B(x)): MyEnum)
+ ```
+ "#]],
+ );
}