Skip to content

Commit 5c97361

Browse files
committed
fix: add parenthesis for or-pattern
1 parent 5caa56e commit 5c97361

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

crates/hir-def/src/body/pretty.rs

+2
Original file line numberDiff line numberDiff line change
@@ -599,12 +599,14 @@ impl Printer<'_> {
599599
w!(self, ")");
600600
}
601601
Pat::Or(pats) => {
602+
w!(self, "(");
602603
for (i, pat) in pats.iter().enumerate() {
603604
if i != 0 {
604605
w!(self, " | ");
605606
}
606607
self.print_pat(*pat);
607608
}
609+
w!(self, ")");
608610
}
609611
Pat::Record { path, args, ellipsis } => {
610612
match path {

crates/ide/src/hover/tests.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -8743,7 +8743,6 @@ fn foo() {
87438743
);
87448744
}
87458745

8746-
87478746
#[test]
87488747
fn test_hover_function_with_pat_param() {
87498748
check(
@@ -8856,4 +8855,20 @@ fn test_hover_function_with_pat_param() {
88568855
```
88578856
"#]],
88588857
);
8858+
8859+
// Test case with Enum and Or pattern
8860+
check(
8861+
r#"enum MyEnum { A(i32), B(i32) } fn test_8$0((MyEnum::A(x) | MyEnum::B(x)): MyEnum) {}"#,
8862+
expect![[r#"
8863+
*test_8*
8864+
8865+
```rust
8866+
test
8867+
```
8868+
8869+
```rust
8870+
fn test_8((MyEnum::A(x) | MyEnum::B(x)): MyEnum)
8871+
```
8872+
"#]],
8873+
);
88598874
}

0 commit comments

Comments
 (0)