Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/mir/pretty.rs')
-rw-r--r--crates/hir-ty/src/mir/pretty.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/crates/hir-ty/src/mir/pretty.rs b/crates/hir-ty/src/mir/pretty.rs
index eb0002266d..ab3bb643e7 100644
--- a/crates/hir-ty/src/mir/pretty.rs
+++ b/crates/hir-ty/src/mir/pretty.rs
@@ -1,6 +1,6 @@
//! A pretty-printer for MIR.
-use std::fmt::{Display, Write};
+use std::fmt::{Display, Write, Debug};
use hir_def::{body::Body, expr::BindingId};
use hir_expand::name::Name;
@@ -23,6 +23,18 @@ impl MirBody {
ctx.for_body();
ctx.result
}
+
+ // String with lines is rendered poorly in `dbg!` macros, which I use very much, so this
+ // function exists to solve that.
+ pub fn dbg(&self, db: &dyn HirDatabase) -> impl Debug {
+ struct StringDbg(String);
+ impl Debug for StringDbg {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.write_str(&self.0)
+ }
+ }
+ StringDbg(self.pretty_print(db))
+ }
}
struct MirPrettyCtx<'a> {