File tree 1 file changed +16
-0
lines changed
1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ use core::fmt;
18
18
use core:: intrinsics;
19
19
use core:: kinds:: Sized ;
20
20
use core:: mem;
21
+ use core:: ops:: { Deref , DerefMut } ;
21
22
use core:: option:: Option ;
22
23
use core:: raw:: TraitObject ;
23
24
use core:: result:: { Ok , Err , Result } ;
@@ -52,6 +53,14 @@ impl<T> Default for Box<[T]> {
52
53
fn default ( ) -> Box < [ T ] > { box [ ] }
53
54
}
54
55
56
+ impl < Sized ? T > Deref < T > for Box < T > {
57
+ fn deref ( & self ) -> & T { & * * self }
58
+ }
59
+
60
+ impl < Sized ? T > DerefMut < T > for Box < T > {
61
+ fn deref_mut ( & mut self ) -> & mut T { & mut * * self }
62
+ }
63
+
55
64
#[ unstable]
56
65
impl < T : Clone > Clone for Box < T > {
57
66
/// Returns a copy of the owned box.
@@ -183,4 +192,11 @@ mod test {
183
192
let s = format ! ( "{}" , b) ;
184
193
assert_eq ! ( s. as_slice( ) , "&Any" ) ;
185
194
}
195
+
196
+ #[ test]
197
+ fn auto_deref ( ) {
198
+ fn test < U : Deref < int > > ( _: U ) { }
199
+ let foo = box 1 ;
200
+ test ( foo) ;
201
+ }
186
202
}
You can’t perform that action at this time.
0 commit comments