Skip to content

Commit 07cdb85

Browse files
committed
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.
1 parent c61d788 commit 07cdb85

File tree

12 files changed

+361
-136
lines changed

12 files changed

+361
-136
lines changed

src/libcollections/btree/set.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,9 @@ mod test {
758758
expected: &'b [int],
759759
}
760760

761-
impl<'a, 'b, 'c> FnMut(&'c int) -> bool for Counter<'a, 'b> {
761+
impl<'a, 'b, 'c> FnMut<(&'c int,)> for Counter<'a, 'b> {
762+
type Output = bool;
763+
762764
extern "rust-call" fn call_mut(&mut self, (&x,): (&'c int,)) -> bool {
763765
assert_eq!(x, self.expected[*self.i]);
764766
*self.i += 1;

src/libcore/ops.rs

Lines changed: 69 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,29 +1117,33 @@ impl<'a, T: ?Sized> DerefMut for &'a mut T {
11171117
#[lang="fn"]
11181118
#[unstable(feature = "core",
11191119
reason = "uncertain about variadic generics, input versus associated types")]
1120-
pub trait Fn<Args,Result> {
1120+
#[cfg(stage0)]
1121+
pub trait Fn<Args,Output> {
11211122
/// This is called when the call operator is used.
1122-
extern "rust-call" fn call(&self, args: Args) -> Result;
1123+
extern "rust-call" fn call(&self, args: Args) -> Output;
11231124
}
11241125

11251126
/// A version of the call operator that takes a mutable receiver.
11261127
#[lang="fn_mut"]
11271128
#[unstable(feature = "core",
11281129
reason = "uncertain about variadic generics, input versus associated types")]
1129-
pub trait FnMut<Args,Result> {
1130+
#[cfg(stage0)]
1131+
pub trait FnMut<Args,Output> {
11301132
/// This is called when the call operator is used.
1131-
extern "rust-call" fn call_mut(&mut self, args: Args) -> Result;
1133+
extern "rust-call" fn call_mut(&mut self, args: Args) -> Output;
11321134
}
11331135

11341136
/// A version of the call operator that takes a by-value receiver.
11351137
#[lang="fn_once"]
11361138
#[unstable(feature = "core",
11371139
reason = "uncertain about variadic generics, input versus associated types")]
1138-
pub trait FnOnce<Args,Result> {
1140+
#[cfg(stage0)]
1141+
pub trait FnOnce<Args,Output> {
11391142
/// This is called when the call operator is used.
1140-
extern "rust-call" fn call_once(self, args: Args) -> Result;
1143+
extern "rust-call" fn call_once(self, args: Args) -> Output;
11411144
}
11421145

1146+
#[cfg(stage0)]
11431147
impl<F: ?Sized, A, R> FnMut<A, R> for F
11441148
where F : Fn<A, R>
11451149
{
@@ -1148,10 +1152,69 @@ impl<F: ?Sized, A, R> FnMut<A, R> for F
11481152
}
11491153
}
11501154

1155+
#[cfg(stage0)]
11511156
impl<F,A,R> FnOnce<A,R> for F
11521157
where F : FnMut<A,R>
11531158
{
11541159
extern "rust-call" fn call_once(mut self, args: A) -> R {
11551160
self.call_mut(args)
11561161
}
11571162
}
1163+
1164+
/// A version of the call operator that takes an immutable receiver.
1165+
#[lang="fn"]
1166+
#[unstable(feature = "core",
1167+
reason = "uncertain about variadic generics, input versus associated types")]
1168+
#[cfg(not(stage0))]
1169+
pub trait Fn<Args> {
1170+
type Output;
1171+
1172+
/// This is called when the call operator is used.
1173+
extern "rust-call" fn call(&self, args: Args) -> Self::Output;
1174+
}
1175+
1176+
/// A version of the call operator that takes a mutable receiver.
1177+
#[lang="fn_mut"]
1178+
#[unstable(feature = "core",
1179+
reason = "uncertain about variadic generics, input versus associated types")]
1180+
#[cfg(not(stage0))]
1181+
pub trait FnMut<Args> {
1182+
type Output;
1183+
1184+
/// This is called when the call operator is used.
1185+
extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output;
1186+
}
1187+
1188+
/// A version of the call operator that takes a by-value receiver.
1189+
#[lang="fn_once"]
1190+
#[unstable(feature = "core",
1191+
reason = "uncertain about variadic generics, input versus associated types")]
1192+
#[cfg(not(stage0))]
1193+
pub trait FnOnce<Args> {
1194+
type Output;
1195+
1196+
/// This is called when the call operator is used.
1197+
extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
1198+
}
1199+
1200+
#[cfg(not(stage0))]
1201+
impl<F: ?Sized, A> FnMut<A> for F
1202+
where F : Fn<A>
1203+
{
1204+
type Output = <F as Fn<A>>::Output;
1205+
1206+
extern "rust-call" fn call_mut(&mut self, args: A) -> <F as Fn<A>>::Output {
1207+
self.call(args)
1208+
}
1209+
}
1210+
1211+
#[cfg(not(stage0))]
1212+
impl<F,A> FnOnce<A> for F
1213+
where F : FnMut<A>
1214+
{
1215+
type Output = <F as FnMut<A>>::Output;
1216+
1217+
extern "rust-call" fn call_once(mut self, args: A) -> <F as FnMut<A>>::Output {
1218+
self.call_mut(args)
1219+
}
1220+
}

src/libcore/str/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,13 +461,24 @@ delegate_iter!{exact u8 : Bytes<'a>}
461461
#[derive(Copy, Clone)]
462462
struct BytesDeref;
463463

464+
#[cfg(stage0)]
464465
impl<'a> Fn(&'a u8) -> u8 for BytesDeref {
465466
#[inline]
466467
extern "rust-call" fn call(&self, (ptr,): (&'a u8,)) -> u8 {
467468
*ptr
468469
}
469470
}
470471

472+
#[cfg(not(stage0))]
473+
impl<'a> Fn<(&'a u8,)> for BytesDeref {
474+
type Output = u8;
475+
476+
#[inline]
477+
extern "rust-call" fn call(&self, (ptr,): (&'a u8,)) -> u8 {
478+
*ptr
479+
}
480+
}
481+
471482
/// An iterator over the substrings of a string, separated by `sep`.
472483
#[derive(Clone)]
473484
struct CharSplits<'a, Sep> {

0 commit comments

Comments
 (0)