From 22586d7caf4687c4011ac002575efd3b6a89c645 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20Nordstr=C3=B6m?= Date: Sun, 27 Oct 2019 02:47:53 +0100 Subject: [PATCH 1/2] Better pretty printing for const raw pointers --- src/librustc/ty/print/pretty.rs | 5 ++++- src/test/ui/const-generics/raw-ptr-const-param.stderr | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/librustc/ty/print/pretty.rs b/src/librustc/ty/print/pretty.rs index 363109a0582df..269010d506168 100644 --- a/src/librustc/ty/print/pretty.rs +++ b/src/librustc/ty/print/pretty.rs @@ -919,7 +919,10 @@ pub trait PrettyPrinter<'tcx>: }, (ConstValue::Scalar(Scalar::Raw { data, .. }), ty::Char) => p!(write("{:?}", ::std::char::from_u32(data as u32).unwrap())), - (ConstValue::Scalar(_), ty::RawPtr(_)) => p!(write("{{pointer}}")), + (ConstValue::Scalar(Scalar::Raw { data, size }), ty::RawPtr(_)) => { + p!(write("{:#01$x} ", data, size as usize * 2)); + self = self.pretty_print_type(&ct.ty)?; + } (ConstValue::Scalar(Scalar::Ptr(ptr)), ty::FnPtr(_)) => { let instance = { let alloc_map = self.tcx().alloc_map.lock(); diff --git a/src/test/ui/const-generics/raw-ptr-const-param.stderr b/src/test/ui/const-generics/raw-ptr-const-param.stderr index 75b4c0a0a3de3..d1256b0c9c173 100644 --- a/src/test/ui/const-generics/raw-ptr-const-param.stderr +++ b/src/test/ui/const-generics/raw-ptr-const-param.stderr @@ -10,10 +10,10 @@ error[E0308]: mismatched types --> $DIR/raw-ptr-const-param.rs:7:38 | LL | let _: Const<{15 as *const _}> = Const::<{10 as *const _}>; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `{pointer}`, found `{pointer}` + | ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `0x0000000000000f *const u32`, found `0x0000000000000a *const u32` | - = note: expected type `Const<{pointer}>` - found type `Const<{pointer}>` + = note: expected type `Const<0x0000000000000f *const u32>` + found type `Const<0x0000000000000a *const u32>` error: aborting due to previous error From 6a6ed12d7c0433e7eb9ab6bd4145e09d269c797f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20Nordstr=C3=B6m?= Date: Sun, 27 Oct 2019 16:02:44 +0100 Subject: [PATCH 2/2] Add the two missing hex digits --- src/librustc/ty/print/pretty.rs | 4 ++-- src/test/ui/const-generics/raw-ptr-const-param.stderr | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/librustc/ty/print/pretty.rs b/src/librustc/ty/print/pretty.rs index 269010d506168..d6ec054911031 100644 --- a/src/librustc/ty/print/pretty.rs +++ b/src/librustc/ty/print/pretty.rs @@ -920,8 +920,8 @@ pub trait PrettyPrinter<'tcx>: (ConstValue::Scalar(Scalar::Raw { data, .. }), ty::Char) => p!(write("{:?}", ::std::char::from_u32(data as u32).unwrap())), (ConstValue::Scalar(Scalar::Raw { data, size }), ty::RawPtr(_)) => { - p!(write("{:#01$x} ", data, size as usize * 2)); - self = self.pretty_print_type(&ct.ty)?; + p!(write("0x{:01$x} : ", data, size as usize * 2)); + p!(print(ct.ty)); } (ConstValue::Scalar(Scalar::Ptr(ptr)), ty::FnPtr(_)) => { let instance = { diff --git a/src/test/ui/const-generics/raw-ptr-const-param.stderr b/src/test/ui/const-generics/raw-ptr-const-param.stderr index d1256b0c9c173..8c05634179d53 100644 --- a/src/test/ui/const-generics/raw-ptr-const-param.stderr +++ b/src/test/ui/const-generics/raw-ptr-const-param.stderr @@ -10,10 +10,10 @@ error[E0308]: mismatched types --> $DIR/raw-ptr-const-param.rs:7:38 | LL | let _: Const<{15 as *const _}> = Const::<{10 as *const _}>; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `0x0000000000000f *const u32`, found `0x0000000000000a *const u32` + | ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `0x000000000000000f : *const u32`, found `0x000000000000000a : *const u32` | - = note: expected type `Const<0x0000000000000f *const u32>` - found type `Const<0x0000000000000a *const u32>` + = note: expected type `Const<0x000000000000000f : *const u32>` + found type `Const<0x000000000000000a : *const u32>` error: aborting due to previous error