about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-12-21 00:04:14 -0800
committerAlex Crichton <alex@alexcrichton.com>2014-12-21 09:27:35 -0800
commit40d59e9467cc06f131064dc5a561a1dd8c77cff6 (patch)
treeba71ba2d69c7cb54b81e3fa083e8472c173abe55 /src/liballoc
parentfb6ff04994a61e5c8c6e0a270b5099ec6983ff10 (diff)
parent39f249067a2b0773d887bb311573dc258118d34d (diff)
downloadrust-40d59e9467cc06f131064dc5a561a1dd8c77cff6.tar.gz
rust-40d59e9467cc06f131064dc5a561a1dd8c77cff6.zip
rollup merge of #20052: barosl/deref-for-box
As the previous pull request (#19023) was closed due to inactivity, I steal the chance and open this pull request. :blush:

Fixes #18624.
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/boxed.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs
index 879a8cc6951..ea7b32ace49 100644
--- a/src/liballoc/boxed.rs
+++ b/src/liballoc/boxed.rs
@@ -22,6 +22,7 @@ use core::option::Option;
 use core::raw::TraitObject;
 use core::result::Result;
 use core::result::Result::{Ok, Err};
+use core::ops::{Deref, DerefMut};
 
 /// A value that represents the global exchange heap. This is the default
 /// place that the `box` keyword allocates into when no place is supplied.
@@ -147,6 +148,14 @@ impl fmt::Show for Box<Any+'static> {
     }
 }
 
+impl<Sized? T> Deref<T> for Box<T> {
+    fn deref(&self) -> &T { &**self }
+}
+
+impl<Sized? T> DerefMut<T> for Box<T> {
+    fn deref_mut(&mut self) -> &mut T { &mut **self }
+}
+
 #[cfg(test)]
 mod test {
     #[test]
@@ -193,4 +202,10 @@ mod test {
         let s = format!("{}", b);
         assert_eq!(s, "&Any");
     }
+
+    #[test]
+    fn deref() {
+        fn homura<T: Deref<i32>>(_: T) { }
+        homura(box 765i32);
+    }
 }