Make the Fn traits inherit from one another and remove the bridging
impls. This requires: 1. modifying trait selection a bit so that when we synthesize impls for fn pointers and closures; 2. adding code to trans so that we can synthesize a `FnMut`/`FnOnce` impl for a `Fn` closure and so forth.
This commit is contained in:
@@ -1136,6 +1136,7 @@ impl<'a, T: ?Sized> DerefMut for &'a mut T {
|
||||
#[lang="fn"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_paren_sugar]
|
||||
#[cfg(stage0)]
|
||||
pub trait Fn<Args> {
|
||||
/// The returned type after the call operator is used.
|
||||
type Output;
|
||||
@@ -1144,10 +1145,21 @@ pub trait Fn<Args> {
|
||||
extern "rust-call" fn call(&self, args: Args) -> Self::Output;
|
||||
}
|
||||
|
||||
/// A version of the call operator that takes an immutable receiver.
|
||||
#[lang="fn"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_paren_sugar]
|
||||
#[cfg(not(stage0))]
|
||||
pub trait Fn<Args> : FnMut<Args> {
|
||||
/// 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"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_paren_sugar]
|
||||
#[cfg(stage0)]
|
||||
pub trait FnMut<Args> {
|
||||
/// The returned type after the call operator is used.
|
||||
type Output;
|
||||
@@ -1156,6 +1168,16 @@ pub trait FnMut<Args> {
|
||||
extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output;
|
||||
}
|
||||
|
||||
/// A version of the call operator that takes a mutable receiver.
|
||||
#[lang="fn_mut"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_paren_sugar]
|
||||
#[cfg(not(stage0))]
|
||||
pub trait FnMut<Args> : FnOnce<Args> {
|
||||
/// 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"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@@ -1168,6 +1190,7 @@ pub trait FnOnce<Args> {
|
||||
extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl<F: ?Sized, A> FnMut<A> for F
|
||||
where F : Fn<A>
|
||||
{
|
||||
@@ -1178,6 +1201,7 @@ impl<F: ?Sized, A> FnMut<A> for F
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl<F,A> FnOnce<A> for F
|
||||
where F : FnMut<A>
|
||||
{
|
||||
|
||||
@@ -29,7 +29,7 @@ use iter::{Map, Iterator, IteratorExt, DoubleEndedIterator};
|
||||
use marker::Sized;
|
||||
use mem;
|
||||
use num::Int;
|
||||
use ops::{Fn, FnMut};
|
||||
use ops::{Fn, FnMut, FnOnce};
|
||||
use option::Option::{self, None, Some};
|
||||
use raw::{Repr, Slice};
|
||||
use result::Result::{self, Ok, Err};
|
||||
@@ -524,6 +524,7 @@ delegate_iter!{exact u8 : Bytes<'a>}
|
||||
#[derive(Copy, Clone)]
|
||||
struct BytesDeref;
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl<'a> Fn<(&'a u8,)> for BytesDeref {
|
||||
type Output = u8;
|
||||
|
||||
@@ -533,6 +534,32 @@ impl<'a> Fn<(&'a u8,)> for BytesDeref {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
impl<'a> Fn<(&'a u8,)> for BytesDeref {
|
||||
#[inline]
|
||||
extern "rust-call" fn call(&self, (ptr,): (&'a u8,)) -> u8 {
|
||||
*ptr
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
impl<'a> FnMut<(&'a u8,)> for BytesDeref {
|
||||
#[inline]
|
||||
extern "rust-call" fn call_mut(&mut self, (ptr,): (&'a u8,)) -> u8 {
|
||||
Fn::call(&*self, (ptr,))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
impl<'a> FnOnce<(&'a u8,)> for BytesDeref {
|
||||
type Output = u8;
|
||||
|
||||
#[inline]
|
||||
extern "rust-call" fn call_once(self, (ptr,): (&'a u8,)) -> u8 {
|
||||
Fn::call(&self, (ptr,))
|
||||
}
|
||||
}
|
||||
|
||||
/// An iterator over the substrings of a string, separated by `sep`.
|
||||
struct CharSplits<'a, P: Pattern<'a>> {
|
||||
/// The slice remaining to be iterated
|
||||
|
||||
Reference in New Issue
Block a user