]> git.lizzy.rs Git - rust.git/commitdiff
Don't print all zsts as their type as it makes no sense for more complex examples...
authorOliver Scherer <github35764891676564198441@oli-obk.de>
Wed, 12 Feb 2020 12:47:00 +0000 (13:47 +0100)
committerOliver Scherer <github35764891676564198441@oli-obk.de>
Wed, 11 Mar 2020 08:10:49 +0000 (09:10 +0100)
src/librustc/ty/print/pretty.rs
src/test/mir-opt/simplify-locals-removes-unused-consts.rs

index 6edab2708386d96551abc46847727e7eb70d0167..d1aee1290c9b35b4ce7721285c43dd5081fa89d9 100644 (file)
@@ -999,12 +999,29 @@ fn pretty_print_const_scalar(
                 };
                 p!(print_value_path(instance.def_id(), instance.substs));
             }
-            // For zsts just print their type as their value gives no extra information
-            (Scalar::Raw { size: 0, .. }, _) => p!(print(ty)),
+            // For function type zsts just printing the type is enough
+            (Scalar::Raw { size: 0, .. }, ty::FnDef(..)) => p!(print(ty)),
+            // Empty tuples are frequently occurring, so don't print the fallback.
+            (Scalar::Raw { size: 0, .. }, ty::Tuple(ts)) if ts.is_empty() => p!(write("()")),
+            // Zero element arrays have a trivial representation.
+            (
+                Scalar::Raw { size: 0, .. },
+                ty::Array(
+                    _,
+                    ty::Const {
+                        val: ty::ConstKind::Value(ConstValue::Scalar(Scalar::Raw { data: 0, .. })),
+                        ..
+                    },
+                ),
+            ) => p!(write("[]")),
             // Nontrivial types with scalar bit representation
             (Scalar::Raw { data, size }, _) => {
                 let print = |mut this: Self| {
-                    write!(this, "transmute(0x{:01$x})", data, size as usize * 2)?;
+                    if size == 0 {
+                        write!(this, "transmute(())")?;
+                    } else {
+                        write!(this, "transmute(0x{:01$x})", data, size as usize * 2)?;
+                    }
                     Ok(this)
                 };
                 self = if print_ty {
index 730314a7888201f5aa5e89069eadd6b0014b1ef8..e427fd55ad6807a82d9e2cb342ad84e50eddd75b 100644 (file)
@@ -38,7 +38,7 @@ fn main() {
 //   _2 = const ();
 //   StorageLive(_3);
 //   _3 = const ();
-//   _1 = const ((), ());
+//   _1 = const {transmute(()): ((), ())};
 //   StorageDead(_3);
 //   StorageDead(_2);
 //   StorageDead(_1);
@@ -49,7 +49,7 @@ fn main() {
 //   _7 = const ();
 //   StorageDead(_7);
 //   StorageDead(_6);
-//   _4 = const use_zst(const ((), ())) -> bb1;
+//   _4 = const use_zst(const {transmute(()): ((), ())}) -> bb1;
 // }
 // bb1: {
 //   StorageDead(_4);
@@ -75,7 +75,7 @@ fn main() {
 // }
 // bb0: {
 //   StorageLive(_1);
-//   _1 = const use_zst(const ((), ())) -> bb1;
+//   _1 = const use_zst(const {transmute(()): ((), ())}) -> bb1;
 // }
 // bb1: {
 //   StorageDead(_1);