diff --git a/src/librustc/ty/print/pretty.rs b/src/librustc/ty/print/pretty.rs index 6edab2708386..d1aee1290c9b 100644 --- a/src/librustc/ty/print/pretty.rs +++ b/src/librustc/ty/print/pretty.rs @@ -999,12 +999,29 @@ pub trait PrettyPrinter<'tcx>: }; 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 { diff --git a/src/test/mir-opt/simplify-locals-removes-unused-consts.rs b/src/test/mir-opt/simplify-locals-removes-unused-consts.rs index 730314a78882..e427fd55ad68 100644 --- a/src/test/mir-opt/simplify-locals-removes-unused-consts.rs +++ b/src/test/mir-opt/simplify-locals-removes-unused-consts.rs @@ -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);