about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-06-20 22:14:25 +0200
committerGitHub <noreply@github.com>2019-06-20 22:14:25 +0200
commit412946368359a6149da69aebbe2f14ecb957082f (patch)
tree12421803ebe11fb0e4fe9cb4adf753f17218168f
parentd3898a67315734c9a7ca8160f732cc360a5334a8 (diff)
parentf0d9d55138fd08f7f4af1c6c311694452369c111 (diff)
downloadrust-412946368359a6149da69aebbe2f14ecb957082f.tar.gz
rust-412946368359a6149da69aebbe2f14ecb957082f.zip
Rollup merge of #61979 - spastorino:fmt-place-base, r=oli-obk
Implement Debug for PlaceBase

r? @oli-obk

More tiny bits that can be extracted from Place 2.0 PR
-rw-r--r--src/librustc/mir/mod.rs48
1 files changed, 25 insertions, 23 deletions
diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs
index 9dfd8d959a3..6e09cc04528 100644
--- a/src/librustc/mir/mod.rs
+++ b/src/librustc/mir/mod.rs
@@ -2184,29 +2184,7 @@ impl<'tcx> Debug for Place<'tcx> {
         });
 
         self.iterate(|place_base, place_projections| {
-            match place_base {
-                PlaceBase::Local(id) => {
-                    write!(fmt, "{:?}", id)?;
-                }
-                PlaceBase::Static(box self::Static { ty, kind: StaticKind::Static(def_id) }) => {
-                    write!(
-                        fmt,
-                        "({}: {:?})",
-                        ty::tls::with(|tcx| tcx.def_path_str(*def_id)),
-                        ty
-                    )?;
-                },
-                PlaceBase::Static(
-                    box self::Static { ty, kind: StaticKind::Promoted(promoted) }
-                ) => {
-                    write!(
-                        fmt,
-                        "({:?}: {:?})",
-                        promoted,
-                        ty
-                    )?;
-                },
-            }
+            write!(fmt, "{:?}", place_base)?;
 
             for projection in place_projections {
                 match projection.elem {
@@ -2256,6 +2234,30 @@ impl<'tcx> Debug for Place<'tcx> {
     }
 }
 
+impl Debug for PlaceBase<'_> {
+    fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
+        match *self {
+            PlaceBase::Local(id) => write!(fmt, "{:?}", id),
+            PlaceBase::Static(box self::Static { ty, kind: StaticKind::Static(def_id) }) => {
+                write!(
+                    fmt,
+                    "({}: {:?})",
+                    ty::tls::with(|tcx| tcx.def_path_str(def_id)),
+                    ty
+                )
+            },
+            PlaceBase::Static(box self::Static { ty, kind: StaticKind::Promoted(promoted) }) => {
+                write!(
+                    fmt,
+                    "({:?}: {:?})",
+                    promoted,
+                    ty
+                )
+            },
+        }
+    }
+}
+
 ///////////////////////////////////////////////////////////////////////////
 // Scopes