diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2014-05-28 22:26:56 -0700 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2014-07-18 09:01:37 -0700 |
| commit | 02adaca4dc7eb4594d8bda9a7e04bc0247fc2a74 (patch) | |
| tree | 2edb47de67e3c8a0d006f61217d7dffaab824b27 /src/test | |
| parent | 5ddc7b4a252fbebee5f2ac87ed755139816d6823 (diff) | |
| download | rust-02adaca4dc7eb4594d8bda9a7e04bc0247fc2a74.tar.gz rust-02adaca4dc7eb4594d8bda9a7e04bc0247fc2a74.zip | |
librustc: Implement unboxed closures with mutable receivers
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/compile-fail/borrowck-overloaded-call.rs | 6 | ||||
| -rw-r--r-- | src/test/compile-fail/overloaded-calls-bad.rs | 2 | ||||
| -rw-r--r-- | src/test/compile-fail/overloaded-calls-nontuple.rs | 2 | ||||
| -rw-r--r-- | src/test/compile-fail/unboxed-closures-type-mismatch.rs | 19 | ||||
| -rw-r--r-- | src/test/compile-fail/unboxed-closures-vtable-mismatch.rs | 25 | ||||
| -rw-r--r-- | src/test/run-pass/fn-trait-sugar.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass/issue-14958.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass/issue-14959.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass/overloaded-calls-simple.rs | 16 | ||||
| -rw-r--r-- | src/test/run-pass/overloaded-calls-zero-args.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass/unboxed-closures-boxed.rs | 25 | ||||
| -rw-r--r-- | src/test/run-pass/unboxed-closures-generic.rs | 25 | ||||
| -rw-r--r-- | src/test/run-pass/unboxed-closures-simple.rs | 19 |
13 files changed, 130 insertions, 17 deletions
diff --git a/src/test/compile-fail/borrowck-overloaded-call.rs b/src/test/compile-fail/borrowck-overloaded-call.rs index 349a20313fa..f134c2aa09b 100644 --- a/src/test/compile-fail/borrowck-overloaded-call.rs +++ b/src/test/compile-fail/borrowck-overloaded-call.rs @@ -18,7 +18,7 @@ struct SFn { } impl Fn<(int,),int> for SFn { - fn call(&self, (z,): (int,)) -> int { + extern "rust-call" fn call(&self, (z,): (int,)) -> int { self.x * self.y * z } } @@ -29,7 +29,7 @@ struct SFnMut { } impl FnMut<(int,),int> for SFnMut { - fn call_mut(&mut self, (z,): (int,)) -> int { + extern "rust-call" fn call_mut(&mut self, (z,): (int,)) -> int { self.x * self.y * z } } @@ -39,7 +39,7 @@ struct SFnOnce { } impl FnOnce<(String,),uint> for SFnOnce { - fn call_once(self, (z,): (String,)) -> uint { + extern "rust-call" fn call_once(self, (z,): (String,)) -> uint { self.x.len() + z.len() } } diff --git a/src/test/compile-fail/overloaded-calls-bad.rs b/src/test/compile-fail/overloaded-calls-bad.rs index 3c03c874757..cc01c0b3c9f 100644 --- a/src/test/compile-fail/overloaded-calls-bad.rs +++ b/src/test/compile-fail/overloaded-calls-bad.rs @@ -18,7 +18,7 @@ struct S { } impl FnMut<(int,),int> for S { - fn call_mut(&mut self, (z,): (int,)) -> int { + extern "rust-call" fn call_mut(&mut self, (z,): (int,)) -> int { self.x * self.y * z } } diff --git a/src/test/compile-fail/overloaded-calls-nontuple.rs b/src/test/compile-fail/overloaded-calls-nontuple.rs index 9bbc4ab3ba3..ee2fe352247 100644 --- a/src/test/compile-fail/overloaded-calls-nontuple.rs +++ b/src/test/compile-fail/overloaded-calls-nontuple.rs @@ -18,7 +18,7 @@ struct S { } impl FnMut<int,int> for S { - fn call_mut(&mut self, z: int) -> int { + extern "rust-call" fn call_mut(&mut self, z: int) -> int { self.x + self.y + z } } diff --git a/src/test/compile-fail/unboxed-closures-type-mismatch.rs b/src/test/compile-fail/unboxed-closures-type-mismatch.rs new file mode 100644 index 00000000000..09f13b77386 --- /dev/null +++ b/src/test/compile-fail/unboxed-closures-type-mismatch.rs @@ -0,0 +1,19 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(unboxed_closures)] + +use std::ops::FnMut; + +pub fn main() { + let mut f = |&mut: x: int, y: int| -> int { x + y }; + let z = f.call_mut((1u, 2)); //~ ERROR mismatched types + println!("{}", z); +} diff --git a/src/test/compile-fail/unboxed-closures-vtable-mismatch.rs b/src/test/compile-fail/unboxed-closures-vtable-mismatch.rs new file mode 100644 index 00000000000..2ee632b9093 --- /dev/null +++ b/src/test/compile-fail/unboxed-closures-vtable-mismatch.rs @@ -0,0 +1,25 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(unboxed_closures)] + +use std::ops::FnMut; + +fn call_it<F:FnMut<(int,int),int>>(y: int, mut f: F) -> int { + f.call_mut((2, y)) +} + +pub fn main() { + let f = |&mut: x: uint, y: int| -> int { (x as int) + y }; + let z = call_it(3, f); //~ ERROR expected core::ops::FnMut + //~^ ERROR expected core::ops::FnMut + println!("{}", z); +} + diff --git a/src/test/run-pass/fn-trait-sugar.rs b/src/test/run-pass/fn-trait-sugar.rs index b0c8d84b664..ccb5634f7a2 100644 --- a/src/test/run-pass/fn-trait-sugar.rs +++ b/src/test/run-pass/fn-trait-sugar.rs @@ -16,7 +16,7 @@ use std::ops::FnMut; struct S; impl FnMut<(int,),int> for S { - fn call_mut(&mut self, (x,): (int,)) -> int { + extern "rust-call" fn call_mut(&mut self, (x,): (int,)) -> int { x * x } } diff --git a/src/test/run-pass/issue-14958.rs b/src/test/run-pass/issue-14958.rs index 045d3cc0458..b53c2258736 100644 --- a/src/test/run-pass/issue-14958.rs +++ b/src/test/run-pass/issue-14958.rs @@ -15,7 +15,7 @@ trait Foo {} struct Bar; impl<'a> std::ops::Fn<(&'a Foo,), ()> for Bar { - fn call(&self, _: (&'a Foo,)) {} + extern "rust-call" fn call(&self, _: (&'a Foo,)) {} } struct Baz; diff --git a/src/test/run-pass/issue-14959.rs b/src/test/run-pass/issue-14959.rs index 7fbb0657c70..af0bc78094e 100644 --- a/src/test/run-pass/issue-14959.rs +++ b/src/test/run-pass/issue-14959.rs @@ -34,7 +34,7 @@ impl Alloy { } impl<'a, 'b> Fn<(&'b mut Response,),()> for SendFile<'a> { - fn call(&self, (_res,): (&'b mut Response,)) {} + extern "rust-call" fn call(&self, (_res,): (&'b mut Response,)) {} } impl<Rq: Request, Rs: Response> Ingot<Rq, Rs> for HelloWorld { diff --git a/src/test/run-pass/overloaded-calls-simple.rs b/src/test/run-pass/overloaded-calls-simple.rs index 33120defedd..76c7e60116f 100644 --- a/src/test/run-pass/overloaded-calls-simple.rs +++ b/src/test/run-pass/overloaded-calls-simple.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(overloaded_calls)] +#![feature(lang_items, overloaded_calls)] use std::ops::{Fn, FnMut, FnOnce}; @@ -18,7 +18,7 @@ struct S1 { } impl FnMut<(int,),int> for S1 { - fn call_mut(&mut self, (z,): (int,)) -> int { + extern "rust-call" fn call_mut(&mut self, (z,): (int,)) -> int { self.x * self.y * z } } @@ -29,7 +29,7 @@ struct S2 { } impl Fn<(int,),int> for S2 { - fn call(&self, (z,): (int,)) -> int { + extern "rust-call" fn call(&self, (z,): (int,)) -> int { self.x * self.y * z } } @@ -40,7 +40,7 @@ struct S3 { } impl FnOnce<(int,int),int> for S3 { - fn call_once(self, (z,zz): (int,int)) -> int { + extern "rust-call" fn call_once(self, (z,zz): (int,int)) -> int { self.x * self.y * z * zz } } @@ -50,21 +50,21 @@ fn main() { x: 3, y: 3, }; - let ans = s(3); - assert_eq!(ans, 27); + let ans = s.call_mut((3,)); + assert_eq!(ans, 27); let s = S2 { x: 3, y: 3, }; - let ans = s(3); + let ans = s.call((3,)); assert_eq!(ans, 27); let s = S3 { x: 3, y: 3, }; - let ans = s(3, 1); + let ans = s.call_once((3, 1)); assert_eq!(ans, 27); } diff --git a/src/test/run-pass/overloaded-calls-zero-args.rs b/src/test/run-pass/overloaded-calls-zero-args.rs index f8f7df6b49b..b868c8c96b5 100644 --- a/src/test/run-pass/overloaded-calls-zero-args.rs +++ b/src/test/run-pass/overloaded-calls-zero-args.rs @@ -18,7 +18,7 @@ struct S { } impl FnMut<(),int> for S { - fn call_mut(&mut self, (): ()) -> int { + extern "rust-call" fn call_mut(&mut self, (): ()) -> int { self.x * self.y } } diff --git a/src/test/run-pass/unboxed-closures-boxed.rs b/src/test/run-pass/unboxed-closures-boxed.rs new file mode 100644 index 00000000000..c4b990abf7e --- /dev/null +++ b/src/test/run-pass/unboxed-closures-boxed.rs @@ -0,0 +1,25 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(unboxed_closures)] + +use std::ops::FnMut; + +fn make_adder(x: int) -> Box<FnMut<(int,),int>> { + (box |&mut: y: int| -> int { x + y }) as Box<FnMut<(int,),int>> +} + +pub fn main() { + let mut adder = make_adder(3); + let z = adder.call_mut((2,)); + println!("{}", z); + assert_eq!(z, 5); +} + diff --git a/src/test/run-pass/unboxed-closures-generic.rs b/src/test/run-pass/unboxed-closures-generic.rs new file mode 100644 index 00000000000..9d1d81fe259 --- /dev/null +++ b/src/test/run-pass/unboxed-closures-generic.rs @@ -0,0 +1,25 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(unboxed_closures)] + +use std::ops::FnMut; + +fn call_it<F:FnMut<(int,int),int>>(y: int, mut f: F) -> int { + f.call_mut((2, y)) +} + +pub fn main() { + let f = |&mut: x: int, y: int| -> int { x + y }; + let z = call_it(3, f); + println!("{}", z); + assert_eq!(z, 5); +} + diff --git a/src/test/run-pass/unboxed-closures-simple.rs b/src/test/run-pass/unboxed-closures-simple.rs new file mode 100644 index 00000000000..f11096ba5ff --- /dev/null +++ b/src/test/run-pass/unboxed-closures-simple.rs @@ -0,0 +1,19 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(unboxed_closures)] + +use std::ops::FnMut; + +pub fn main() { + let mut f = |&mut: x: int, y: int| -> int { x + y }; + let z = f.call_mut((1, 2)); + assert_eq!(z, 3); +} |
