diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index 729d9218a2960..6f73d0f8b76a6 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -936,6 +936,35 @@ impl Hash for Arc { } } +#[stable(feature = "fn_smart_ptr", since = "1.11.0")] +impl Fn for Arc + where F: Fn +{ + extern "rust-call" fn call(&self, args: I) -> Self::Output { + (&**self).call(args) + } +} + +#[stable(feature = "fn_smart_ptr", since = "1.11.0")] +impl FnMut for Arc + where F: Fn +{ + extern "rust-call" fn call_mut(&mut self, args: I) -> Self::Output { + self.call(args) + } +} + +#[stable(feature = "fn_smart_ptr", since = "1.11.0")] +impl FnOnce for Arc + where F: Fn +{ + type Output = F::Output; + extern "rust-call" fn call_once(self, args: I) -> Self::Output { + self.call(args) + } +} + + #[stable(feature = "from_for_ptrs", since = "1.6.0")] impl From for Arc { fn from(t: T) -> Self { @@ -1172,6 +1201,12 @@ mod tests { assert_eq!(format!("{:?}", a), "5"); } + #[test] + fn test_fn() { + let f = Arc::new(|i: i32| -> i32 { i + 1 }); + assert_eq!(Some(1).map(f), Some(2)); + } + // Make sure deriving works with Arc #[derive(Eq, Ord, PartialEq, PartialOrd, Clone, Debug, Default)] struct Foo { diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index 0293d5402c4c9..44973daaaa592 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -90,8 +90,9 @@ #![feature(unique)] #![feature(unsafe_no_drop_flag, filling_drop)] #![feature(unsize)] +#![feature(fn_traits)] -#![cfg_attr(not(test), feature(raw, fn_traits, placement_new_protocol))] +#![cfg_attr(not(test), feature(raw, placement_new_protocol))] #![cfg_attr(test, feature(test, box_heap))] // Allow testing this library diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index cf4fb459bc104..461306d589981 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -693,6 +693,34 @@ impl fmt::Pointer for Rc { } } +#[stable(feature = "fn_smart_ptr", since = "1.11.0")] +impl Fn for Rc + where F: Fn +{ + extern "rust-call" fn call(&self, args: I) -> Self::Output { + (&**self).call(args) + } +} + +#[stable(feature = "fn_smart_ptr", since = "1.11.0")] +impl FnMut for Rc + where F: Fn +{ + extern "rust-call" fn call_mut(&mut self, args: I) -> Self::Output { + self.call(args) + } +} + +#[stable(feature = "fn_smart_ptr", since = "1.11.0")] +impl FnOnce for Rc + where F: Fn +{ + type Output = F::Output; + extern "rust-call" fn call_once(self, args: I) -> Self::Output { + self.call(args) + } +} + #[stable(feature = "from_for_ptrs", since = "1.6.0")] impl From for Rc { fn from(t: T) -> Self { @@ -1137,6 +1165,12 @@ mod tests { assert_eq!(format!("{:?}", foo), "75"); } + #[test] + fn test_fn() { + let f = Rc::new(|i: i32| -> i32 { i + 1 }); + assert_eq!(Some(1).map(f), Some(2)); + } + #[test] fn test_unsized() { let foo: Rc<[i32]> = Rc::new([1, 2, 3]);