]> git.lizzy.rs Git - rust.git/commitdiff
fix cfail tests
authorJorge Aparicio <japaricious@gmail.com>
Sat, 3 Jan 2015 15:45:00 +0000 (10:45 -0500)
committerJorge Aparicio <japaricious@gmail.com>
Mon, 5 Jan 2015 22:22:17 +0000 (17:22 -0500)
101 files changed:
src/test/compile-fail/access-mode-in-closures.rs
src/test/compile-fail/assign-to-method.rs
src/test/compile-fail/block-coerce-no-2.rs [deleted file]
src/test/compile-fail/block-coerce-no.rs [deleted file]
src/test/compile-fail/borrowck-assign-comp-idx.rs
src/test/compile-fail/borrowck-autoref-3261.rs
src/test/compile-fail/borrowck-block-unint.rs
src/test/compile-fail/borrowck-call-is-borrow-issue-12224.rs
src/test/compile-fail/borrowck-closures-mut-and-imm.rs
src/test/compile-fail/borrowck-closures-mut-of-imm.rs
src/test/compile-fail/borrowck-closures-two-mut.rs
src/test/compile-fail/borrowck-closures-unique-imm.rs
src/test/compile-fail/borrowck-closures-unique.rs
src/test/compile-fail/borrowck-closures-use-after-free.rs
src/test/compile-fail/borrowck-init-in-called-fn-expr.rs
src/test/compile-fail/borrowck-init-in-fn-expr.rs
src/test/compile-fail/borrowck-insert-during-each.rs
src/test/compile-fail/borrowck-lend-flow-if.rs
src/test/compile-fail/borrowck-lend-flow-loop.rs
src/test/compile-fail/borrowck-lend-flow.rs
src/test/compile-fail/borrowck-loan-blocks-move-cc.rs
src/test/compile-fail/borrowck-loan-blocks-mut-uniq.rs
src/test/compile-fail/borrowck-loan-rcvr.rs
src/test/compile-fail/borrowck-loan-vec-content.rs
src/test/compile-fail/borrowck-move-by-capture.rs
src/test/compile-fail/borrowck-move-in-irrefut-pat.rs
src/test/compile-fail/borrowck-report-with-custom-diagnostic.rs
src/test/compile-fail/break-outside-loop.rs
src/test/compile-fail/closure-bounds-cant-promote-superkind-in-struct.rs
src/test/compile-fail/closure-bounds-not-builtin.rs [deleted file]
src/test/compile-fail/closure-bounds-static-cant-capture-borrowed.rs
src/test/compile-fail/closure-bounds-subtype.rs
src/test/compile-fail/closure-reform-bad.rs
src/test/compile-fail/closure-that-fails.rs [deleted file]
src/test/compile-fail/coerce-bare-fn-to-closure-and-proc.rs [deleted file]
src/test/compile-fail/dead-code-closure-bang.rs
src/test/compile-fail/extern-wrong-value-type.rs
src/test/compile-fail/fn-variance-1.rs
src/test/compile-fail/immut-function-arguments.rs
src/test/compile-fail/issue-10291.rs
src/test/compile-fail/issue-11192.rs
src/test/compile-fail/issue-11873.rs
src/test/compile-fail/issue-14182.rs
src/test/compile-fail/issue-16939.rs
src/test/compile-fail/issue-17636.rs [deleted file]
src/test/compile-fail/issue-17651.rs
src/test/compile-fail/issue-18343.rs
src/test/compile-fail/issue-18345.rs [deleted file]
src/test/compile-fail/issue-18783.rs
src/test/compile-fail/issue-19009.rs [deleted file]
src/test/compile-fail/issue-19141.rs [deleted file]
src/test/compile-fail/issue-20193.rs [deleted file]
src/test/compile-fail/issue-20228-1.rs [deleted file]
src/test/compile-fail/issue-20228-2.rs [deleted file]
src/test/compile-fail/issue-2149.rs
src/test/compile-fail/issue-3044.rs
src/test/compile-fail/issue-3563.rs
src/test/compile-fail/issue-4335.rs
src/test/compile-fail/issue-4523.rs [deleted file]
src/test/compile-fail/issue-5216.rs
src/test/compile-fail/issue-5239-1.rs
src/test/compile-fail/issue-6801.rs
src/test/compile-fail/issue-7573.rs
src/test/compile-fail/kindck-copy.rs
src/test/compile-fail/kindck-send-object.rs
src/test/compile-fail/lint-unused-mut-variables.rs
src/test/compile-fail/lint-unused-unsafe.rs
src/test/compile-fail/liveness-closure-require-ret.rs
src/test/compile-fail/moves-based-on-type-block-bad.rs
src/test/compile-fail/moves-based-on-type-move-out-of-closure-env-issue-1965.rs
src/test/compile-fail/moves-based-on-type-no-recursive-stack-closure.rs
src/test/compile-fail/pptypedef.rs
src/test/compile-fail/refutable-pattern-in-fn-arg.rs
src/test/compile-fail/region-bound-on-closure-outlives-call.rs
src/test/compile-fail/regionck-closure-lifetimes.rs [deleted file]
src/test/compile-fail/regions-addr-of-upvar-self.rs
src/test/compile-fail/regions-bounded-by-send.rs
src/test/compile-fail/regions-creating-enums.rs
src/test/compile-fail/regions-escape-bound-fn-2.rs
src/test/compile-fail/regions-escape-bound-fn.rs
src/test/compile-fail/regions-escape-method.rs
src/test/compile-fail/regions-escape-via-trait-or-not.rs
src/test/compile-fail/regions-fn-subtyping.rs [deleted file]
src/test/compile-fail/regions-fns.rs [deleted file]
src/test/compile-fail/regions-free-region-ordering-callee.rs
src/test/compile-fail/regions-freevar.rs [deleted file]
src/test/compile-fail/regions-infer-at-fn-not-param.rs
src/test/compile-fail/regions-infer-borrow-scope-within-loop.rs
src/test/compile-fail/regions-infer-call-3.rs
src/test/compile-fail/regions-infer-invariance-due-to-mutability-3.rs
src/test/compile-fail/regions-infer-invariance-due-to-mutability-4.rs
src/test/compile-fail/regions-infer-not-param.rs
src/test/compile-fail/regions-name-undeclared.rs
src/test/compile-fail/regions-nested-fns-2.rs
src/test/compile-fail/regions-nested-fns.rs
src/test/compile-fail/regions-ref-in-fn-arg.rs
src/test/compile-fail/regions-ret-borrowed-1.rs
src/test/compile-fail/regions-ret-borrowed.rs
src/test/compile-fail/regions-return-ref-to-upvar-issue-17403.rs
src/test/compile-fail/regions-steal-closure.rs
src/test/compile-fail/type-arg-out-of-scope.rs

index e1696f0e63ed7607a52fca0aa55f590009b1ba14..f15157d126ed76ee64c85f474f66a9c42efcdeb6 100644 (file)
@@ -11,7 +11,7 @@
 
 struct sty(Vec<int> );
 
