@@ -19,6 +19,37 @@ fn test_pointer_formats_data_pointer() {
1919 assert_eq ! ( format!( "{b:p}" ) , format!( "{:p}" , b as * const _) ) ;
2020}
2121
22+ #[ test]
23+ fn test_fmt_debug_of_raw_pointers ( ) {
24+ use core:: fmt:: Debug ;
25+
26+ fn check_fmt < T : Debug > ( t : T , expected : & str ) {
27+ use std:: sync:: LazyLock ;
28+
29+ use regex:: Regex ;
30+
31+ static ADDR_REGEX : LazyLock < Regex > =
32+ LazyLock :: new ( || Regex :: new ( r"0x[0-9a-fA-F]+" ) . unwrap ( ) ) ;
33+
34+ let formatted = format ! ( "{:?}" , t) ;
35+ let normalized = ADDR_REGEX . replace_all ( & formatted, "$$HEX" ) ;
36+
37+ assert_eq ! ( normalized, expected) ;
38+ }
39+
40+ let plain = & mut 100 ;
41+ check_fmt ( plain as * mut i32 , "$HEX" ) ;
42+ check_fmt ( plain as * const i32 , "$HEX" ) ;
43+
44+ let slice = & mut [ 200 , 300 , 400 ] [ ..] ;
45+ check_fmt ( slice as * mut [ i32 ] , "$HEX" ) ;
46+ check_fmt ( slice as * const [ i32 ] , "$HEX" ) ;
47+
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" ) ;
51+ }
52+
2253#[ test]
2354fn test_estimated_capacity ( ) {
2455 assert_eq ! ( format_args!( "" ) . estimated_capacity( ) , 0 ) ;
0 commit comments