Skip to content

Commit b837e71

Browse files
committed
Reduce special casing in the const pretty printer
1 parent e22ddfd commit b837e71

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

src/librustc/ty/print/pretty.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,6 @@ pub trait PrettyPrinter<'tcx>:
937937
// Bool
938938
(Scalar::Raw { data: 0, .. }, ty::Bool) => p!(write("false")),
939939
(Scalar::Raw { data: 1, .. }, ty::Bool) => p!(write("true")),
940-
(Scalar::Raw { data, .. }, ty::Bool) => p!(write("{}_bool", data)),
941940
// Float
942941
(Scalar::Raw { data, .. }, ty::Float(ast::FloatTy::F32)) => {
943942
p!(write("{}f32", Single::from_bits(data)))
@@ -975,14 +974,9 @@ pub trait PrettyPrinter<'tcx>:
975974
Some(c) => p!(write("{:?}", c)),
976975
None => p!(write("{}_char", data)),
977976
},
978-
// References and pointers
979-
(Scalar::Raw { data: 0, .. }, ty::RawPtr(_)) => p!(write("{{null pointer}}")),
980-
// This is UB, but we still print it
981-
(Scalar::Raw { data: 0, .. }, ty::Ref(_, ty, _)) => {
982-
p!(write("{{null reference to "), print(ty), write("}}"))
983-
}
984-
(Scalar::Raw { data, .. }, ty::Ref(..)) | (Scalar::Raw { data, .. }, ty::RawPtr(_)) => {
985-
p!(write("0x{:x}", data))
977+
// Raw pointers
978+
(Scalar::Raw { data, .. }, ty::RawPtr(_)) => {
979+
p!(write("{{0x{:x} as ", data), print(ty), write("}}"))
986980
}
987981
(Scalar::Ptr(ptr), ty::FnPtr(_)) => {
988982
let instance = {

src/test/ui/const-generics/raw-ptr-const-param.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ error[E0308]: mismatched types
1010
--> $DIR/raw-ptr-const-param.rs:7:40
1111
|
1212
LL | let _: Const<{ 15 as *const _ }> = Const::<{ 10 as *const _ }>;
13-
| ------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `0xf`, found `0xa`
13+
| ------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `{0xf as *const u32}`, found `{0xa as *const u32}`
1414
| |
1515
| expected due to this
1616
|
17-
= note: expected struct `Const<0xf>`
18-
found struct `Const<0xa>`
17+
= note: expected struct `Const<{0xf as *const u32}>`
18+
found struct `Const<{0xa as *const u32}>`
1919

2020
error: aborting due to previous error
2121

0 commit comments

Comments
 (0)