-fn unpack(_unpack: |v: &sty| -> Vec<int> ) {}
+fn unpack<F>(_unpack: F) where F: FnOnce(&sty) -> Vec<int> {}
 
 fn main() {
     let _foo = unpack(|s| {
index 453d7ffdad5c3249945623fb8b4c651b2722fb3c..f14668192f8503cfd0d4485b900ef5d2b1247303 100644 (file)
@@ -27,5 +27,5 @@ fn cat(in_x : uint, in_y : int) -> cat {
 
 fn main() {
   let nyan : cat = cat(52u, 99);
-  nyan.speak = || println!("meow"); //~ ERROR attempted to take value of method
+  nyan.speak = |&:| println!("meow"); //~ ERROR attempted to take value of method
 }
diff --git a/src/test/compile-fail/block-coerce-no-2.rs b/src/test/compile-fail/block-coerce-no-2.rs
deleted file mode 100644 (file)
index e268b0e..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-// 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.
-
-// Make sure that fn-to-block coercion isn't incorrectly lifted over
-// other tycons.
-
-fn main() {
-    fn f(f: fn(fn(fn()))) {
-    }
-
-    fn g(f: fn(||)) {
-    }
-
-    f(g);
-    //~^ ERROR mismatched types: expected `fn(fn(fn()))`
-}
diff --git a/src/test/compile-fail/block-coerce-no.rs b/src/test/compile-fail/block-coerce-no.rs
deleted file mode 100644 (file)
index 76af956..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-// 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.
-
-// Make sure that fn-to-block coercion isn't incorrectly lifted over
-// other tycons.
-
-fn coerce(b: ||) -> extern fn() {
-    fn lol(f: extern fn(v: ||) -> extern fn(),
-           g: ||) -> extern fn() { return f(g); }
-    fn fn_id(f: extern fn()) -> extern fn() { return f }
-    return lol(fn_id, b);
-    //~^ ERROR mismatched types
-}
-
-fn main() {
-    let i = 8i;
-    let f = coerce(|| println!("{}", i) );
-    f();
-}
index e14911d3508da46ddd106a4cb141152f1efe27e1..a6801a6a51a52d10ae228bed6b16caa563570240 100644 (file)
@@ -24,7 +24,7 @@ fn a() {
     println!("{}", *q);
 }
 
-fn borrow(_x: &[int], _f: ||) {}
+fn borrow<F>(_x: &[int], _f: F) where F: FnOnce() {}
 
 fn b() {
     // here we alias the mutable vector into an imm slice and try to
index 1b4e5891f941de493f284cf808da66326a7b88ea..2804b8c48a703f4f4be64c71d3ac5effd36452af 100644 (file)
@@ -13,7 +13,7 @@ enum Either<T, U> { Left(T), Right(U) }
 struct X(Either<(uint,uint), fn()>);
 
 impl X {
-    pub fn with(&self, blk: |x: &Either<(uint,uint), fn()>|) {
+    pub fn with<F>(&self, blk: F) where F: FnOnce(&Either<(uint, uint), fn()>) {
         let X(ref e) = *self;
         blk(e)
     }
@@ -25,7 +25,7 @@ fn main() {
         |opt| { //~ ERROR cannot borrow `x` as mutable more than once at a time
             match opt {
                 &Either::Right(ref f) => {
-                    x = X(Either::Left((0,0)));
+                    x = X(Either::Left((0, 0)));
                     (*f)()
                 },
                 _ => panic!()
index a37717ed5d99897d99e26165b6a65b55e5f3eee0..e519e57d178c85b10dc9fd68ec308aecdcc660e7 100644 (file)
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-fn force(f: ||) { f(); }
+fn force<F>(f: F) where F: FnOnce() { f(); }
 fn main() {
     let x: int;
     force(|| {  //~ ERROR capture of possibly uninitialized variable: `x`
index 002ae5a7d28b418ab394d40247ff8aa100f4bf42..6dbdff9441d55a8b0283bedfc3598c5b88e206a4 100644 (file)
 
 // Ensure that invoking a closure counts as a unique immutable borrow
 
+#![feature(unboxed_closures)]
 
-type Fn<'a> = ||:'a;
+type Fn<'a> = Box<FnMut() + 'a>;
 
 struct Test<'a> {
-    f: ||: 'a
+    f: Box<FnMut() + 'a>
 }
 
-fn call(f: |Fn|) {
-    f(|| {
-    //~^ ERROR: closure requires unique access to `f` but it is already borrowed
-        f(|| {})
+fn call<F>(mut f: F) where F: FnMut(Fn) {
+    f(box || {
+    //~^ ERROR: cannot borrow `f` as mutable more than once
+        f(box || {})
     });
 }
 
 fn test1() {
-    call(|a| {
-        a();
+    call(|mut a| {
+        a.call_mut(());
     });
 }
 
-fn test2(f: &||) {
-    (*f)(); //~ ERROR: closure invocation in a `&` reference
+fn test2<F>(f: &F) where F: FnMut() {
+    (*f)(); //~ ERROR: cannot borrow immutable dereference of `&`-pointer `*f` as mutable
 }
 
-fn test3(f: &mut ||) {
+fn test3<F>(f: &mut F) where F: FnMut() {
     (*f)();
 }
 
 fn test4(f: &Test) {
-    (f.f)() //~ ERROR: closure invocation in a `&` reference
+    f.f.call_mut(()) //~ ERROR: cannot borrow immutable dereference of `Box` `*f.f` as mutable
 }
 
 fn test5(f: &mut Test) {
-    (f.f)()
+    f.f.call_mut(())
 }
 
 fn test6() {
-    let f = || {};
-    (|| {
+    let mut f = |&mut:| {};
+    (|&mut:| {
         f();
     })();
 }
 
 fn test7() {
-    fn foo(_: |g: |int|, b: int|) {}
-    let f = |g: |int|, b: int| {};
-    f(|a| { //~ ERROR: cannot borrow `f` as immutable because previous closure
+    fn foo<F>(_: F) where F: FnMut(Box<FnMut(int)>, int) {}
+    let mut f = |&mut: g: Box<FnMut(int)>, b: int| {};
+    f(box |a| { //~ ERROR: cannot borrow `f` as immutable because it is also borrowed as mutable
         foo(f); //~ ERROR: cannot move out of captured outer variable
     }, 3);
 }
index 886026e45d90f1f8c89734a3b04a0f77e2b1b572..47a47d0443255aab3e06d4d13f3970637a47593b 100644 (file)
@@ -22,37 +22,37 @@ fn set(x: &mut int) {
 
 fn a() {
     let mut x = 3i;
-    let c1 = || x = 4;
-    let c2 = || x * 5; //~ ERROR cannot borrow `x`
+    let c1 = |&mut:| x = 4;
+    let c2 = |&mut:| x * 5; //~ ERROR cannot borrow `x`
 }
 
 fn b() {
     let mut x = 3i;
-    let c1 = || set(&mut x);
-    let c2 = || get(&x); //~ ERROR cannot borrow `x`
+    let c1 = |&mut:| set(&mut x);
+    let c2 = |&mut:| get(&x); //~ ERROR cannot borrow `x`
 }
 
 fn c() {
     let mut x = 3i;
-    let c1 = || set(&mut x);
-    let c2 = || x * 5; //~ ERROR cannot borrow `x`
+    let c1 = |&mut:| set(&mut x);
+    let c2 = |&mut:| x * 5; //~ ERROR cannot borrow `x`
 }
 
 fn d() {
     let mut x = 3i;
-    let c2 = || x * 5;
+    let c2 = |&mut:| x * 5;
     x = 5; //~ ERROR cannot assign
 }
 
 fn e() {
     let mut x = 3i;
-    let c1 = || get(&x);
+    let c1 = |&mut:| get(&x);
     x = 5; //~ ERROR cannot assign
 }
 
 fn f() {
     let mut x = box 3i;
-    let c1 = || get(&*x);
+    let c1 = |&mut:| get(&*x);
     *x = 5; //~ ERROR cannot assign
 }
 
@@ -62,7 +62,7 @@ struct Foo {
     }
 
     let mut x = box Foo { f: box 3 };
-    let c1 = || get(&*x.f);
+    let c1 = |&mut:| get(&*x.f);
     *x.f = 5; //~ ERROR cannot assign to `*x.f`
 }
 
@@ -72,8 +72,8 @@ struct Foo {
     }
 
     let mut x = box Foo { f: box 3 };
-    let c1 = || get(&*x.f);
-    let c2 = || *x.f = 5; //~ ERROR cannot borrow `x` as mutable
+    let c1 = |&mut:| get(&*x.f);
+    let c2 = |&mut:| *x.f = 5; //~ ERROR cannot borrow `x` as mutable
 }
 
 fn main() {
index 8163df5e967cd52f8ec9ea9225f3c05bfb4a5952..30e1421ba2660fb873bba3bc85488f9ab9abe519 100644 (file)
@@ -20,9 +20,9 @@ fn set(x: &mut int) {
 }
 
 fn a(x: &int) {
-    let c1 = || set(&mut *x);
+    let c1 = |&mut:| set(&mut *x);
     //~^ ERROR cannot borrow
-    let c2 = || set(&mut *x);
+    let c2 = |&mut:| set(&mut *x);
     //~^ ERROR cannot borrow
     //~| ERROR closure requires unique access
 }
index 6d382854d49f2b2b9cadf49bceb100effba039b2..0f284b5384913f41dce038cdd46da80b67894333 100644 (file)
@@ -15,8 +15,8 @@
 
 fn a() {
     let mut x = 3i;
-    let c1 = || x = 4;
-    let c2 = || x = 5; //~ ERROR cannot borrow `x` as mutable more than once
+    let c1 = |&mut:| x = 4;
+    let c2 = |&mut:| x = 5; //~ ERROR cannot borrow `x` as mutable more than once
 }
 
 fn set(x: &mut int) {
@@ -25,20 +25,20 @@ fn set(x: &mut int) {
 
 fn b() {
     let mut x = 3i;
-    let c1 = || set(&mut x);
-    let c2 = || set(&mut x); //~ ERROR cannot borrow `x` as mutable more than once
+    let c1 = |&mut:| set(&mut x);
+    let c2 = |&mut:| set(&mut x); //~ ERROR cannot borrow `x` as mutable more than once
 }
 
 fn c() {
     let mut x = 3i;
-    let c1 = || x = 5;
-    let c2 = || set(&mut x); //~ ERROR cannot borrow `x` as mutable more than once
+    let c1 = |&mut:| x = 5;
+    let c2 = |&mut:| set(&mut x); //~ ERROR cannot borrow `x` as mutable more than once
 }
 
 fn d() {
     let mut x = 3i;
-    let c1 = || x = 5;
-    let c2 = || { let _y = || set(&mut x); }; // (nested closure)
+    let c1 = |&mut:| x = 5;
+    let c2 = |&mut:| { let _y = |&mut:| set(&mut x); }; // (nested closure)
     //~^ ERROR cannot borrow `x` as mutable more than once
 }
 
@@ -48,8 +48,8 @@ struct Foo {
     }
 
     let mut x = box Foo { f: box 3 };
-    let c1 = || set(&mut *x.f);
-    let c2 = || set(&mut *x.f);
+    let c1 = |&mut:| set(&mut *x.f);
+    let c2 = |&mut:| set(&mut *x.f);
     //~^ ERROR cannot borrow `x` as mutable more than once
 }
 
index dfe5de09c50979284ebd5049d16e8f9916ee5c33..a9cc9e967f6ff70ecdabda9052ef7f118864f3d6 100644 (file)
@@ -16,7 +16,7 @@ pub fn main() {
     let mut this = &mut Foo {
         x: 1,
     };
-    let r = || {
+    let mut r = |&mut:| {
         let p = &this.x;
         &mut this.x; //~ ERROR cannot borrow
     };
index febc84ccd44613c8fb7401c8c852cad9c880ca8b..9a772cc49b87b62ac8b6e84caa81bbf0b7b0467f 100644 (file)
@@ -23,27 +23,27 @@ fn set(x: &mut int) -> int {
 }
 
 fn a(x: &mut int) {
-    let c1 = || get(x);
-    let c2 = || get(x);
+    let c1 = |&mut:| get(x);
+    let c2 = |&mut:| get(x);
 }
 
 fn b(x: &mut int) {
-    let c1 = || get(x);
-    let c2 = || set(x); //~ ERROR closure requires unique access to `x`
+    let c1 = |&mut:| get(x);
+    let c2 = |&mut:| set(x); //~ ERROR closure requires unique access to `x`
 }
 
 fn c(x: &mut int) {
-    let c1 = || get(x);
-    let c2 = || { get(x); set(x); }; //~ ERROR closure requires unique access to `x`
+    let c1 = |&mut:| get(x);
+    let c2 = |&mut:| { get(x); set(x); }; //~ ERROR closure requires unique access to `x`
 }
 
 fn d(x: &mut int) {
-    let c1 = || set(x);
-    let c2 = || set(x); //~ ERROR closure requires unique access to `x`
+    let c1 = |&mut:| set(x);
+    let c2 = |&mut:| set(x); //~ ERROR closure requires unique access to `x`
 }
 
 fn e(x: &mut int) {
-    let c1: || = || x = panic!(); //~ ERROR closure cannot assign to immutable local variable
+    let c1 = |&mut:| x = panic!(); //~ ERROR closure cannot assign to immutable local variable
 }
 
 fn main() {
index 735d9ece9b1a500844cf22701ee8f9412cfeee25..23c90fcf574d5bb45b920cb6ba60a6b84475f31b 100644 (file)
@@ -25,7 +25,7 @@ fn drop(&mut self) {
 
 fn main() {
   let mut ptr = box Foo { x: 0 };
-  let test = |foo: &Foo| {
+  let mut test = |&mut: foo: &Foo| {
     ptr = box Foo { x: ptr.x + 1 };
   };
   test(&*ptr); //~ ERROR cannot borrow `*ptr`
index d759a5738bd22703b7187705b8dd3fdca5511201..5496a9dd4b3611c78b2a0fc70f7f4845ea5f6d08 100644 (file)
@@ -9,7 +9,7 @@
 // except according to those terms.
 
 fn main() {
-    let j: || -> int = || {
+    let j = |&:| -> int {
         let i: int;
         i //~ ERROR use of possibly uninitialized variable: `i`
     };
index 07e2ff084664dcfc11d8a8abc97baf0341e165ca..33c284c71b341df0558956f2e861747d3d5fa37f 100644 (file)
@@ -9,7 +9,7 @@
 // except according to those terms.
 
 fn main() {
-    let f: || -> int = || {
+    let f  = |&:| -> int {
         let i: int;
         i //~ ERROR use of possibly uninitialized variable: `i`
     };
index a84a025d8a8ee9d89dcd4323be6ad169781dd34c..0428ee83065173a99156ebf4a7bfa7e78d8cbdd5 100644 (file)
@@ -16,7 +16,7 @@ struct Foo {
 }
 
 impl Foo {
-    pub fn foo(&mut self, fun: |&int|) {
+    pub fn foo<F>(&mut self, mut fun: F) where F: FnMut(&int) {
         for f in self.n.iter() {
             fun(f);
         }
index 8a7ecde700ae6f7cbab94f64f68d198002007978..f798d170f963b35dd8a2f255c96f5c6df4694596 100644 (file)
@@ -18,7 +18,7 @@
 fn borrow(_v: &int) {}
 fn borrow_mut(_v: &mut int) {}
 fn cond() -> bool { panic!() }
-fn for_func(_f: || -> bool) { panic!() }
+fn for_func<F>(_f: F) where F: FnOnce() -> bool { panic!() }
 fn produce<T>() -> T { panic!(); }
 
 fn inc(v: &mut Box<int>) {
index 6adcfad33f46c58c582f7ffe1d14538f2cefa762..ff038b545d5fec4013c51b85f3e2692956b2f276 100644 (file)
@@ -112,7 +112,9 @@ fn while_aliased_mut_cond(cond: bool, cond2: bool) {
     }
 }
 
-fn loop_break_pops_scopes<'r>(_v: &'r mut [uint], f: |&'r mut uint| -> bool) {
+fn loop_break_pops_scopes<'r, F>(_v: &'r mut [uint], mut f: F) where
+    F: FnMut(&'r mut uint) -> bool,
+{
     // Here we check that when you break out of an inner loop, the
     // borrows that go out of scope as you exit the inner loop are
     // removed from the bitset.
@@ -128,7 +130,7 @@ fn loop_break_pops_scopes<'r>(_v: &'r mut [uint], f: |&'r mut uint| -> bool) {
     }
 }
 
-fn loop_loop_pops_scopes<'r>(_v: &'r mut [uint], f: |&'r mut uint| -> bool) {
+fn loop_loop_pops_scopes<'r, F>(_v: &'r mut [uint], mut f: F) where F: FnMut(&'r mut uint) -> bool {
     // Similar to `loop_break_pops_scopes` but for the `loop` keyword
 
     while cond() {
index de8c7d9def4e1b709f2441091e18a809c0a42384..85fc7fb87b34034b9a6c4379b7a4191799713b1f 100644 (file)
@@ -18,7 +18,7 @@
 fn borrow(_v: &int) {}
 fn borrow_mut(_v: &mut int) {}
 fn cond() -> bool { panic!() }
-fn for_func(_f: || -> bool) { panic!() }
+fn for_func<F>(_f: F) where F: FnOnce() -> bool { panic!() }
 fn produce<T>() -> T { panic!(); }
 
 fn inc(v: &mut Box<int>) {
index 9bd2d48b29a8587c8b6a00108950396ca1cead28..5c282495cc239419705136bcbb19aaf62fb720f4 100644 (file)
@@ -10,7 +10,7 @@
 
 use std::thread::Thread;
 
-fn borrow(v: &int, f: |x: &int|) {
+fn borrow<F>(v: &int, f: F) where F: FnOnce(&int) {
     f(v);
 }
 
index bfa890ada9f1925fc44611c2b15dfd6080a4e7e4..b6a71fcd446abe72bb6fbdf3067a47ab2e0750e6 100644 (file)
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-fn borrow(v: &int, f: |x: &int|) {
+fn borrow<F>(v: &int, f: F) where F: FnOnce(&int) {
     f(v);
 }
 
index d678fd48f21d2584a65ee95e1f0a1709d7c9ea2a..0ada3db47a4b6ec1884fa2bae169fb9bcae24d3c 100644 (file)
@@ -13,14 +13,14 @@ struct point { x: int, y: int }
 
 trait methods {
     fn impurem(&self);
-    fn blockm(&self, f: ||);
+    fn blockm<F>(&self, f: F) where F: FnOnce();
 }
 
 impl methods for point {
     fn impurem(&self) {
     }
 
-    fn blockm(&self, f: ||) { f() }
+    fn blockm<F>(&self, f: F) where F: FnOnce() { f() }
 }
 
 fn a() {
index 200d208d140b69a054538222bf1d7d10c8fdf4a0..7849475ec67991cb519cf33dff826920764bfc84 100644 (file)
@@ -12,7 +12,7 @@
 // (locally rooted) mutable, unique vector, and that we then prevent
 // modifications to the contents.
 
-fn takes_imm_elt(_v: &int, f: ||) {
+fn takes_imm_elt<F>(_v: &int, f: F) where F: FnOnce() {
     f();
 }
 
index 9c9641bccfa144de2d76e538df8f038f3b2c2ef3..35f0751aa7895a941f1adecaf1a7d581114ec7da 100644 (file)
@@ -10,7 +10,7 @@
 
 pub fn main() {
     let bar = box 3;
-    let _g = || {
+    let _g = |&mut:| {
         let _h = move |:| -> int { *bar }; //~ ERROR cannot move out of captured outer variable
     };
 }
index c7b573562e3484747c7d272b28e7cd9f7d9ddc19..c5d23925a89b1f2d25c5470e2b43ea00a318457c 100644 (file)
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-fn with(f: |&String|) {}
+fn with<F>(f: F) where F: FnOnce(&String) {}
 
 fn arg_item(&_x: &String) {}
     //~^ ERROR cannot move out of dereference of `&`-pointer
index 82189c6b7c1f1b7fa4e1e240ec275b555b7cba66..0a47353683cfb7cfa82483a199c9767260e81183 100644 (file)
@@ -32,7 +32,7 @@ fn foo() {
 
 fn bar() {
     // Original borrow ends at end of closure
-    || {
+    |&:| {
         let mut x = 1u;
         let y = &mut x;
         let z = &mut x; //~ ERROR cannot borrow
index d72398a6ac5a71d2d80a2e0b8a12a5e44d1ebeab..1f257b8a5cba847d2b0d281a1ac0c78bea9cbbf4 100644 (file)
@@ -14,7 +14,7 @@ struct Foo {
 
 fn cond() -> bool { true }
 
-fn foo(_: ||) {}
+fn foo<F>(_: F) where F: FnOnce() {}
 
 fn main() {
     let pth = break; //~ ERROR: `break` outside of loop
index 1ff9dc9dac4c296315b271d3660ab22e344f9d14..a02d6b7f5173acc3ea6b4f4f36b03baf020f4c02 100644 (file)
@@ -8,12 +8,13 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-struct X {
-    field: ||:'static + Send,
+struct X<F> where F: FnOnce() + 'static + Send {
+    field: F,
 }
 
-fn foo(blk: ||:'static) -> X {
-    return X { field: blk }; //~ ERROR expected bounds `Send`
+fn foo<F>(blk: F) -> X<F> where F: FnOnce() + 'static {
+    //~^ ERROR the trait `core::kinds::Send` is not implemented for the type
+    return X { field: blk };
 }
 
 fn main() {
diff --git a/src/test/compile-fail/closure-bounds-not-builtin.rs b/src/test/compile-fail/closure-bounds-not-builtin.rs
deleted file mode 100644 (file)
index 6b25e4b..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright 2014 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.
-
-
-trait Foo {}
-
-fn take(f: ||:Foo) {
-    //~^ ERROR only the builtin traits can be used as closure or object bounds
-}
-
-fn main() {}
index 6769740294bc6c7892c78c9b55048c05c3ff3b20..d27529bad43052b776fc8702005e62cd1c01425d 100644 (file)
@@ -8,13 +8,12 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-fn bar(blk: ||:'static) {
+fn bar<F>(blk: F) where F: FnOnce() + 'static {
 }
 
 fn foo(x: &()) {
     bar(|| { //~ ERROR cannot infer an appropriate lifetime
         let _ = x;
-        //~^ ERROR captured variable `x` does not outlive
     })
 }
 
index 5bd9f20dd834368d7913a6c691360b25c841af78..509fffc5c9a882e2806b64b587fbf15d1c73e7e5 100644 (file)
@@ -9,19 +9,19 @@
 // except according to those terms.
 
 
-fn take_any(_: ||) {
+fn take_any<F>(_: F) where F: FnOnce() {
 }
 
-fn take_const_owned(_: ||:Sync+Send) {
+fn take_const_owned<F>(_: F) where F: FnOnce() + Sync + Send {
 }
 
-fn give_any(f: ||) {
+fn give_any<F>(f: F) where F: FnOnce() {
     take_any(f);
 }
 
-fn give_owned(f: ||:Send) {
+fn give_owned<F>(f: F) where F: FnOnce() + Send {
     take_any(f);
-    take_const_owned(f); //~ ERROR expected bounds `Send+Sync`, found bounds `Send`
+    take_const_owned(f); //~ ERROR the trait `core::kinds::Sync` is not implemented for the type
 }
 
 fn main() {}
index 1e1889c7339d26ce6e430545bdf71cd5fb7987ac..ef01c96addeb8f555f4ba26919e7f3b65b73c961 100644 (file)
@@ -17,7 +17,7 @@ fn call_bare(f: fn(&str)) {
 
 fn main() {
     let string = "world!";
-    let f: |&str| = |s| println!("{}{}", s, string);
+    let f = |&: s: &str| println!("{}{}", s, string);
     call_bare(f)    //~ ERROR mismatched types
 }
 
diff --git a/src/test/compile-fail/closure-that-fails.rs b/src/test/compile-fail/closure-that-fails.rs
deleted file mode 100644 (file)
index 7a1ebed..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2014 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.
-
-fn foo(f: || -> !) {}
-
-fn main() {
-    // Type inference didn't use to be able to handle this:
-    foo(|| panic!());
-    foo(|| -> ! panic!());
-    foo(|| 22i); //~ ERROR computation may converge in a function marked as diverging
-    foo(|| -> ! 22i); //~ ERROR computation may converge in a function marked as diverging
-    let x = || -> ! 1i; //~ ERROR computation may converge in a function marked as diverging
-}
diff --git a/src/test/compile-fail/coerce-bare-fn-to-closure-and-proc.rs b/src/test/compile-fail/coerce-bare-fn-to-closure-and-proc.rs
deleted file mode 100644 (file)
index 52f4c47..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright 2014 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.
-
-// Test that coercions from fn item types are ok, but not fn pointer
-// types to closures/procs are not allowed.
-
-fn foo() {}
-
-fn fn_item_type() {
-    let f = foo;
-
-    let f_closure: || = f;
-}
-
-fn fn_pointer_type() {
-    let f = foo as fn();
-    let f_closure: || = f;
-    //~^ ERROR: mismatched types
-}
-
-fn main() { }
index 0aa3c40fa5f88c64b1f38034a28635e5d2ceffe0..46f5f41d7282f89254c2c022629204c0aefe2f39 100644 (file)
@@ -8,10 +8,12 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+// ignore-test FIXME(#20574)
+
 #![deny(unreachable_code)]
 
 fn main() {
-    let x: || -> ! = || panic!();
+    let x = |:| panic!();
     x();
     std::io::println("Foo bar"); //~ ERROR: unreachable statement
 }
index 6b01b83db21fd31d0c097a459a52f00c9ba10411..d7586af291e8638d77de1aa3344366c5c7272220 100644 (file)
 extern fn f() {
 }
 
+fn is_fn<F>(_: F) where F: Fn() {}
+
 fn main() {
     // extern functions are extern "C" fn
     let _x: extern "C" fn() = f; // OK
-    let _x: || = f; //~ ERROR mismatched types
+    is_fn(f); //~ ERROR the trait `core::ops::Fn()` is not implemented for the type `extern "C" fn()
 }
index 2277f7080af75c464225f56ee34b52336f579f1d..039628b67528289e2780b50d4f3441ea3199d748 100644 (file)
@@ -12,7 +12,7 @@ fn takes_imm(x: &int) { }
 
 fn takes_mut(x: &mut int) { }
 
-fn apply<T>(t: T, f: |T|) {
+fn apply<T, F>(t: T, f: F) where F: FnOnce(T) {
     f(t)
 }
 
index 71328acdd7017f406af5dbeafc876af001aa186b..827e648cca86d0a32113bf2a6ca38cecbea4cd2f 100644 (file)
@@ -14,7 +14,7 @@ fn f(y: Box<int>) {
 }
 
 fn g() {
-    let _frob: |Box<int>| = |q| { *q = 2; }; //~ ERROR cannot assign
+    let _frob = |&: q: Box<int>| { *q = 2; }; //~ ERROR cannot assign
 
 }
 
index 924132c6de26bff8023a066ecc71ff66e77813df..dec4fc3b8f5b274649bb7f06a280f1cd50a64210 100644 (file)
@@ -9,7 +9,7 @@
 // except according to those terms.
 
 fn test<'x>(x: &'x int) {
-    drop::< for<'z>|&'z int| -> &'z int >(|z| {
+    drop::<Box<for<'z> FnMut(&'z int) -> &'z int>>(box |z| {
         x
         //~^ ERROR cannot infer an appropriate lifetime
     });
index 18a00d15eafe36610d5763fa63a6a28251e2fd20..f496c1e1227dbcc3b9be173558453f298a2c5e2c 100644 (file)
@@ -20,7 +20,7 @@ fn drop(&mut self) {
 
 fn main() {
     let mut ptr = box Foo { x: 0 };
-    let test = |foo: &Foo| {
+    let mut test = |&mut: foo: &Foo| {
         println!("access {}", foo.x);
         ptr = box Foo { x: ptr.x + 1 };
         println!("access {}", foo.x);
index e1acab4008a9b1a65586d8859ee05775b8a61469..89667937531536fe306c3eb881b6a1e0dc772d02 100644 (file)
@@ -10,7 +10,7 @@
 
 fn main() {
     let mut v = vec!(1i);
-    let f = || v.push(2i);
+    let mut f = |&mut:| v.push(2i);
     let _w = v; //~ ERROR: cannot move out of `v`
 
     f();
index 24256e31118e35b616ce779039e2cc2d1c2e7d3f..5033576a23482e2847b8bac03c1ccc99fb6e8300 100644 (file)
@@ -8,6 +8,8 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+// ignore-test FIXME(japari) remove test
+
 struct Foo {
     f: for <'b> |&'b int|:
       'b -> &'b int //~ ERROR use of undeclared lifetime name `'b`
index 7ec3fef5c878eb05a060356e60fa5b169b03392c..9d2212b69cee116de1d270b87f1010416b4ab45a 100644 (file)
@@ -14,7 +14,7 @@
 // wrong arity.
 
 fn _foo<F: Fn()> (f: F) {
-    |t| f(t); //~ ERROR E0057
+    |&: t| f(t); //~ ERROR E0057
 }
 
 fn main() {}
diff --git a/src/test/compile-fail/issue-17636.rs b/src/test/compile-fail/issue-17636.rs
deleted file mode 100644 (file)
index ad2ebff..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright 2014 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.
-
-trait MyItem<T> {}
-impl<T> MyItem<T> for T {}
-
-pub fn build_archive<'a, I: MyItem<&'a (|&uint|:'a)>>(files: I) {}
-
-fn main() {
-    build_archive(&(|_| { }));
-//~^ ERROR not implemented
-}
index ab396edddf49c1031dce42f0a69a9a6d1ff952f0..970b14c7eb7cc612224a3e12d1bbf226bbd78c5d 100644 (file)
@@ -12,7 +12,7 @@
 // and rejected.
 
 fn main() {
-    (|| box *[0u].as_slice())();
+    (|&:| box *[0u].as_slice())();
     //~^ ERROR cannot move out of dereference
     //~^^ ERROR cannot move a value of type [uint]
 }
index 1608d2137fc3216ee92862d8f79619c584b9aa09..f87a0d774fa7c7c9745b833654d097c658aa5d29 100644 (file)
@@ -8,12 +8,12 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-struct Obj<'a> {
-    closure: ||: 'a -> u32
+struct Obj<F> where F: FnMut() -> u32 {
+    closure: F,
 }
 
 fn main() {
     let o = Obj { closure: || 42 };
-    o.closure(); //~ ERROR type `Obj<'_>` does not implement any method in scope named `closure`
+    o.closure(); //~ ERROR does not implement any method in scope named `closure`
     //~^ NOTE use `(s.closure)(...)` if you meant to call the function stored in the `closure` field
 }
diff --git a/src/test/compile-fail/issue-18345.rs b/src/test/compile-fail/issue-18345.rs
deleted file mode 100644 (file)
index e93acb3..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2014 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.
-
-type Step<'s, R, T> = |R, T|: 's -> R;
-type Transducer<'t, R, T, U> = |Step<'t, R, U>|: 't -> Step<'t, R, T>;
-
-fn mapping<'f, R, T, U>(f: |T|: 'f -> U) -> &'f Transducer<'f, R, T, U> {
-    |step| |r, x|
-        step(r, f(x))
-        //~^ ERROR the type of this value must be known in this context
-}
-
-fn main() {}
index 8097d93ca07458a855fc3adaac8e0be440ff5520..3a0fbddf8185fa3d9fdb5345023d79b131d150f4 100644 (file)
@@ -13,8 +13,8 @@
 fn main() {
     let c = RefCell::new(vec![]);
     let mut y = 1u;
-    c.push(|| y = 0);
-    c.push(|| y = 0);
+    c.push(box || y = 0);
+    c.push(box || y = 0);
 //~^ ERROR cannot borrow `y` as mutable more than once at a time
 }
 
@@ -22,16 +22,16 @@ fn ufcs() {
     let c = RefCell::new(vec![]);
     let mut y = 1u;
 
-    Push::push(&c, || y = 0);
-    Push::push(&c, || y = 0);
+    Push::push(&c, box || y = 0);
+    Push::push(&c, box || y = 0);
 }
 
 trait Push<'c> {
-    fn push<'f: 'c>(&self, push: ||:'f -> ());
+    fn push<'f: 'c>(&self, push: Box<FnMut() + 'f>);
 }
 
-impl<'c> Push<'c> for RefCell<Vec<||:'c>> {
-    fn push<'f: 'c>(&self, fun: ||:'f -> ()) {
+impl<'c> Push<'c> for RefCell<Vec<Box<FnMut() + 'c>>> {
+    fn push<'f: 'c>(&self, fun: Box<FnMut() + 'f>) {
         self.borrow_mut().push(fun)
     }
 }
diff --git a/src/test/compile-fail/issue-19009.rs b/src/test/compile-fail/issue-19009.rs
deleted file mode 100644 (file)
index aa7c4c3..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright 2014 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(lang_items)]
-#![no_std]
-#![crate_type="rlib"]
-#[lang="sized"] pub trait Sized for Sized? {}
-
-fn ice(f: for <'s> ||
-    :'s //~ ERROR use of undeclared lifetime name `'s`
-) {}
-fn main() { ice(||{}) }
diff --git a/src/test/compile-fail/issue-19141.rs b/src/test/compile-fail/issue-19141.rs
deleted file mode 100644 (file)
index 545e3f8..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright 2014 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.
-
-fn main() {
-    let n = 0u;
-
-    let f = move || n += 1;  //~error boxed closures can't capture by value
-}
diff --git a/src/test/compile-fail/issue-20193.rs b/src/test/compile-fail/issue-20193.rs
deleted file mode 100644 (file)
index e5d8d33..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright 2014 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.
-
-fn foo(t: &mut int){
-    println!("{}", t);
-}
-
-fn main() {
-    let test = 10;
-
-    let h = move || {  //~error boxed closures can't capture by value
-        let mut r = &mut test.clone();
-        foo(r);
-    };
-
-    h();
-}
diff --git a/src/test/compile-fail/issue-20228-1.rs b/src/test/compile-fail/issue-20228-1.rs
deleted file mode 100644 (file)
index 3ff4557..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2014 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.
-
-struct S;
-
-impl S {
-    fn foo(&self) {
-        let _ = move || { self };  //~error boxed closures can't capture by value
-    }
-}
-
-fn main() {
-}
diff --git a/src/test/compile-fail/issue-20228-2.rs b/src/test/compile-fail/issue-20228-2.rs
deleted file mode 100644 (file)
index 5fec426..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2014 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.
-
-struct S;
-
-impl S {
-    fn foo(&self) {
-        let _ = move || { self.foo() };  //~error boxed closures can't capture by value
-    }
-}
-
-fn main() {
-}
index b688cafb67459aab05c1701e8eb6968083c9c430..691660f897157f309dfcb52a2e3420b4db1dd729 100644 (file)
@@ -9,17 +9,17 @@
 // except according to those terms.
 
 trait vec_monad<A> {
-    fn bind<B>(&self, f: |A| -> Vec<B> );
+    fn bind<B, F>(&self, f: F) where F: FnMut(A) -> Vec<B>;
 }
 
 impl<A> vec_monad<A> for Vec<A> {
-    fn bind<B>(&self, f: |A| -> Vec<B> ) {
+    fn bind<B, F>(&self, mut f: F) where F: FnMut(A) -> Vec<B> {
         let mut r = panic!();
         for elt in self.iter() { r = r + f(*elt); }
         //~^ ERROR the type of this value must be known
    }
 }
 fn main() {
-    ["hi"].bind(|x| [x] );
+    ["hi"].bind(|&mut: x| [x] );
     //~^ ERROR type `[&str; 1]` does not implement any method in scope named `bind`
 }
index 0f7cc2cb72b8e2b05b73dcb6456119e3ade48d33..c67d6b1ce8f7ce17e063dcc42ab31835527ca254 100644 (file)
@@ -11,7 +11,7 @@
 
 fn main() {
     let needlesArr: Vec<char> = vec!('a', 'f');
-    needlesArr.iter().fold(|x, y| {
+    needlesArr.iter().fold(|&: x, y| {
     });
     //~^^ ERROR this function takes 2 parameters but 1 parameter was supplied
     //
index 38f28bd79dfa1905d9ed09d82583c03d4b5f1ee4..86ab9be77fc6808389e948f913e33d1ac10ff23e 100644 (file)
@@ -9,8 +9,9 @@
 // except according to those terms.
 
 trait A {
-  fn a(&self) {
-      || self.b() //~ ERROR type `&Self` does not implement any method in scope named `b`
-  }
+    fn a(&self) {
+        |&:| self.b() //~ ERROR type `&Self` does not implement any method in scope named `b`
+        //~^ ERROR expected (), found closure
+    }
 }
 fn main() {}
index eadd16348b2e8573b81138986176cd7d9aca6f4e..d4f9ea5b276f9fc4ed4165528e021999db1e37c5 100644 (file)
@@ -8,13 +8,15 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+#![feature(unboxed_closures)]
+
 fn id<T>(t: T) -> T { t }
 
-fn f<'r, T>(v: &'r T) -> ||: 'r -> T {
-    id(|| *v) //~ ERROR cannot infer
+fn f<'r, T>(v: &'r T) -> Box<FnMut() -> T + 'r> {
+    id(box |&mut:| *v) //~ ERROR cannot infer
 }
 
 fn main() {
     let v = &5i;
-    println!("{}", f(v)());
+    println!("{}", f(v).call_mut(()));
 }
diff --git a/src/test/compile-fail/issue-4523.rs b/src/test/compile-fail/issue-4523.rs
deleted file mode 100644 (file)
index 5063a78..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright 2013 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.
-
-fn foopy() {}
-
-static f: ||: 'static = foopy;
-
-fn main () {
-    f(); //~ ERROR closure invocation in a static location
-}
index 18af9736ed9f8408224d80d0c78095a9d1e0a189..fef414ce978a8756e263cc821d6035950611033d 100644 (file)
@@ -9,12 +9,12 @@
 // except according to those terms.
 
 fn f() { }
-struct S(||); //~ ERROR explicit lifetime bound required
+struct S(Box<FnMut()>); //~ ERROR explicit lifetime bound required
 pub static C: S = S(f);
 
 
 fn g() { }
-type T = ||;  //~ ERROR explicit lifetime bound required
+type T = Box<FnMut()>;  //~ ERROR explicit lifetime bound required
 pub static D: T = g;
 
 fn main() {}
index 88b08655caad2547d3fc066932c15cf1e1062859..1691688fd84645f65d31446cae23cdd48d3e2f44 100644 (file)
@@ -11,6 +11,6 @@
 // Regression test for issue #5239
 
 fn main() {
-    let x: |int| -> int = |ref x| { x += 1; };
+    let x = |&: ref x: int| -> int { x += 1; };
     //~^ ERROR binary assignment operation `+=` cannot be applied to type `&int`
 }
index 5925f6869391a1d4f6280a08567d8bac6e3a714c..433ae3bf89e03a540c9965ef21f327556d044c52 100644 (file)
@@ -17,13 +17,13 @@ fn twice(x: Box<uint>) -> uint {
      *x * 2
 }
 
-fn invoke(f: || -> uint) {
+fn invoke<F>(f: F) where F: FnOnce() -> uint {
      f();
 }
 
 fn main() {
       let x  : Box<uint>  = box 9;
-      let sq : || -> uint =  || { *x * *x };
+      let sq =  |:| { *x * *x };
 
       twice(x); //~ ERROR: cannot move out of
       invoke(sq);
index 0e978a09edd2d8669ae60c7dd7f147e6978065ae..897afb1c10245a256ddeb449afe47292b8b44b6b 100644 (file)
@@ -25,7 +25,7 @@ fn new(s: &str) -> CrateId {
 
 pub fn remove_package_from_database() {
     let mut lines_to_use: Vec<&CrateId> = Vec::new();
-    let push_id = |installed_id: &CrateId| {
+    let push_id = |&mut: installed_id: &CrateId| {
         lines_to_use.push(installed_id);
         //~^ ERROR cannot infer an appropriate lifetime for automatic coercion due to
         // conflicting requirements
@@ -38,7 +38,7 @@ pub fn remove_package_from_database() {
 
 }
 
-pub fn list_database(f: |&CrateId|) {
+pub fn list_database<F>(mut f: F) where F: FnMut(&CrateId) {
     let stuff = ["foo", "bar"];
 
     for l in stuff.iter() {
index 8868c7f8256da5b646386e049ae389a028c9de66..b5725249812f6ccd2edfb018b5d3fddbe9d62ded 100644 (file)
@@ -57,9 +57,6 @@ fn test<'a,T,U:Copy>(_: &'a int) {
     // mutable object types are not ok
     assert_copy::<&'a mut (Dummy+Copy)>();  //~ ERROR `core::kinds::Copy` is not implemented
 
-    // closures are like an `&mut` object
-    assert_copy::<||>(); //~ ERROR `core::kinds::Copy` is not implemented
-
     // unsafe ptrs are ok
     assert_copy::<*const int>();
     assert_copy::<*const &'a mut int>();
index 3b67e98f42ca81d55e51967c243fa74a41952ef5..c300096caf1e09c87bcb4f8e6c99d8e9cecbe837 100644 (file)
@@ -27,14 +27,9 @@ fn box_object_with_no_bound_not_ok<'a>() {
     assert_send::<Box<Dummy>>(); //~ ERROR the trait `core::kinds::Send` is not implemented
 }
 
-fn closure_with_no_bound_not_ok<'a>() {
-    assert_send::<||:'static>(); //~ ERROR the trait `core::kinds::Send` is not implemented
-}
-
 fn object_with_send_bound_ok() {
     assert_send::<&'static (Dummy+Send)>();
     assert_send::<Box<Dummy+Send>>();
-    assert_send::<||:Send>;
 }
 
 fn main() { }
index 29b4686198be1fc8a91a539d3282ba4e5b3cef9d..7513e1bc21a4a7e1a953beb1dcbde9af804cb43d 100644 (file)
@@ -35,7 +35,7 @@ fn main() {
       _ => {}
     }
 
-    let x = |mut y: int| 10i; //~ ERROR: variable does not need to be mutable
+    let x = |&: mut y: int| 10i; //~ ERROR: variable does not need to be mutable
     fn what(mut foo: int) {} //~ ERROR: variable does not need to be mutable
 
     // positive cases
@@ -65,7 +65,7 @@ fn what(mut foo: int) {} //~ ERROR: variable does not need to be mutable
       _ => {}
     }
 
-    let x = |mut y: int| y = 32i;
+    let x = |&mut: mut y: int| y = 32i;
     fn nothing(mut foo: int) { foo = 37i; }
 
     // leading underscore should avoid the warning, just like the
@@ -73,7 +73,7 @@ fn what(mut foo: int) {} //~ ERROR: variable does not need to be mutable
     let mut _allowed = 1i;
 }
 
-fn callback(f: ||) {}
+fn callback<F>(f: F) where F: FnOnce() {}
 
 // make sure the lint attribute can be turned off
 #[allow(unused_mut)]
index df3feefa881f3f28231da76f42a16c03d62c80c4..5c8e73e674751d109db04ffec9e4d657e0abae90 100644 (file)
@@ -20,7 +20,7 @@ mod foo {
     }
 }
 
-fn callback<T>(_f: || -> T) -> T { panic!() }
+fn callback<T, F>(_f: F) -> T where F: FnOnce() -> T { panic!() }
 unsafe fn unsf() {}
 
 fn bad1() { unsafe {} }                  //~ ERROR: unnecessary `unsafe` block
index 6466310eb4d2e133b681961478cc29941c38cd6e..82de02f09813ce9a7ca0acd663f32048cd1007a9 100644 (file)
@@ -8,5 +8,5 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-fn force(f: || -> int) -> int { f() }
+fn force<F>(f: F) -> int where F: FnOnce() -> int { f() }
 fn main() { println!("{}", force(|| {})); } //~ ERROR mismatched types
index ee57377943d12b28a962c6316dee3b81cdcc7f24..14af49dfc49c5d379c9907fb9b49e66041d659a9 100644 (file)
@@ -20,7 +20,7 @@ enum E {
     Baz
 }
 
-fn f(s: &S, g: |&S|) {
+fn f<G>(s: &S, g: G) where G: FnOnce(&S) {
     g(s)
 }
 
index f9614574abda970b749a44f43b6781085caa7e74..ab762332ee43da3ba48d32eeca32b4ca3cfd4b25 100644 (file)
@@ -14,5 +14,5 @@ fn test(_x: Box<uint>) {}
 
 fn main() {
     let i = box 3;
-    let _f = || test(i); //~ ERROR cannot move out
+    let _f = |&:| test(i); //~ ERROR cannot move out
 }
index 2a73b769895eeeb75be648157400f0bc3d73d75d..787e25ea319544606154d49020210379426a1f91 100644 (file)
 // bound must be noncopyable. For details see
 // http://smallcultfollowing.com/babysteps/blog/2013/04/30/the-case-of-the-recurring-closure/
 
+#![feature(unboxed_closures)]
+
 struct R<'a> {
     // This struct is needed to create the
     // otherwise infinite type of a fn that
     // accepts itself as argument:
-    c: |&mut R, bool|: 'a
+    c: Box<FnMut(&mut R, bool) + 'a>
 }
 
 fn innocent_looking_victim() {
@@ -27,8 +29,8 @@ fn innocent_looking_victim() {
         } else {
             match x {
                 Some(ref msg) => {
-                    (f.c)(f, true);
-                    //~^ ERROR: cannot borrow `*f` as mutable because
+                    f.c.call_mut((f, true));
+                    //~^ ERROR: cannot borrow `*f` as mutable more than once at a time
                     println!("{}", msg);
                 },
                 None => panic!("oops"),
@@ -37,8 +39,8 @@ fn innocent_looking_victim() {
     })
 }
 
-fn conspirator(f: |&mut R, bool|) {
-    let mut r = R {c: f};
+fn conspirator<F>(mut f: F) where F: FnMut(&mut R, bool) {
+    let mut r = R {c: box f};
     f(&mut r, false) //~ ERROR use of moved value
 }
 
index 4de56e32f560a98ba7dbb34e459bede38f950d01..ebda4e9103d604669547d28dd73e1d4e2a2aef8f 100644 (file)
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-fn let_in<T>(x: T, f: |T|) {}
+fn let_in<T, F>(x: T, f: F) where F: FnOnce(T) {}
 
 fn main() {
     let_in(3u, |i| { assert!(i == 3i); });
index 954d4b23e30faa942734b7a752d885591b0116d4..575e9864a92d3bd633febe9e08cdfb73c86acf9f 100644 (file)
@@ -9,7 +9,7 @@
 // except according to those terms.
 
 fn main() {
-    let f = |3: int| println!("hello");
+    let f = |&: 3: int| println!("hello");
     //~^ ERROR refutable pattern in function argument: `_` not covered
     f(4);
 }
index 13ab7acaf48353b99391e48826941e33afe59d4d..9e8281faf2f567c4f4bf4561182420c0771a1885 100644 (file)
@@ -8,8 +8,8 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-fn call_rec(f: |uint| -> uint) -> uint {
-    (|x| f(x))(call_rec(f)) //~ ERROR cannot move out of `f`
+fn call_rec<F>(mut f: F) -> uint where F: FnMut(uint) -> uint {
+    (|&mut: x| f(x))(call_rec(f)) //~ ERROR cannot move out of `f`
 }
 
 fn main() {}
diff --git a/src/test/compile-fail/regionck-closure-lifetimes.rs b/src/test/compile-fail/regionck-closure-lifetimes.rs
deleted file mode 100644 (file)
index bb895a3..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-// Copyright 2013 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.
-
-fn env<'a>(blk: |p: ||: 'a|) {
-    // Test that the closure here cannot be assigned
-    // the lifetime `'a`, which outlives the current
-    // block.
-
-    let mut state = 0i;
-    let statep = &mut state;
-    blk(|| *statep = 1i); //~ ERROR captured variable `statep` does not outlive
-}
-
-fn no_env_no_for<'a>(blk: |p: |||: 'a) {
-    // Test that a closure with no free variables CAN
-    // outlive the block in which it is created.
-
-    blk(|| ())
-}
-
-fn repeating_loop() {
-    // Test that the closure cannot be created within `loop` loop and
-    // called without, even though the state that it closes over is
-    // external to the loop.
-
-    let closure;
-    let state = 0i;
-
-    loop {
-        closure = || state; //~ ERROR cannot infer
-        break;
-    }
-
-    closure();
-}
-
-fn repeating_while() {
-    // Test that the closure cannot be created within `while` loop and
-    // called without, even though the state that it closes over is
-    // external to the loop.
-
-    let closure;
-    let state = 0i;
-
-    while true {
-        closure = || state; //~ ERROR cannot infer
-        break;
-    }
-
-    closure();
-}
-
-fn main() {}
index 7a146c043c8389cfb776c42dc104be176c666f5e..fb60d8f7b27a4acb442fe0fcc7b3fafc3b5911d3 100644 (file)
@@ -16,7 +16,7 @@ struct dog {
 
 impl dog {
     pub fn chase_cat(&mut self) {
-        let _f = || {
+        let _f = |&:| {
             let p: &'static mut uint = &mut self.food; //~ ERROR cannot infer
             *p = 3u;
         };
index e15cb25295aac7defa8ec6fa8766911fedf96830..0628bbb8bb08eb70a85813bb450bd8c8ee155da3 100644 (file)
@@ -69,11 +69,6 @@ fn object_with_send_bound_not_ok<'a>() {
     //~^ ERROR declared lifetime bound not satisfied
 }
 
-fn closure_with_lifetime_not_ok<'a>() {
-    assert_send::<||:'a>();
-    //~^ ERROR not implemented
-}
-
 // unsafe pointers are ok unless they point at unsendable things
 
 struct UniqueUnsafePtr(Unique<*const int>);
index b15f0405d23c69bb5651e2003765a495b0aef151..1774c9fada946fc6a3806735a0052ace3f3d6a48 100644 (file)
@@ -27,14 +27,14 @@ fn compute(x: &ast) -> uint {
     }
 }
 
-fn map_nums<'a,'b>(x: &ast, f: |uint| -> uint) -> &'a ast<'b> {
+fn map_nums<'a,'b, F>(x: &ast, f: &mut F) -> &'a ast<'b> where F: FnMut(uint) -> uint {
     match *x {
       ast::num(x) => {
-        return &ast::num(f(x)); //~ ERROR borrowed value does not live long enough
+        return &ast::num((*f)(x)); //~ ERROR borrowed value does not live long enough
       }
       ast::add(x, y) => {
-        let m_x = map_nums(x, |z| f(z));
-        let m_y = map_nums(y, |z| f(z));
+        let m_x = map_nums(x, f);
+        let m_y = map_nums(y, f);
         return &ast::add(m_x, m_y);  //~ ERROR borrowed value does not live long enough
       }
     }
index 66103eb95888ac941e1cf123c8641d2b0978c584..547accbf0860d27ce85d7b65aedc27f0c709123d 100644 (file)
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-fn with_int(f: |x: &int|) {
+fn with_int<F>(f: F) where F: FnOnce(&int) {
     let x = 3;
     f(&x);
 }
index fee84cf9656d1ceaae73f4fb5d02a75c55a63579..6d67bd80650fad0afa66f5e2a9e46087345eaa59 100644 (file)
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-fn with_int(f: |x: &int|) {
+fn with_int<F>(f: F) where F: FnOnce(&int) {
     let x = 3;
     f(&x);
 }
index f92c264784ae6a402dc6d8d60e69e29d63b4abdd..e3771cfebba255cf7f656f3e4153486b0c6c6829 100644 (file)
@@ -16,7 +16,7 @@
 struct S;
 
 impl S {
-    fn f<B>(&self, _: |&i32| -> B) {
+    fn f<B, F>(&self, _: F) where F: FnOnce(&i32) -> B {
     }
 }
 
index adc960b069d05d89f798d1a7e7673c5445e1189a..873d4cea0395e627f2dcbfcecdef8b4c59e19c81 100644 (file)
@@ -20,7 +20,7 @@ fn get(self) -> int {
     }
 }
 
-fn with<R:Deref>(f: |x: &int| -> R) -> int {
+fn with<R:Deref, F>(f: F) -> int where F: FnOnce(&int) -> R {
     f(&3).get()
 }
 
diff --git a/src/test/compile-fail/regions-fn-subtyping.rs b/src/test/compile-fail/regions-fn-subtyping.rs
deleted file mode 100644 (file)
index 91a6ff7..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-// 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.
-
-fn of<'a,T>() -> |T|:'a { panic!(); }
-fn subtype<T>(x: |T|) { panic!(); }
-
-fn test_fn<'x,'y,'z,T>(_x: &'x T, _y: &'y T, _z: &'z T) {
-    // Here, x, y, and z are free.  Other letters
-    // are bound.  Note that the arrangement
-    // subtype::<T1>(of::<T2>()) will typecheck
-    // iff T1 <: T2.
-
-    subtype::< for<'a>|&'a T|>(
-        of::< for<'a>|&'a T|>());
-
-    subtype::< for<'a>|&'a T|>(
-        of::< for<'b>|&'b T|>());
-
-    subtype::< for<'b>|&'b T|>(
-        of::<|&'x T|>());
-
-    subtype::<|&'x T|>(
-        of::< for<'b>|&'b T|>());  //~ ERROR mismatched types
-
-    subtype::< for<'a,'b>|&'a T, &'b T|>(
-        of::< for<'a>|&'a T, &'a T|>());
-
-    subtype::< for<'a>|&'a T, &'a T|>(
-        of::< for<'a,'b>|&'a T, &'b T|>()); //~ ERROR mismatched types
-
-    subtype::< for<'a,'b>|&'a T, &'b T|>(
-        of::<|&'x T, &'y T|>());
-
-    subtype::<|&'x T, &'y T|>(
-        of::< for<'a,'b>|&'a T, &'b T|>()); //~ ERROR mismatched types
-}
-
-fn main() {}
diff --git a/src/test/compile-fail/regions-fns.rs b/src/test/compile-fail/regions-fns.rs
deleted file mode 100644 (file)
index 854584e..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-// 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.
-
-// Before fn subtyping was properly implemented,
-// we reported errors in this case:
-
-fn not_ok<'b>(a: &uint, b: &'b uint) {
-    let mut g: |x: &uint| = |x: &'b uint| {};
-    //~^ ERROR mismatched types
-    g(a);
-}
-
-fn main() {
-}
index 435d10a0a29a1c07db7a43a40d2ca3bfee547143..6e59a29b8cf2236f8e57110c0f4d00171b5eb47a 100644 (file)
@@ -30,7 +30,7 @@ fn ordering3<'a, 'b>(x: &'a uint, y: &'b uint) -> &'a &'b uint {
     panic!();
 }
 
-fn ordering4<'a, 'b>(a: &'a uint, b: &'b uint, x: |&'a &'b uint|) {
+fn ordering4<'a, 'b, F>(a: &'a uint, b: &'b uint, x: F) where F: FnOnce(&'a &'b uint) {
     // Do not infer ordering from closure argument types.
     let z: Option<&'a &'b uint> = None;
     //~^ ERROR reference has a longer lifetime than the data it references
diff --git a/src/test/compile-fail/regions-freevar.rs b/src/test/compile-fail/regions-freevar.rs
deleted file mode 100644 (file)
index 76bbe71..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-// 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.
-
-fn wants_static_fn(_x: ||: 'static) {}
-
-fn main() {
-    let i = 3i;
-    wants_static_fn(|| {
-        println!("i={}", i); //~ ERROR captured variable `i` does not outlive
-    })
-}
index 8af341e3ace42b9d949319d92199f98008180d8b..0c250e38258cec518bddb3a48a81e14c965be69b 100644 (file)
@@ -9,15 +9,15 @@
 // except according to those terms.
 
 struct parameterized1<'a> {
-    g: ||: 'a
+    g: Box<FnMut() + 'a>
 }
 
 struct not_parameterized1 {
-    g: ||: 'static
+    g: Box<FnMut() + 'static>
 }
 
 struct not_parameterized2 {
-    g: ||: 'static
+    g: Box<FnMut() + 'static>
 }
 
 fn take1<'a>(p: parameterized1) -> parameterized1<'a> { p }
index cf1fa2cfc4c2cbd8986f850bf48f8d06becf6086..c8edd936bf28b232a16e7fa50e33aded71fef4ef 100644 (file)
 
 fn borrow<T>(x: &T) -> &T {x}
 
-fn foo(cond: || -> bool, make_box: || -> Box<int>) {
+fn foo<C, M>(mut cond: C, mut make_box: M) where
+    C: FnMut() -> bool,
+    M: FnMut() -> Box<int>,
+{
     let mut y: &int;
     loop {
         let x = make_box();
index 66f958c789336a1b778d7028d062e942379bb91d..ac41f2a5b3e47be208a6c53d257990538ab6dc51 100644 (file)
@@ -10,7 +10,7 @@
 
 fn select<'r>(x: &'r int, y: &'r int) -> &'r int { x }
 
-fn with<T>(f: |x: &int| -> T) -> T {
+fn with<T, F>(f: F) -> T where F: FnOnce(&int) -> T {
     f(&20)
 }
 
index 33573cae0f66d5a2aa78d6c2d0b0348433de651d..190e444fe7e830bc92879e0e8792547767f753bb 100644 (file)
@@ -10,7 +10,7 @@
 
 
 struct invariant<'a> {
-    f: |x: &mut &'a int|: 'static
+    f: Box<FnOnce(&mut &'a int) + 'static>,
 }
 
 fn to_same_lifetime<'r>(bi: invariant<'r>) {
index 66dcb5fdebd2d0fa3d4bee961aadf0b807854160..71d0c988c5e274e0849c8c6b8b24c4169d0f14d6 100644 (file)
@@ -10,7 +10,7 @@
 
 
 struct invariant<'a> {
-    f: ||: 'static -> &mut &'a int
+    f: Box<for<'b> FnOnce() -> &'b mut &'a int + 'static>,
 }
 
 fn to_same_lifetime<'r>(bi: invariant<'r>) {
index b84f13ec37feb44d16654af4e6bf795c965046f3..323ebc3c20b37c3aad95cc84735b4de70bdc0483 100644 (file)
@@ -14,12 +14,12 @@ struct direct<'a> {
 
 struct indirect1 {
     // Here the lifetime parameter of direct is bound by the fn()
-    g: |direct|: 'static
+    g: Box<FnOnce(direct) + 'static>
 }
 
 struct indirect2<'a> {
     // But here it is set to 'a
-    g: |direct<'a>|: 'static
+    g: Box<FnOnce(direct<'a>) + 'static>
 }
 
 fn take_direct<'a,'b>(p: direct<'a>) -> direct<'b> { p } //~ ERROR mismatched types
index ffd1501075e94c594b3e3f7c9932f742654196c1..b9c721159f2b44c125117afe7e7523f6b047a821 100644 (file)
@@ -43,19 +43,16 @@ fn f(a: &'a int) { } //~ ERROR undeclared lifetime
 
     // &'a CAN be declared on functions and used then:
     fn g<'a>(a: &'a int) { } // OK
-    fn h(a: for<'a>|&'a int|) { } // OK
-
-    // But not in the bound of a closure, it's not in scope *there*
-    fn i(a: for<'a>|&int|:'a) { } //~ ERROR undeclared lifetime
+    fn h(a: Box<for<'a> FnOnce(&'a int)>) { } // OK
 }
 
 // Test nesting of lifetimes in fn type declarations
 fn fn_types(a: &'a int, //~ ERROR undeclared lifetime
-            b: for<'a>|a: &'a int,
-                       b: &'b int, //~ ERROR undeclared lifetime
-                       c: for<'b>|a: &'a int,
-                                  b: &'b int|,
-                       d: &'b int|, //~ ERROR undeclared lifetime
+            b: Box<for<'a> FnOnce(&'a int,
+                                  &'b int, //~ ERROR undeclared lifetime
+                                  Box<for<'b> FnOnce(&'a int,
+                                                     &'b int)>,
+                                  &'b int)>, //~ ERROR undeclared lifetime
             c: &'a int) //~ ERROR undeclared lifetime
 {
 }
index a08cf2263894dfc5396a63164f119f48588b16a8..b7fe893a1f5bbca1a2857c8b9212e0238b02bdcc 100644 (file)
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-fn ignore(_f: for<'z>|&'z int| -> &'z int) {}
+fn ignore<F>(_f: F) where F: for<'z> FnOnce(&'z int) -> &'z int {}
 
 fn nested() {
     let y = 3;
index f4654367970d11d052b16a23f73f54b8933e3113..5d8ef718ef0d354b7bfe93720256f002b8f55c2a 100644 (file)
@@ -14,13 +14,13 @@ fn nested<'x>(x: &'x int) {
     let y = 3;
     let mut ay = &y;
 
-    ignore::< for<'z>|&'z int|>(|z| {
+    ignore::<Box<for<'z> FnMut(&'z int)>>(box |z| {
         ay = x; //~ ERROR cannot infer
         ay = &y;
         ay = z;
     });
 
-    ignore::< for<'z>|&'z int| -> &'z int>(|z| {
+    ignore::< Box<for<'z> FnMut(&'z int) -> &'z int>>(box |z| {
         if false { return x; }  //~ ERROR cannot infer an appropriate lifetime for automatic
         if false { return ay; }
         return z;
index 47fca8bb8df2374e83395d5a46599afbf96441cd..f9eecb60c6af118a72680ad92e3ef5fb1f7bc9b6 100644 (file)
@@ -13,7 +13,7 @@ fn arg_item(box ref x: Box<int>) -> &'static int {
     x //~^ ERROR borrowed value does not live long enough
 }
 
-fn with<R>(f: |Box<int>| -> R) -> R { f(box 3) }
+fn with<R, F>(f: F) -> R where F: FnOnce(Box<int>) -> R { f(box 3) }
 
 fn arg_closure() -> &'static int {
     with(|box ref x| x) //~ ERROR borrowed value does not live long enough
index 997775efa84b52d60756dfc3ed3c62652f37dbbb..bd14d31217e88269ee580d55bdb45ed2fa255b03 100644 (file)
@@ -12,7 +12,7 @@
 // some point regions-ret-borrowed reported an error but this file did
 // not, due to special hardcoding around the anonymous region.
 
-fn with<R>(f: for<'a>|x: &'a int| -> R) -> R {
+fn with<R, F>(f: F) -> R where F: for<'a> FnOnce(&'a int) -> R {
     f(&3)
 }
 
index 465f4410fbbccb2d05451c0db6240e5433815a9f..4dfd4f1709a6f2894da09c0d2a7deac419595b32 100644 (file)
@@ -15,7 +15,7 @@
 // used to successfully compile because we failed to account for the
 // fact that fn(x: &int) rebound the region &.
 
-fn with<R>(f: |x: &int| -> R) -> R {
+fn with<R, F>(f: F) -> R where F: FnOnce(&int) -> R {
     f(&3)
 }
 
index aedaced5794a784a9449be54262e31beab676478..d7b2a45cc63bb6f10457472e5ba11db80dbc0604 100644 (file)
@@ -20,11 +20,4 @@ fn main() {
         let x = f();
         let y = f();
     }
-    // Boxed closure case
-    {
-        let mut x = 0u;
-        let f = || &mut x; //~ ERROR cannot infer
-        let x = f();
-        let y = f();
-    }
 }
index 7ffc6a75cff8ca9ac9d5a8b48a3d5fecf355f45b..991040bc62fea1ef8f4151002c6187db889e9283 100644 (file)
@@ -8,18 +8,20 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+#![feature(unboxed_closures)]
+
 struct closure_box<'a> {
-    cl: ||: 'a
+    cl: Box<FnMut() + 'a>,
 }
 
-fn box_it<'r>(x: ||: 'r) -> closure_box<'r> {
+fn box_it<'r>(x: Box<FnMut() + 'r>) -> closure_box<'r> {
     closure_box {cl: x}
 }
 
 fn main() {
     let cl_box = {
-        let mut i = 3;
-        box_it(|| i += 1) //~ ERROR cannot infer
+        let mut i = 3i;
+        box_it(box || i += 1) //~ ERROR cannot infer
     };
-    (cl_box.cl)();
+    cl_box.cl.call_mut(());
 }
index ac2f9d0379f64d1a63bd3c468ceb032e53bca8c6..3249794e5c822a879e0b83e6f5356cb1b93510bc 100644 (file)
@@ -10,6 +10,6 @@
 
 // error-pattern:can't use type parameters from outer function; try using
 fn foo<T>(x: T) {
-    fn bar(f: |T| -> T) { }
+    fn bar(f: Box<FnMut(T) -> T>) { }
 }
 fn main() { foo(1); }