File tree 2 files changed +23
-1
lines changed
2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -844,12 +844,29 @@ impl Display for char {
844
844
}
845
845
}
846
846
847
+ // Two extra bytes for 0x
848
+ #[ cfg( target_pointer_width = "32" ) ]
849
+ const POINTER_PADDING : Option < usize > = Some ( 10 ) ;
850
+ #[ cfg( target_pointer_width = "64" ) ]
851
+ const POINTER_PADDING : Option < usize > = Some ( 18 ) ;
852
+
847
853
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
848
854
impl < T > Pointer for * const T {
849
855
fn fmt ( & self , f : & mut Formatter ) -> Result {
850
856
f. flags |= 1 << ( FlagV1 :: Alternate as u32 ) ;
857
+ f. flags |= 1 << ( FlagV1 :: SignAwareZeroPad as u32 ) ;
858
+
859
+ let old_width = f. width ;
860
+ if let None = f. width {
861
+ f. width = POINTER_PADDING ;
862
+ }
863
+
851
864
let ret = LowerHex :: fmt ( & ( * self as usize ) , f) ;
865
+
866
+ f. width = old_width;
852
867
f. flags &= !( 1 << ( FlagV1 :: Alternate as u32 ) ) ;
868
+ f. flags &= !( 1 << ( FlagV1 :: SignAwareZeroPad as u32 ) ) ;
869
+
853
870
ret
854
871
}
855
872
}
Original file line number Diff line number Diff line change @@ -14,6 +14,11 @@ use std::ptr;
14
14
use std:: rc:: Rc ;
15
15
use std:: sync:: Arc ;
16
16
17
+ #[ cfg( target_pointer_width = "32" ) ]
18
+ const PTR : & ' static str = "0x00000000" ;
19
+ #[ cfg( target_pointer_width = "64" ) ]
20
+ const PTR : & ' static str = "0x0000000000000000" ;
21
+
17
22
fn main ( ) {
18
23
let p: * const libc:: c_void = ptr:: null ( ) ;
19
24
let rc = Rc :: new ( 1usize ) ;
@@ -24,5 +29,5 @@ fn main() {
24
29
rc, arc, b) ;
25
30
26
31
assert_eq ! ( format!( "{:p}" , p) ,
27
- "0x0" ) ;
32
+ PTR . to_string ( ) ) ;
28
33
}
You can’t perform that action at this time.
0 commit comments