about summary refs log tree commit diff
path: root/src/libcore/fmt
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-02-11 01:54:15 +0000
committerbors <bors@rust-lang.org>2016-02-11 01:54:15 +0000
commit106070b905d1d312e19f7d0e439d1a7e78d3dc05 (patch)
tree8aa4ade04e74d30fc04ee5b094128f999db2beda /src/libcore/fmt
parent3f4227af139f1da30710a9f07dc28e5a3ccc6fe5 (diff)
parentc5f73ed80c9c37cceaa25ed20c0f88f9d324bd8c (diff)
Auto merge of #31479 - kamalmarhubi:fmt-pointer-unsized, r=alexcrichton
This allows printing pointers to unsized types with the {:p} formatting
directive. The following impls are extended to unsized types:
 - impl<'a, T: ?Sized> Pointer for &'a T
 - impl<'a, T: ?Sized> Pointer for &'a mut T
 - impl<T: ?Sized> Pointer for *const T
 - impl<T: ?Sized> Pointer for *mut T
 - impl<T: ?Sized> fmt::Pointer for Box<T>
 - impl<T: ?Sized> fmt::Pointer for Rc<T>
 - impl<T: ?Sized> fmt::Pointer for Arc<T>
Diffstat (limited to 'src/libcore/fmt')
-rw-r--r--src/libcore/fmt/mod.rs10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs
index e5b645a2938..5c67930c52f 100644
--- a/src/libcore/fmt/mod.rs
+++ b/src/libcore/fmt/mod.rs
@@ -1384,7 +1384,7 @@ impl Display for char {
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
-impl<T> Pointer for *const T {
+impl<T: ?Sized> Pointer for *const T {
     fn fmt(&self, f: &mut Formatter) -> Result {
         let old_width = f.width;
         let old_flags = f.flags;
@@ -1402,7 +1402,7 @@ impl<T> Pointer for *const T {
         }
         f.flags |= 1 << (FlagV1::Alternate as u32);
 
-        let ret = LowerHex::fmt(&(*self as usize), f);
+        let ret = LowerHex::fmt(&(*self as *const () as usize), f);
 
         f.width = old_width;
         f.flags = old_flags;
@@ -1412,21 +1412,21 @@ impl<T> Pointer for *const T {
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
-impl<T> Pointer for *mut T {
+impl<T: ?Sized> Pointer for *mut T {
     fn fmt(&self, f: &mut Formatter) -> Result {
         Pointer::fmt(&(*self as *const T), f)
     }
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
-impl<'a, T> Pointer for &'a T {
+impl<'a, T: ?Sized> Pointer for &'a T {
     fn fmt(&self, f: &mut Formatter) -> Result {
         Pointer::fmt(&(*self as *const T), f)
     }
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
-impl<'a, T> Pointer for &'a mut T {
+impl<'a, T: ?Sized> Pointer for &'a mut T {
     fn fmt(&self, f: &mut Formatter) -> Result {
         Pointer::fmt(&(&**self as *const T), f)
     }