From 5c97361622bb3c6410c3c36dda30bfbb1ebca5e8 Mon Sep 17 00:00:00 2001 From: roife Date: Mon, 9 Sep 2024 03:55:59 +0800 Subject: [PATCH] fix: add parenthesis for or-pattern --- crates/hir-def/src/body/pretty.rs | 2 ++ crates/ide/src/hover/tests.rs | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) 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) + ``` + "#]], + ); }