@@ -2233,35 +2233,41 @@ impl Display for char {
2233
2233
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2234
2234
impl < T : ?Sized > Pointer for * const T {
2235
2235
fn fmt ( & self , f : & mut Formatter < ' _ > ) -> Result {
2236
- /// Since the formatting will be identical for all pointer types, use a non-monomorphized
2237
- /// implementation for the actual formatting to reduce the amount of codegen work needed
2238
- fn inner ( ptr : * const ( ) , f : & mut Formatter < ' _ > ) -> Result {
2239
- let old_width = f. width ;
2240
- let old_flags = f. flags ;
2241
-
2242
- // The alternate flag is already treated by LowerHex as being special-
2243
- // it denotes whether to prefix with 0x. We use it to work out whether
2244
- // or not to zero extend, and then unconditionally set it to get the
2245
- // prefix.
2246
- if f. alternate ( ) {
2247
- f. flags |= 1 << ( FlagV1 :: SignAwareZeroPad as u32 ) ;
2248
-
2249
- if f. width . is_none ( ) {
2250
- f. width = Some ( ( usize:: BITS / 4 ) as usize + 2 ) ;
2251
- }
2252
- }
2253
- f. flags |= 1 << ( FlagV1 :: Alternate as u32 ) ;
2236
+ // Cast is needed here because `.addr()` requires `T: Sized`.
2237
+ pointer_fmt_inner ( ( * self as * const ( ) ) . addr ( ) , f)
2238
+ }
2239
+ }
2254
2240
2255
- let ret = LowerHex :: fmt ( & ( ptr. addr ( ) ) , f) ;
2241
+ /// Since the formatting will be identical for all pointer types, use a non-monomorphized
2242
+ /// implementation for the actual formatting to reduce the amount of codegen work needed.
2243
+ ///
2244
+ /// This uses `ptr_addr: usize` and not `ptr: *const ()` to be able to use this for
2245
+ /// `fn(...) -> ...` without using [problematic] "Oxford Casts".
2246
+ ///
2247
+ /// [problematic]: https://github.com/rust-lang/rust/issues/95489
2248
+ pub ( crate ) fn pointer_fmt_inner ( ptr_addr : usize , f : & mut Formatter < ' _ > ) -> Result {
2249
+ let old_width = f. width ;
2250
+ let old_flags = f. flags ;
2256
2251
2257
- f. width = old_width;
2258
- f. flags = old_flags;
2252
+ // The alternate flag is already treated by LowerHex as being special-
2253
+ // it denotes whether to prefix with 0x. We use it to work out whether
2254
+ // or not to zero extend, and then unconditionally set it to get the
2255
+ // prefix.
2256
+ if f. alternate ( ) {
2257
+ f. flags |= 1 << ( FlagV1 :: SignAwareZeroPad as u32 ) ;
2259
2258
2260
- ret
2259
+ if f. width . is_none ( ) {
2260
+ f. width = Some ( ( usize:: BITS / 4 ) as usize + 2 ) ;
2261
2261
}
2262
-
2263
- inner ( * self as * const ( ) , f)
2264
2262
}
2263
+ f. flags |= 1 << ( FlagV1 :: Alternate as u32 ) ;
2264
+
2265
+ let ret = LowerHex :: fmt ( & ptr_addr, f) ;
2266
+
2267
+ f. width = old_width;
2268
+ f. flags = old_flags;
2269
+
2270
+ ret
2265
2271
}
2266
2272
2267
2273
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
0 commit comments