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/9] 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/9] 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 From d32204413f426f4808b5a798e8ea2aef67122fc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20Nordstr=C3=B6m?= Date: Thu, 31 Oct 2019 21:44:16 +0100 Subject: [PATCH 3/9] Fix raw const ptr test on 32 bit platforms --- src/test/ui/const-generics/raw-ptr-const-param.rs | 3 +++ src/test/ui/const-generics/raw-ptr-const-param.stderr | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/test/ui/const-generics/raw-ptr-const-param.rs b/src/test/ui/const-generics/raw-ptr-const-param.rs index f69c37fbb8f3d..ad4db5b8e53bf 100644 --- a/src/test/ui/const-generics/raw-ptr-const-param.rs +++ b/src/test/ui/const-generics/raw-ptr-const-param.rs @@ -1,3 +1,6 @@ +// normalize-stderr-32bit: "0x" -> "$$PREFIX" +// normalize-stderr-64bit: "0x00000000" -> "$$PREFIX" + #![feature(const_generics, const_compare_raw_pointers)] //~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash 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 8c05634179d53..19d750dbf8bdd 100644 --- a/src/test/ui/const-generics/raw-ptr-const-param.stderr +++ b/src/test/ui/const-generics/raw-ptr-const-param.stderr @@ -1,5 +1,5 @@ warning: the feature `const_generics` is incomplete and may cause the compiler to crash - --> $DIR/raw-ptr-const-param.rs:1:12 + --> $DIR/raw-ptr-const-param.rs:4:12 | LL | #![feature(const_generics, const_compare_raw_pointers)] | ^^^^^^^^^^^^^^ @@ -7,13 +7,13 @@ LL | #![feature(const_generics, const_compare_raw_pointers)] = note: `#[warn(incomplete_features)]` on by default error[E0308]: mismatched types - --> $DIR/raw-ptr-const-param.rs:7:38 + --> $DIR/raw-ptr-const-param.rs:10:38 | LL | let _: Const<{15 as *const _}> = Const::<{10 as *const _}>; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `0x000000000000000f : *const u32`, found `0x000000000000000a : *const u32` + | ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `$PREFIX0000000f : *const u32`, found `$PREFIX0000000a : *const u32` | - = note: expected type `Const<0x000000000000000f : *const u32>` - found type `Const<0x000000000000000a : *const u32>` + = note: expected type `Const<$PREFIX0000000f : *const u32>` + found type `Const<$PREFIX0000000a : *const u32>` error: aborting due to previous error From 3364c4641ee00be1e4d53a1533892568a9215dc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20Nordstr=C3=B6m?= Date: Mon, 4 Nov 2019 22:18:09 +0100 Subject: [PATCH 4/9] Nicer fallback for const pointers to allocations --- src/librustc/ty/print/pretty.rs | 9 +++++++-- src/test/ui/const-generics/raw-ptr-const-param.rs | 2 ++ src/test/ui/const-generics/raw-ptr-const-param.stderr | 11 ++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/librustc/ty/print/pretty.rs b/src/librustc/ty/print/pretty.rs index d6ec054911031..99492de164fb9 100644 --- a/src/librustc/ty/print/pretty.rs +++ b/src/librustc/ty/print/pretty.rs @@ -919,8 +919,13 @@ 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("0x{:01$x} : ", data, size as usize * 2)); + (ConstValue::Scalar(value), ty::RawPtr(_)) => { + match value { + Scalar::Raw { data, size } => { + p!(write("0x{:01$x} : ", data, size as usize * 2)); + } + _ => p!(write("{{pointer}} : ")) + }; p!(print(ct.ty)); } (ConstValue::Scalar(Scalar::Ptr(ptr)), ty::FnPtr(_)) => { diff --git a/src/test/ui/const-generics/raw-ptr-const-param.rs b/src/test/ui/const-generics/raw-ptr-const-param.rs index ad4db5b8e53bf..fd494daa85b01 100644 --- a/src/test/ui/const-generics/raw-ptr-const-param.rs +++ b/src/test/ui/const-generics/raw-ptr-const-param.rs @@ -9,4 +9,6 @@ struct Const; fn main() { let _: Const<{15 as *const _}> = Const::<{10 as *const _}>; //~ mismatched types let _: Const<{10 as *const _}> = Const::<{10 as *const _}>; + + let _: Const<{10 as *const _}> = Const::<{&8_u32 as *const _}>; //~ mismatched types } 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 19d750dbf8bdd..47e9cd534b3ad 100644 --- a/src/test/ui/const-generics/raw-ptr-const-param.stderr +++ b/src/test/ui/const-generics/raw-ptr-const-param.stderr @@ -15,6 +15,15 @@ LL | let _: Const<{15 as *const _}> = Const::<{10 as *const _}>; = note: expected type `Const<$PREFIX0000000f : *const u32>` found type `Const<$PREFIX0000000a : *const u32>` -error: aborting due to previous error +error[E0308]: mismatched types + --> $DIR/raw-ptr-const-param.rs:13:38 + | +LL | let _: Const<{10 as *const _}> = Const::<{&8_u32 as *const _}>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `$PREFIX0000000a : *const u32`, found `{pointer} : *const u32` + | + = note: expected type `Const<$PREFIX0000000a : *const u32>` + found type `Const<{pointer} : *const u32>` + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0308`. From f2cb4d7a21d26ce18265a5e0aebefa957f918048 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20Nordstr=C3=B6m?= Date: Mon, 4 Nov 2019 23:22:23 +0100 Subject: [PATCH 5/9] Print const refs like const raw pointers --- src/librustc/ty/print/pretty.rs | 1 + .../const-generics/int-as-ref-const-param.rs | 26 +++++++++++++++++ .../int-as-ref-const-param.stderr | 29 +++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 src/test/ui/const-generics/int-as-ref-const-param.rs create mode 100644 src/test/ui/const-generics/int-as-ref-const-param.stderr diff --git a/src/librustc/ty/print/pretty.rs b/src/librustc/ty/print/pretty.rs index 99492de164fb9..7955731781b48 100644 --- a/src/librustc/ty/print/pretty.rs +++ b/src/librustc/ty/print/pretty.rs @@ -919,6 +919,7 @@ pub trait PrettyPrinter<'tcx>: }, (ConstValue::Scalar(Scalar::Raw { data, .. }), ty::Char) => p!(write("{:?}", ::std::char::from_u32(data as u32).unwrap())), + (ConstValue::Scalar(value), ty::Ref(..)) | (ConstValue::Scalar(value), ty::RawPtr(_)) => { match value { Scalar::Raw { data, size } => { diff --git a/src/test/ui/const-generics/int-as-ref-const-param.rs b/src/test/ui/const-generics/int-as-ref-const-param.rs new file mode 100644 index 0000000000000..539b86b30a4bc --- /dev/null +++ b/src/test/ui/const-generics/int-as-ref-const-param.rs @@ -0,0 +1,26 @@ +// normalize-stderr-32bit: "0x" -> "$$PREFIX" +// normalize-stderr-64bit: "0x00000000" -> "$$PREFIX" + +#![feature(const_generics, const_compare_raw_pointers)] +//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash + +struct Const; + +#[repr(C)] +union Transmuter { + pointer: *const (), + reference: &'static (), +} + +fn main() { + const A: &'static () = { + unsafe { Transmuter { pointer: 10 as *const () }.reference } + }; + const B: &'static () = { + unsafe { Transmuter { pointer: 11 as *const () }.reference } + }; + + let _: Const<{A}> = Const::<{B}>; //~ mismatched types + let _: Const<{A}> = Const::<{&()}>; //~ mismatched types + let _: Const<{A}> = Const::<{A}>; +} diff --git a/src/test/ui/const-generics/int-as-ref-const-param.stderr b/src/test/ui/const-generics/int-as-ref-const-param.stderr new file mode 100644 index 0000000000000..4a9ab615601da --- /dev/null +++ b/src/test/ui/const-generics/int-as-ref-const-param.stderr @@ -0,0 +1,29 @@ +warning: the feature `const_generics` is incomplete and may cause the compiler to crash + --> $DIR/int-as-ref-const-param.rs:4:12 + | +LL | #![feature(const_generics, const_compare_raw_pointers)] + | ^^^^^^^^^^^^^^ + | + = note: `#[warn(incomplete_features)]` on by default + +error[E0308]: mismatched types + --> $DIR/int-as-ref-const-param.rs:23:25 + | +LL | let _: Const<{A}> = Const::<{B}>; + | ^^^^^^^^^^^^ expected `$PREFIX0000000a : &()`, found `$PREFIX0000000b : &()` + | + = note: expected type `Const<$PREFIX0000000a : &()>` + found type `Const<$PREFIX0000000b : &()>` + +error[E0308]: mismatched types + --> $DIR/int-as-ref-const-param.rs:24:25 + | +LL | let _: Const<{A}> = Const::<{&()}>; + | ^^^^^^^^^^^^^^ expected `$PREFIX0000000a : &()`, found `{pointer} : &()` + | + = note: expected type `Const<$PREFIX0000000a : &()>` + found type `Const<{pointer} : &()>` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. From 6c26bd683bf3ad76bde64832c8f9f17a27e5b43d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20Nordstr=C3=B6m?= Date: Mon, 11 Nov 2019 22:04:29 +0100 Subject: [PATCH 6/9] Try to print as slice before ref --- src/librustc/ty/print/pretty.rs | 93 ++++++++++++++++----------------- 1 file changed, 45 insertions(+), 48 deletions(-) diff --git a/src/librustc/ty/print/pretty.rs b/src/librustc/ty/print/pretty.rs index 7955731781b48..8247838be35c5 100644 --- a/src/librustc/ty/print/pretty.rs +++ b/src/librustc/ty/print/pretty.rs @@ -864,6 +864,49 @@ pub trait PrettyPrinter<'tcx>: let u8 = self.tcx().types.u8; + if let ty::Ref(_, ref_ty, _) = ct.ty.kind { + let byte_str = match (ct.val, &ref_ty.kind) { + (ConstValue::Scalar(Scalar::Ptr(ptr)), ty::Array(t, n)) if *t == u8 => { + let n = n.eval_usize(self.tcx(), ty::ParamEnv::empty()); + Some(self.tcx() + .alloc_map.lock() + .unwrap_memory(ptr.alloc_id) + .get_bytes(&self.tcx(), ptr, Size::from_bytes(n)).unwrap()) + }, + (ConstValue::Slice { data, start, end }, ty::Slice(t)) if *t == u8 => { + // The `inspect` here is okay since we checked the bounds, and there are + // no relocations (we have an active slice reference here). We don't use + // this result to affect interpreter execution. + Some(data.inspect_with_undef_and_ptr_outside_interpreter(start..end)) + }, + _ => None, + }; + + if let Some(byte_str) = byte_str { + p!(write("b\"")); + for &c in byte_str { + for e in std::ascii::escape_default(c) { + self.write_char(e as char)?; + } + } + p!(write("\"")); + return Ok(self); + } + + if let (ConstValue::Slice { data, start, end }, ty::Str) = + (ct.val, &ref_ty.kind) + { + // The `inspect` here is okay since we checked the bounds, and there are no + // relocations (we have an active `str` reference here). We don't use this + // result to affect interpreter execution. + let slice = data.inspect_with_undef_and_ptr_outside_interpreter(start..end); + let s = ::std::str::from_utf8(slice) + .expect("non utf8 str from miri"); + p!(write("{:?}", s)); + return Ok(self); + } + }; + match (ct.val, &ct.ty.kind) { (_, ty::FnDef(did, substs)) => p!(print_value_path(*did, substs)), (ConstValue::Unevaluated(did, substs), _) => { @@ -937,54 +980,8 @@ pub trait PrettyPrinter<'tcx>: p!(print_value_path(instance.def_id(), instance.substs)); }, _ => { - let printed = if let ty::Ref(_, ref_ty, _) = ct.ty.kind { - let byte_str = match (ct.val, &ref_ty.kind) { - (ConstValue::Scalar(Scalar::Ptr(ptr)), ty::Array(t, n)) if *t == u8 => { - let n = n.eval_usize(self.tcx(), ty::ParamEnv::empty()); - Some(self.tcx() - .alloc_map.lock() - .unwrap_memory(ptr.alloc_id) - .get_bytes(&self.tcx(), ptr, Size::from_bytes(n)).unwrap()) - }, - (ConstValue::Slice { data, start, end }, ty::Slice(t)) if *t == u8 => { - // The `inspect` here is okay since we checked the bounds, and there are - // no relocations (we have an active slice reference here). We don't use - // this result to affect interpreter execution. - Some(data.inspect_with_undef_and_ptr_outside_interpreter(start..end)) - }, - _ => None, - }; - - if let Some(byte_str) = byte_str { - p!(write("b\"")); - for &c in byte_str { - for e in std::ascii::escape_default(c) { - self.write_char(e as char)?; - } - } - p!(write("\"")); - true - } else if let (ConstValue::Slice { data, start, end }, ty::Str) = - (ct.val, &ref_ty.kind) - { - // The `inspect` here is okay since we checked the bounds, and there are no - // relocations (we have an active `str` reference here). We don't use this - // result to affect interpreter execution. - let slice = data.inspect_with_undef_and_ptr_outside_interpreter(start..end); - let s = ::std::str::from_utf8(slice) - .expect("non utf8 str from miri"); - p!(write("{:?}", s)); - true - } else { - false - } - } else { - false - }; - if !printed { - // fallback - p!(write("{:?} : ", ct.val), print(ct.ty)) - } + // fallback + p!(write("{:?} : ", ct.val), print(ct.ty)) } }; Ok(self) From 175c608ea6a09bfd3a7ac9b6f4722db96b44ce02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20Nordstr=C3=B6m?= Date: Mon, 11 Nov 2019 22:05:29 +0100 Subject: [PATCH 7/9] Update expected output in mir-opt tests --- src/test/mir-opt/const_prop/const_prop_fails_gracefully.rs | 6 +++--- src/test/mir-opt/const_prop/ref_deref.rs | 2 +- src/test/mir-opt/const_prop/slice_len.rs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/test/mir-opt/const_prop/const_prop_fails_gracefully.rs b/src/test/mir-opt/const_prop/const_prop_fails_gracefully.rs index 85ed8d55b243b..e705f92d61961 100644 --- a/src/test/mir-opt/const_prop/const_prop_fails_gracefully.rs +++ b/src/test/mir-opt/const_prop/const_prop_fails_gracefully.rs @@ -23,9 +23,9 @@ fn main() { // START rustc.main.ConstProp.after.mir // bb0: { // ... -// _4 = const Scalar(AllocId(1).0x0) : &i32; -// _3 = const Scalar(AllocId(1).0x0) : &i32; -// _2 = const Scalar(AllocId(1).0x0) : *const i32; +// _4 = const {pointer} : &i32; +// _3 = const {pointer} : &i32; +// _2 = const {pointer} : *const i32; // ... // _1 = move _2 as usize (Misc); // ... diff --git a/src/test/mir-opt/const_prop/ref_deref.rs b/src/test/mir-opt/const_prop/ref_deref.rs index 2d04822c0e789..e92fe98761f99 100644 --- a/src/test/mir-opt/const_prop/ref_deref.rs +++ b/src/test/mir-opt/const_prop/ref_deref.rs @@ -14,7 +14,7 @@ fn main() { // START rustc.main.ConstProp.after.mir // bb0: { // ... -// _2 = const Scalar(AllocId(0).0x0) : &i32; +// _2 = const {pointer} : &i32; // _1 = const 4i32; // ... // } diff --git a/src/test/mir-opt/const_prop/slice_len.rs b/src/test/mir-opt/const_prop/slice_len.rs index 05595ce147c96..cae66f7994aab 100644 --- a/src/test/mir-opt/const_prop/slice_len.rs +++ b/src/test/mir-opt/const_prop/slice_len.rs @@ -24,8 +24,8 @@ fn main() { // START rustc.main.ConstProp.after.mir // bb0: { // ... -// _4 = const Scalar(AllocId(0).0x0) : &[u32; 3]; -// _3 = const Scalar(AllocId(0).0x0) : &[u32; 3]; +// _4 = const {pointer} : &[u32; 3]; +// _3 = const {pointer} : &[u32; 3]; // _2 = move _3 as &[u32] (Pointer(Unsize)); // ... // _6 = const 1usize; From c2dbe44a8f263a134bcd115eb26f6818e9cd707c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20Nordstr=C3=B6m?= Date: Sat, 16 Nov 2019 13:36:34 +0100 Subject: [PATCH 8/9] Bless mir-opt test --- src/test/mir-opt/const_prop/const_prop_fails_gracefully.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/mir-opt/const_prop/const_prop_fails_gracefully.rs b/src/test/mir-opt/const_prop/const_prop_fails_gracefully.rs index e705f92d61961..6cd6382cc4695 100644 --- a/src/test/mir-opt/const_prop/const_prop_fails_gracefully.rs +++ b/src/test/mir-opt/const_prop/const_prop_fails_gracefully.rs @@ -25,7 +25,7 @@ fn main() { // ... // _4 = const {pointer} : &i32; // _3 = const {pointer} : &i32; -// _2 = const {pointer} : *const i32; +// _2 = const Scalar(AllocId(1).0x0) : *const i32; // ... // _1 = move _2 as usize (Misc); // ... From 1407cdd0a28126a8f123fe3aa91eed061b631d31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20Nordstr=C3=B6m?= Date: Sat, 16 Nov 2019 19:39:53 +0100 Subject: [PATCH 9/9] Comment which kinds of refs get printed where --- src/librustc/ty/print/pretty.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/librustc/ty/print/pretty.rs b/src/librustc/ty/print/pretty.rs index 02fada31dbf28..ec7c49464abd5 100644 --- a/src/librustc/ty/print/pretty.rs +++ b/src/librustc/ty/print/pretty.rs @@ -907,6 +907,9 @@ pub trait PrettyPrinter<'tcx>: let u8 = self.tcx().types.u8; if let ty::Ref(_, ref_ty, _) = ty.kind { + // &str is a special case of references, and should override the general case, so we + // check for and handle that first. + let byte_str = match (ct, &ref_ty.kind) { (ConstValue::Scalar(Scalar::Ptr(ptr)), ty::Array(t, n)) if *t == u8 => { let n = n.eval_usize(self.tcx(), ty::ParamEnv::empty()); @@ -988,6 +991,8 @@ pub trait PrettyPrinter<'tcx>: p!(write("{:?}", ::std::char::from_u32(data as u32).unwrap())), (ConstValue::Scalar(value), ty::Ref(..)) | (ConstValue::Scalar(value), ty::RawPtr(_)) => { + // &str should already have been handled, so this is a general representation of a + // reference. match value { Scalar::Raw { data, size } => { p!(write("0x{:01$x} : ", data, size as usize * 2));