Unnamed repository; edit this file 'description' to name the repository.
Fix pretty-printing of `@` patterns
It didn't print the `@`.
Chayim Refael Friedman 2024-12-18
parent 27e824f · commit 8c8e738
-rw-r--r--crates/hir-def/src/body/pretty.rs1
-rw-r--r--crates/hir-def/src/body/tests.rs18
2 files changed, 19 insertions, 0 deletions
diff --git a/crates/hir-def/src/body/pretty.rs b/crates/hir-def/src/body/pretty.rs
index f8b6eef342..52b91b522a 100644
--- a/crates/hir-def/src/body/pretty.rs
+++ b/crates/hir-def/src/body/pretty.rs
@@ -685,6 +685,7 @@ impl Printer<'_> {
self.print_binding(*id);
if let Some(pat) = subpat {
self.whitespace();
+ w!(self, "@ ");
self.print_pat(*pat);
}
}
diff --git a/crates/hir-def/src/body/tests.rs b/crates/hir-def/src/body/tests.rs
index 8f01091584..13ba4db606 100644
--- a/crates/hir-def/src/body/tests.rs
+++ b/crates/hir-def/src/body/tests.rs
@@ -426,3 +426,21 @@ fn f() {
"should have a binding for `B`",
);
}
+
+#[test]
+fn regression_pretty_print_bind_pat() {
+ let (db, body, owner) = lower(
+ r#"
+fn foo() {
+ let v @ u = 123;
+}
+"#,
+ );
+ let printed = body.pretty_print(&db, owner, Edition::CURRENT);
+ assert_eq!(
+ printed,
+ r#"fn foo() -> () {
+ let v @ u = 123;
+}"#
+ );
+}