From 64b7c22c46b204520a6fae1c5cd750a3d3c6a66a Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 1 Jan 2015 14:53:20 -0500 Subject: core: use assoc types in `Deref[Mut]` --- src/liballoc/arc.rs | 4 +++- src/liballoc/boxed.rs | 8 +++++--- src/liballoc/lib.rs | 1 + src/liballoc/rc.rs | 4 +++- 4 files changed, 12 insertions(+), 5 deletions(-) (limited to 'src/liballoc') diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index 820a3838978..d38b77eb6fd 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -247,7 +247,9 @@ impl BorrowFrom> for T { } #[experimental = "Deref is experimental."] -impl Deref for Arc { +impl Deref for Arc { + type Target = T; + #[inline] fn deref(&self) -> &T { &self.inner().data diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 74f0599e486..0d6ada4b229 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -153,11 +153,13 @@ impl fmt::Show for Box { } } -impl Deref for Box { +impl Deref for Box { + type Target = T; + fn deref(&self) -> &T { &**self } } -impl DerefMut for Box { +impl DerefMut for Box { fn deref_mut(&mut self) -> &mut T { &mut **self } } @@ -210,7 +212,7 @@ mod test { #[test] fn deref() { - fn homura>(_: T) { } + fn homura>(_: T) { } homura(box 765i32); } } diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index 61b5d43d1cb..c4858aea022 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -65,6 +65,7 @@ #![no_std] #![feature(lang_items, phase, unsafe_destructor, default_type_params)] +#![feature(associated_types)] #[phase(plugin, link)] extern crate core; diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index bd250938836..c57231fc434 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -355,7 +355,9 @@ impl BorrowFrom> for T { } #[experimental = "Deref is experimental."] -impl Deref for Rc { +impl Deref for Rc { + type Target = T; + #[inline(always)] fn deref(&self) -> &T { &self.inner().value -- cgit 1.4.1-3-g733a5