mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-29 06:23:25 +00:00
fix: add parenthesis for or-pattern
This commit is contained in:
parent
5caa56e18a
commit
5c97361622
2 changed files with 18 additions and 1 deletions
|
@ -599,12 +599,14 @@ impl Printer<'_> {
|
||||||
w!(self, ")");
|
w!(self, ")");
|
||||||
}
|
}
|
||||||
Pat::Or(pats) => {
|
Pat::Or(pats) => {
|
||||||
|
w!(self, "(");
|
||||||
for (i, pat) in pats.iter().enumerate() {
|
for (i, pat) in pats.iter().enumerate() {
|
||||||
if i != 0 {
|
if i != 0 {
|
||||||
w!(self, " | ");
|
w!(self, " | ");
|
||||||
}
|
}
|
||||||
self.print_pat(*pat);
|
self.print_pat(*pat);
|
||||||
}
|
}
|
||||||
|
w!(self, ")");
|
||||||
}
|
}
|
||||||
Pat::Record { path, args, ellipsis } => {
|
Pat::Record { path, args, ellipsis } => {
|
||||||
match path {
|
match path {
|
||||||
|
|
|
@ -8743,7 +8743,6 @@ fn foo() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_hover_function_with_pat_param() {
|
fn test_hover_function_with_pat_param() {
|
||||||
check(
|
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)
|
||||||
|
```
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue