File tree 6 files changed +67
-0
lines changed
6 files changed +67
-0
lines changed Original file line number Diff line number Diff line change @@ -668,6 +668,13 @@ impl<T: fmt::Debug> fmt::Debug for Arc<T> {
668
668
}
669
669
}
670
670
671
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
672
+ impl < T > fmt:: Pointer for Arc < T > {
673
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
674
+ fmt:: Pointer :: fmt ( & * self . _ptr , f)
675
+ }
676
+ }
677
+
671
678
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
672
679
impl < T : Default + Sync + Send > Default for Arc < T > {
673
680
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
Original file line number Diff line number Diff line change @@ -275,6 +275,16 @@ impl<T: fmt::Debug + ?Sized> fmt::Debug for Box<T> {
275
275
}
276
276
}
277
277
278
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
279
+ impl < T > fmt:: Pointer for Box < T > {
280
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
281
+ // It's not possible to extract the inner Uniq directly from the Box,
282
+ // instead we cast it to a *const which aliases the Unique
283
+ let ptr: * const T = & * * self ;
284
+ fmt:: Pointer :: fmt ( & ptr, f)
285
+ }
286
+ }
287
+
278
288
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
279
289
impl < T : ?Sized > Deref for Box < T > {
280
290
type Target = T ;
Original file line number Diff line number Diff line change @@ -634,6 +634,13 @@ impl<T: fmt::Debug> fmt::Debug for Rc<T> {
634
634
}
635
635
}
636
636
637
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
638
+ impl < T > fmt:: Pointer for Rc < T > {
639
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
640
+ fmt:: Pointer :: fmt ( & * self . _ptr , f)
641
+ }
642
+ }
643
+
637
644
/// A weak version of `Rc<T>`.
638
645
///
639
646
/// Weak references do not count when determining if the inner value should be
Original file line number Diff line number Diff line change @@ -94,6 +94,7 @@ use mem;
94
94
use clone:: Clone ;
95
95
use intrinsics;
96
96
use ops:: Deref ;
97
+ use core:: fmt;
97
98
use option:: Option :: { self , Some , None } ;
98
99
use marker:: { PhantomData , Send , Sized , Sync } ;
99
100
use nonzero:: NonZero ;
@@ -570,3 +571,10 @@ impl<T:?Sized> Deref for Unique<T> {
570
571
unsafe { mem:: transmute ( & * self . pointer ) }
571
572
}
572
573
}
574
+
575
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
576
+ impl < T > fmt:: Pointer for Unique < T > {
577
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
578
+ fmt:: Pointer :: fmt ( & * self . pointer , f)
579
+ }
580
+ }
Original file line number Diff line number Diff line change @@ -111,6 +111,13 @@ impl<T: Display> Display for P<T> {
111
111
}
112
112
}
113
113
114
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
115
+ impl < T > fmt:: Pointer for P < T > {
116
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
117
+ fmt:: Pointer :: fmt ( & self . ptr , f)
118
+ }
119
+ }
120
+
114
121
impl < T : Hash > Hash for P < T > {
115
122
fn hash < H : Hasher > ( & self , state : & mut H ) {
116
123
( * * self ) . hash ( state) ;
Original file line number Diff line number Diff line change
1
+ // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2
+ // file at the top-level directory of this distribution and at
3
+ // http://rust-lang.org/COPYRIGHT.
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6
+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7
+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8
+ // option. This file may not be copied, modified, or distributed
9
+ // except according to those terms.
10
+
11
+ #![ feature( libc) ]
12
+ extern crate libc;
13
+ use std:: ptr;
14
+ use std:: rc:: Rc ;
15
+ use std:: sync:: Arc ;
16
+
17
+ fn main ( ) {
18
+ let p: * const libc:: c_void = ptr:: null ( ) ;
19
+ let rc = Rc :: new ( 1usize ) ;
20
+ let arc = Arc :: new ( 1usize ) ;
21
+ let b = Box :: new ( "hi" ) ;
22
+
23
+ let _ = format ! ( "{:p}{:p}{:p}" ,
24
+ rc, arc, b) ;
25
+
26
+ assert_eq ! ( format!( "{:p}" , p) ,
27
+ "0x0" ) ;
28
+ }
You can’t perform that action at this time.
0 commit comments