File tree 3 files changed +28
-5
lines changed
3 files changed +28
-5
lines changed Original file line number Diff line number Diff line change @@ -2776,7 +2776,14 @@ impl Display for char {
2776
2776
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2777
2777
impl < T : ?Sized > Pointer for * const T {
2778
2778
fn fmt ( & self , f : & mut Formatter < ' _ > ) -> Result {
2779
- pointer_fmt_inner ( self . expose_provenance ( ) , f)
2779
+ if <<T as core:: ptr:: Pointee >:: Metadata as core:: unit:: IsUnit >:: is_unit ( ) {
2780
+ pointer_fmt_inner ( self . expose_provenance ( ) , f)
2781
+ } else {
2782
+ f. debug_struct ( "Pointer" )
2783
+ . field_with ( "addr" , |f| pointer_fmt_inner ( self . expose_provenance ( ) , f) )
2784
+ . field ( "metadata" , & core:: ptr:: metadata ( * self ) )
2785
+ . finish ( )
2786
+ }
2780
2787
}
2781
2788
}
2782
2789
Original file line number Diff line number Diff line change @@ -17,3 +17,19 @@ impl FromIterator<()> for () {
17
17
iter. into_iter ( ) . for_each ( |( ) | { } )
18
18
}
19
19
}
20
+
21
+ pub ( crate ) trait IsUnit {
22
+ fn is_unit ( ) -> bool ;
23
+ }
24
+
25
+ impl < T : ?Sized > IsUnit for T {
26
+ default fn is_unit ( ) -> bool {
27
+ false
28
+ }
29
+ }
30
+
31
+ impl IsUnit for ( ) {
32
+ fn is_unit ( ) -> bool {
33
+ true
34
+ }
35
+ }
Original file line number Diff line number Diff line change @@ -42,12 +42,12 @@ fn test_fmt_debug_of_raw_pointers() {
42
42
check_fmt ( plain as * const i32 , "$HEX" ) ;
43
43
44
44
let slice = & mut [ 200 , 300 , 400 ] [ ..] ;
45
- check_fmt ( slice as * mut [ i32 ] , "$HEX" ) ;
46
- check_fmt ( slice as * const [ i32 ] , "$HEX" ) ;
45
+ check_fmt ( slice as * mut [ i32 ] , "Pointer { addr: $HEX, metadata: 3 } " ) ;
46
+ check_fmt ( slice as * const [ i32 ] , "Pointer { addr: $HEX, metadata: 3 } " ) ;
47
47
48
48
let vtable = & mut 500 as & mut dyn Debug ;
49
- check_fmt ( vtable as * mut dyn Debug , "$HEX" ) ;
50
- check_fmt ( vtable as * const dyn Debug , "$HEX" ) ;
49
+ check_fmt ( vtable as * mut dyn Debug , "Pointer { addr: $HEX, metadata: DynMetadata($HEX) } " ) ;
50
+ check_fmt ( vtable as * const dyn Debug , "Pointer { addr: $HEX, metadata: DynMetadata($HEX) } " ) ;
51
51
}
52
52
53
53
#[ test]
You can’t perform that action at this time.
0 commit comments