diff options
| author | roife <roifewu@gmail.com> | 2024-09-09 03:55:59 +0800 |
|---|---|---|
| committer | roife <roifewu@gmail.com> | 2024-09-09 20:59:23 +0800 |
| commit | cbfa3578134e09a5a296cba3dc8b7951569ca603 (patch) | |
| tree | 3dab7b65ac8ff9bc2aa37e750bcdae0f4189d444 | |
| parent | 81fae18c9e3eff9b69a466beba9e7081278b3a90 (diff) | |
| download | rust-cbfa3578134e09a5a296cba3dc8b7951569ca603.tar.gz rust-cbfa3578134e09a5a296cba3dc8b7951569ca603.zip | |
fix: add parenthesis for or-pattern
| -rw-r--r-- | src/tools/rust-analyzer/crates/hir-def/src/body/pretty.rs | 2 | ||||
| -rw-r--r-- | src/tools/rust-analyzer/crates/ide/src/hover/tests.rs | 17 |
2 files changed, 18 insertions, 1 deletions
diff --git a/src/tools/rust-analyzer/crates/hir-def/src/body/pretty.rs b/src/tools/rust-analyzer/crates/hir-def/src/body/pretty.rs index 3333956adb2..64d0c16f525 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/body/pretty.rs +++ b/src/tools/rust-analyzer/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/src/tools/rust-analyzer/crates/ide/src/hover/tests.rs b/src/tools/rust-analyzer/crates/ide/src/hover/tests.rs index d1e51a2d28a..1a97d99f051 100644 --- a/src/tools/rust-analyzer/crates/ide/src/hover/tests.rs +++ b/src/tools/rust-analyzer/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) + ``` + "#]], + ); } |
