diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2015-01-10 11:54:15 -0500 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2015-01-28 05:15:23 -0500 |
| commit | 07cdb853317697c247b41e61f7a429c3fb623524 (patch) | |
| tree | 4b44f3fb2fa20220413aea7b6c844a5b99e9a196 /src/libcore | |
| parent | c61d7889b4bb270102dafe54cdfffbd737d168ff (diff) | |
| download | rust-07cdb853317697c247b41e61f7a429c3fb623524.tar.gz rust-07cdb853317697c247b41e61f7a429c3fb623524.zip | |
Move return type an associated type of the `Fn*` traits. Mostly this involves tweaking things in
the compiler that assumed two input types to assume two ouputs; we also have to teach `project.rs` to project `Output` from the unboxed closure and fn traits.
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/ops.rs | 75 | ||||
| -rw-r--r-- | src/libcore/str/mod.rs | 11 |
2 files changed, 80 insertions, 6 deletions
diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index d482888e3bc..0e99a2c9c3e 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -1117,29 +1117,33 @@ impl<'a, T: ?Sized> DerefMut for &'a mut T { #[lang="fn"] #[unstable(feature = "core", reason = "uncertain about variadic generics, input versus associated types")] -pub trait Fn<Args,Result> { +#[cfg(stage0)] +pub trait Fn<Args,Output> { /// This is called when the call operator is used. - extern "rust-call" fn call(&self, args: Args) -> Result; + extern "rust-call" fn call(&self, args: Args) -> Output; } /// A version of the call operator that takes a mutable receiver. #[lang="fn_mut"] #[unstable(feature = "core", reason = "uncertain about variadic generics, input versus associated types")] -pub trait FnMut<Args,Result> { +#[cfg(stage0)] +pub trait FnMut<Args,Output> { /// This is called when the call operator is used. - extern "rust-call" fn call_mut(&mut self, args: Args) -> Result; + extern "rust-call" fn call_mut(&mut self, args: Args) -> Output; } /// A version of the call operator that takes a by-value receiver. #[lang="fn_once"] #[unstable(feature = "core", reason = "uncertain about variadic generics, input versus associated types")] -pub trait FnOnce<Args,Result> { +#[cfg(stage0)] +pub trait FnOnce<Args,Output> { /// This is called when the call operator is used. - extern "rust-call" fn call_once(self, args: Args) -> Result; + extern "rust-call" fn call_once(self, args: Args) -> Output; } +#[cfg(stage0)] impl<F: ?Sized, A, R> FnMut<A, R> for F where F : Fn<A, R> { @@ -1148,6 +1152,7 @@ impl<F: ?Sized, A, R> FnMut<A, R> for F } } +#[cfg(stage0)] impl<F,A,R> FnOnce<A,R> for F where F : FnMut<A,R> { @@ -1155,3 +1160,61 @@ impl<F,A,R> FnOnce<A,R> for F self.call_mut(args) } } + +/// A version of the call operator that takes an immutable receiver. +#[lang="fn"] +#[unstable(feature = "core", + reason = "uncertain about variadic generics, input versus associated types")] +#[cfg(not(stage0))] +pub trait Fn<Args> { + type Output; + + /// This is called when the call operator is used. + extern "rust-call" fn call(&self, args: Args) -> Self::Output; +} + +/// A version of the call operator that takes a mutable receiver. +#[lang="fn_mut"] +#[unstable(feature = "core", + reason = "uncertain about variadic generics, input versus associated types")] +#[cfg(not(stage0))] +pub trait FnMut<Args> { + type Output; + + /// This is called when the call operator is used. + extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output; +} + +/// A version of the call operator that takes a by-value receiver. +#[lang="fn_once"] +#[unstable(feature = "core", + reason = "uncertain about variadic generics, input versus associated types")] +#[cfg(not(stage0))] +pub trait FnOnce<Args> { + type Output; + + /// This is called when the call operator is used. + extern "rust-call" fn call_once(self, args: Args) -> Self::Output; +} + +#[cfg(not(stage0))] +impl<F: ?Sized, A> FnMut<A> for F + where F : Fn<A> +{ + type Output = <F as Fn<A>>::Output; + + extern "rust-call" fn call_mut(&mut self, args: A) -> <F as Fn<A>>::Output { + self.call(args) + } +} + +#[cfg(not(stage0))] +impl<F,A> FnOnce<A> for F + where F : FnMut<A> +{ + type Output = <F as FnMut<A>>::Output; + + extern "rust-call" fn call_once(mut self, args: A) -> <F as FnMut<A>>::Output { + self.call_mut(args) + } +} diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 5b94733ea6f..101d349c351 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -461,6 +461,7 @@ delegate_iter!{exact u8 : Bytes<'a>} #[derive(Copy, Clone)] struct BytesDeref; +#[cfg(stage0)] impl<'a> Fn(&'a u8) -> u8 for BytesDeref { #[inline] extern "rust-call" fn call(&self, (ptr,): (&'a u8,)) -> u8 { @@ -468,6 +469,16 @@ impl<'a> Fn(&'a u8) -> u8 for BytesDeref { } } +#[cfg(not(stage0))] +impl<'a> Fn<(&'a u8,)> for BytesDeref { + type Output = u8; + + #[inline] + extern "rust-call" fn call(&self, (ptr,): (&'a u8,)) -> u8 { + *ptr + } +} + /// An iterator over the substrings of a string, separated by `sep`. #[derive(Clone)] struct CharSplits<'a, Sep> { |
