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>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user