From b837e7173236b27ba76660864cd160aacbe66c57 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Mon, 10 Feb 2020 15:36:14 +0100 Subject: [PATCH] Reduce special casing in the const pretty printer --- src/librustc/ty/print/pretty.rs | 12 +++--------- .../ui/const-generics/raw-ptr-const-param.stderr | 6 +++--- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/librustc/ty/print/pretty.rs b/src/librustc/ty/print/pretty.rs index 86791ece5fc..446bb3db004 100644 --- a/src/librustc/ty/print/pretty.rs +++ b/src/librustc/ty/print/pretty.rs @@ -937,7 +937,6 @@ pub trait PrettyPrinter<'tcx>: // Bool (Scalar::Raw { data: 0, .. }, ty::Bool) => p!(write("false")), (Scalar::Raw { data: 1, .. }, ty::Bool) => p!(write("true")), - (Scalar::Raw { data, .. }, ty::Bool) => p!(write("{}_bool", data)), // Float (Scalar::Raw { data, .. }, ty::Float(ast::FloatTy::F32)) => { p!(write("{}f32", Single::from_bits(data))) @@ -975,14 +974,9 @@ pub trait PrettyPrinter<'tcx>: Some(c) => p!(write("{:?}", c)), None => p!(write("{}_char", data)), }, - // References and pointers - (Scalar::Raw { data: 0, .. }, ty::RawPtr(_)) => p!(write("{{null pointer}}")), - // This is UB, but we still print it - (Scalar::Raw { data: 0, .. }, ty::Ref(_, ty, _)) => { - p!(write("{{null reference to "), print(ty), write("}}")) - } - (Scalar::Raw { data, .. }, ty::Ref(..)) | (Scalar::Raw { data, .. }, ty::RawPtr(_)) => { - p!(write("0x{:x}", data)) + // Raw pointers + (Scalar::Raw { data, .. }, ty::RawPtr(_)) => { + p!(write("{{0x{:x} as ", data), print(ty), write("}}")) } (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 7bf2616fea2..d9794f60a19 100644 --- a/src/test/ui/const-generics/raw-ptr-const-param.stderr +++ b/src/test/ui/const-generics/raw-ptr-const-param.stderr @@ -10,12 +10,12 @@ error[E0308]: mismatched types --> $DIR/raw-ptr-const-param.rs:7:40 | LL | let _: Const<{ 15 as *const _ }> = Const::<{ 10 as *const _ }>; - | ------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `0xf`, found `0xa` + | ------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `{0xf as *const u32}`, found `{0xa as *const u32}` | | | expected due to this | - = note: expected struct `Const<0xf>` - found struct `Const<0xa>` + = note: expected struct `Const<{0xf as *const u32}>` + found struct `Const<{0xa as *const u32}>` error: aborting due to previous error