Skip to content

Commit 154f3f1

Browse files
committed
Don't print all zsts as their type as it makes no sense for more complex examples (e.g. structs)
1 parent 1191eb4 commit 154f3f1

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

src/librustc/ty/print/pretty.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -999,12 +999,29 @@ pub trait PrettyPrinter<'tcx>:
999999
};
10001000
p!(print_value_path(instance.def_id(), instance.substs));
10011001
}
1002-
// For zsts just print their type as their value gives no extra information
1003-
(Scalar::Raw { size: 0, .. }, _) => p!(print(ty)),
1002+
// For function type zsts just printing the type is enough
1003+
(Scalar::Raw { size: 0, .. }, ty::FnDef(..)) => p!(print(ty)),
1004+
// Empty tuples are frequently occurring, so don't print the fallback.
1005+
(Scalar::Raw { size: 0, .. }, ty::Tuple(ts)) if ts.is_empty() => p!(write("()")),
1006+
// Zero element arrays have a trivial representation.
1007+
(
1008+
Scalar::Raw { size: 0, .. },
1009+
ty::Array(
1010+
_,
1011+
ty::Const {
1012+
val: ty::ConstKind::Value(ConstValue::Scalar(Scalar::Raw { data: 0, .. })),
1013+
..
1014+
},
1015+
),
1016+
) => p!(write("[]")),
10041017
// Nontrivial types with scalar bit representation
10051018
(Scalar::Raw { data, size }, _) => {
10061019
let print = |mut this: Self| {
1007-
write!(this, "transmute(0x{:01$x})", data, size as usize * 2)?;
1020+
if size == 0 {
1021+
write!(this, "transmute(())")?;
1022+
} else {
1023+
write!(this, "transmute(0x{:01$x})", data, size as usize * 2)?;
1024+
}
10081025
Ok(this)
10091026
};
10101027
self = if print_ty {

src/test/mir-opt/simplify-locals-removes-unused-consts.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn main() {
3838
// _2 = const ();
3939
// StorageLive(_3);
4040
// _3 = const ();
41-
// _1 = const ((), ());
41+
// _1 = const {transmute(()): ((), ())};
4242
// StorageDead(_3);
4343
// StorageDead(_2);
4444
// StorageDead(_1);
@@ -49,7 +49,7 @@ fn main() {
4949
// _7 = const ();
5050
// StorageDead(_7);
5151
// StorageDead(_6);
52-
// _4 = const use_zst(const ((), ())) -> bb1;
52+
// _4 = const use_zst(const {transmute(()): ((), ())}) -> bb1;
5353
// }
5454
// bb1: {
5555
// StorageDead(_4);
@@ -75,7 +75,7 @@ fn main() {
7575
// }
7676
// bb0: {
7777
// StorageLive(_1);
78-
// _1 = const use_zst(const ((), ())) -> bb1;
78+
// _1 = const use_zst(const {transmute(()): ((), ())}) -> bb1;
7979
// }
8080
// bb1: {
8181
// StorageDead(_1);

0 commit comments

Comments
 (0)