Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--crates/hir-def/src/body.rs11
-rw-r--r--crates/hir-def/src/body/pretty.rs20
2 files changed, 31 insertions, 0 deletions
diff --git a/crates/hir-def/src/body.rs b/crates/hir-def/src/body.rs
index f18083d387..6493826f07 100644
--- a/crates/hir-def/src/body.rs
+++ b/crates/hir-def/src/body.rs
@@ -227,6 +227,17 @@ impl Body {
pretty::print_expr_hir(db, self, owner, expr, edition)
}
+ pub fn pretty_print_pat(
+ &self,
+ db: &dyn DefDatabase,
+ owner: DefWithBodyId,
+ pat: PatId,
+ oneline: bool,
+ edition: Edition,
+ ) -> String {
+ pretty::print_pat_hir(db, self, owner, pat, oneline, edition)
+ }
+
fn new(
db: &dyn DefDatabase,
owner: DefWithBodyId,
diff --git a/crates/hir-def/src/body/pretty.rs b/crates/hir-def/src/body/pretty.rs
index 6555d8061e..3333956adb 100644
--- a/crates/hir-def/src/body/pretty.rs
+++ b/crates/hir-def/src/body/pretty.rs
@@ -121,6 +121,26 @@ pub(super) fn print_expr_hir(
p.buf
}
+pub(super) fn print_pat_hir(
+ db: &dyn DefDatabase,
+ body: &Body,
+ _owner: DefWithBodyId,
+ pat: PatId,
+ oneline: bool,
+ edition: Edition,
+) -> String {
+ let mut p = Printer {
+ db,
+ body,
+ buf: String::new(),
+ indent_level: 0,
+ line_format: if oneline { LineFormat::Oneline } else { LineFormat::Newline },
+ edition,
+ };
+ p.print_pat(pat);
+ p.buf
+}
+
macro_rules! w {
($dst:expr, $($arg:tt)*) => {
{ let _ = write!($dst, $($arg)*); }