diff --git a/src/test/compile-fail/access-mode-in-closures.rs b/src/test/compile-fail/access-mode-in-closures.rs index e1696f0e63ed7607a52fca0aa55f590009b1ba14..f15157d126ed76ee64c85f474f66a9c42efcdeb6 100644 --- a/src/test/compile-fail/access-mode-in-closures.rs +++ b/src/test/compile-fail/access-mode-in-closures.rs @@ -11,7 +11,7 @@ struct sty(Vec ); -fn unpack(_unpack: |v: &sty| -> Vec ) {} +fn unpack(_unpack: F) where F: FnOnce(&sty) -> Vec {} fn main() { let _foo = unpack(|s| { diff --git a/src/test/compile-fail/assign-to-method.rs b/src/test/compile-fail/assign-to-method.rs index 453d7ffdad5c3249945623fb8b4c651b2722fb3c..f14668192f8503cfd0d4485b900ef5d2b1247303 100644 --- a/src/test/compile-fail/assign-to-method.rs +++ b/src/test/compile-fail/assign-to-method.rs @@ -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 index e268b0e93fdad4e9aac45a114c0adeb738d51b28..0000000000000000000000000000000000000000 --- a/src/test/compile-fail/block-coerce-no-2.rs +++ /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 or the MIT license -// , 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 index 76af956a26fff7a9a908163d5c578fa49b8fc908..0000000000000000000000000000000000000000 --- a/src/test/compile-fail/block-coerce-no.rs +++ /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 or the MIT license -// , 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(); -} diff --git a/src/test/compile-fail/borrowck-assign-comp-idx.rs b/src/test/compile-fail/borrowck-assign-comp-idx.rs index e14911d3508da46ddd106a4cb141152f1efe27e1..a6801a6a51a52d10ae228bed6b16caa563570240 100644 --- a/src/test/compile-fail/borrowck-assign-comp-idx.rs +++ b/src/test/compile-fail/borrowck-assign-comp-idx.rs @@ -24,7 +24,7 @@ fn a() { println!("{}", *q); } -fn borrow(_x: &[int], _f: ||) {} +fn borrow(_x: &[int], _f: F) where F: FnOnce() {} fn b() { // here we alias the mutable vector into an imm slice and try to diff --git a/src/test/compile-fail/borrowck-autoref-3261.rs b/src/test/compile-fail/borrowck-autoref-3261.rs index 1b4e5891f941de493f284cf808da66326a7b88ea..2804b8c48a703f4f4be64c71d3ac5effd36452af 100644 --- a/src/test/compile-fail/borrowck-autoref-3261.rs +++ b/src/test/compile-fail/borrowck-autoref-3261.rs @@ -13,7 +13,7 @@ enum Either { 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(&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!() diff --git a/src/test/compile-fail/borrowck-block-unint.rs b/src/test/compile-fail/borrowck-block-unint.rs index a37717ed5d99897d99e26165b6a65b55e5f3eee0..e519e57d178c85b10dc9fd68ec308aecdcc660e7 100644 --- a/src/test/compile-fail/borrowck-block-unint.rs +++ b/src/test/compile-fail/borrowck-block-unint.rs @@ -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) where F: FnOnce() { f(); } fn main() { let x: int; force(|| { //~ ERROR capture of possibly uninitialized variable: `x` diff --git a/src/test/compile-fail/borrowck-call-is-borrow-issue-12224.rs b/src/test/compile-fail/borrowck-call-is-borrow-issue-12224.rs index 002ae5a7d28b418ab394d40247ff8aa100f4bf42..6dbdff9441d55a8b0283bedfc3598c5b88e206a4 100644 --- a/src/test/compile-fail/borrowck-call-is-borrow-issue-12224.rs +++ b/src/test/compile-fail/borrowck-call-is-borrow-issue-12224.rs @@ -10,53 +10,54 @@ // Ensure that invoking a closure counts as a unique immutable borrow +#![feature(unboxed_closures)] -type Fn<'a> = ||:'a; +type Fn<'a> = Box; struct Test<'a> { - f: ||: 'a + f: Box } -fn call(f: |Fn|) { - f(|| { - //~^ ERROR: closure requires unique access to `f` but it is already borrowed - f(|| {}) +fn call(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) where F: FnMut() { + (*f)(); //~ ERROR: cannot borrow immutable dereference of `&`-pointer `*f` as mutable } -fn test3(f: &mut ||) { +fn test3(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) where F: FnMut(Box, int) {} + let mut f = |&mut: g: Box, 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); } diff --git a/src/test/compile-fail/borrowck-closures-mut-and-imm.rs b/src/test/compile-fail/borrowck-closures-mut-and-imm.rs index 886026e45d90f1f8c89734a3b04a0f77e2b1b572..47a47d0443255aab3e06d4d13f3970637a47593b 100644 --- a/src/test/compile-fail/borrowck-closures-mut-and-imm.rs +++ b/src/test/compile-fail/borrowck-closures-mut-and-imm.rs @@ -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() { diff --git a/src/test/compile-fail/borrowck-closures-mut-of-imm.rs b/src/test/compile-fail/borrowck-closures-mut-of-imm.rs index 8163df5e967cd52f8ec9ea9225f3c05bfb4a5952..30e1421ba2660fb873bba3bc85488f9ab9abe519 100644 --- a/src/test/compile-fail/borrowck-closures-mut-of-imm.rs +++ b/src/test/compile-fail/borrowck-closures-mut-of-imm.rs @@ -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 } diff --git a/src/test/compile-fail/borrowck-closures-two-mut.rs b/src/test/compile-fail/borrowck-closures-two-mut.rs index 6d382854d49f2b2b9cadf49bceb100effba039b2..0f284b5384913f41dce038cdd46da80b67894333 100644 --- a/src/test/compile-fail/borrowck-closures-two-mut.rs +++ b/src/test/compile-fail/borrowck-closures-two-mut.rs @@ -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 } diff --git a/src/test/compile-fail/borrowck-closures-unique-imm.rs b/src/test/compile-fail/borrowck-closures-unique-imm.rs index dfe5de09c50979284ebd5049d16e8f9916ee5c33..a9cc9e967f6ff70ecdabda9052ef7f118864f3d6 100644 --- a/src/test/compile-fail/borrowck-closures-unique-imm.rs +++ b/src/test/compile-fail/borrowck-closures-unique-imm.rs @@ -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 }; diff --git a/src/test/compile-fail/borrowck-closures-unique.rs b/src/test/compile-fail/borrowck-closures-unique.rs index febc84ccd44613c8fb7401c8c852cad9c880ca8b..9a772cc49b87b62ac8b6e84caa81bbf0b7b0467f 100644 --- a/src/test/compile-fail/borrowck-closures-unique.rs +++ b/src/test/compile-fail/borrowck-closures-unique.rs @@ -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() { diff --git a/src/test/compile-fail/borrowck-closures-use-after-free.rs b/src/test/compile-fail/borrowck-closures-use-after-free.rs index 735d9ece9b1a500844cf22701ee8f9412cfeee25..23c90fcf574d5bb45b920cb6ba60a6b84475f31b 100644 --- a/src/test/compile-fail/borrowck-closures-use-after-free.rs +++ b/src/test/compile-fail/borrowck-closures-use-after-free.rs @@ -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` diff --git a/src/test/compile-fail/borrowck-init-in-called-fn-expr.rs b/src/test/compile-fail/borrowck-init-in-called-fn-expr.rs index d759a5738bd22703b7187705b8dd3fdca5511201..5496a9dd4b3611c78b2a0fc70f7f4845ea5f6d08 100644 --- a/src/test/compile-fail/borrowck-init-in-called-fn-expr.rs +++ b/src/test/compile-fail/borrowck-init-in-called-fn-expr.rs @@ -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` }; diff --git a/src/test/compile-fail/borrowck-init-in-fn-expr.rs b/src/test/compile-fail/borrowck-init-in-fn-expr.rs index 07e2ff084664dcfc11d8a8abc97baf0341e165ca..33c284c71b341df0558956f2e861747d3d5fa37f 100644 --- a/src/test/compile-fail/borrowck-init-in-fn-expr.rs +++ b/src/test/compile-fail/borrowck-init-in-fn-expr.rs @@ -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` }; diff --git a/src/test/compile-fail/borrowck-insert-during-each.rs b/src/test/compile-fail/borrowck-insert-during-each.rs index a84a025d8a8ee9d89dcd4323be6ad169781dd34c..0428ee83065173a99156ebf4a7bfa7e78d8cbdd5 100644 --- a/src/test/compile-fail/borrowck-insert-during-each.rs +++ b/src/test/compile-fail/borrowck-insert-during-each.rs @@ -16,7 +16,7 @@ struct Foo { } impl Foo { - pub fn foo(&mut self, fun: |&int|) { + pub fn foo(&mut self, mut fun: F) where F: FnMut(&int) { for f in self.n.iter() { fun(f); } diff --git a/src/test/compile-fail/borrowck-lend-flow-if.rs b/src/test/compile-fail/borrowck-lend-flow-if.rs index 8a7ecde700ae6f7cbab94f64f68d198002007978..f798d170f963b35dd8a2f255c96f5c6df4694596 100644 --- a/src/test/compile-fail/borrowck-lend-flow-if.rs +++ b/src/test/compile-fail/borrowck-lend-flow-if.rs @@ -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) where F: FnOnce() -> bool { panic!() } fn produce() -> T { panic!(); } fn inc(v: &mut Box) { diff --git a/src/test/compile-fail/borrowck-lend-flow-loop.rs b/src/test/compile-fail/borrowck-lend-flow-loop.rs index 6adcfad33f46c58c582f7ffe1d14538f2cefa762..ff038b545d5fec4013c51b85f3e2692956b2f276 100644 --- a/src/test/compile-fail/borrowck-lend-flow-loop.rs +++ b/src/test/compile-fail/borrowck-lend-flow-loop.rs @@ -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() { diff --git a/src/test/compile-fail/borrowck-lend-flow.rs b/src/test/compile-fail/borrowck-lend-flow.rs index de8c7d9def4e1b709f2441091e18a809c0a42384..85fc7fb87b34034b9a6c4379b7a4191799713b1f 100644 --- a/src/test/compile-fail/borrowck-lend-flow.rs +++ b/src/test/compile-fail/borrowck-lend-flow.rs @@ -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) where F: FnOnce() -> bool { panic!() } fn produce() -> T { panic!(); } fn inc(v: &mut Box) { diff --git a/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs b/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs index 9bd2d48b29a8587c8b6a00108950396ca1cead28..5c282495cc239419705136bcbb19aaf62fb720f4 100644 --- a/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs +++ b/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs @@ -10,7 +10,7 @@ use std::thread::Thread; -fn borrow(v: &int, f: |x: &int|) { +fn borrow(v: &int, f: F) where F: FnOnce(&int) { f(v); } diff --git a/src/test/compile-fail/borrowck-loan-blocks-mut-uniq.rs b/src/test/compile-fail/borrowck-loan-blocks-mut-uniq.rs index bfa890ada9f1925fc44611c2b15dfd6080a4e7e4..b6a71fcd446abe72bb6fbdf3067a47ab2e0750e6 100644 --- a/src/test/compile-fail/borrowck-loan-blocks-mut-uniq.rs +++ b/src/test/compile-fail/borrowck-loan-blocks-mut-uniq.rs @@ -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(v: &int, f: F) where F: FnOnce(&int) { f(v); } diff --git a/src/test/compile-fail/borrowck-loan-rcvr.rs b/src/test/compile-fail/borrowck-loan-rcvr.rs index d678fd48f21d2584a65ee95e1f0a1709d7c9ea2a..0ada3db47a4b6ec1884fa2bae169fb9bcae24d3c 100644 --- a/src/test/compile-fail/borrowck-loan-rcvr.rs +++ b/src/test/compile-fail/borrowck-loan-rcvr.rs @@ -13,14 +13,14 @@ struct point { x: int, y: int } trait methods { fn impurem(&self); - fn blockm(&self, f: ||); + fn blockm(&self, f: F) where F: FnOnce(); } impl methods for point { fn impurem(&self) { } - fn blockm(&self, f: ||) { f() } + fn blockm(&self, f: F) where F: FnOnce() { f() } } fn a() { diff --git a/src/test/compile-fail/borrowck-loan-vec-content.rs b/src/test/compile-fail/borrowck-loan-vec-content.rs index 200d208d140b69a054538222bf1d7d10c8fdf4a0..7849475ec67991cb519cf33dff826920764bfc84 100644 --- a/src/test/compile-fail/borrowck-loan-vec-content.rs +++ b/src/test/compile-fail/borrowck-loan-vec-content.rs @@ -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(_v: &int, f: F) where F: FnOnce() { f(); } diff --git a/src/test/compile-fail/borrowck-move-by-capture.rs b/src/test/compile-fail/borrowck-move-by-capture.rs index 9c9641bccfa144de2d76e538df8f038f3b2c2ef3..35f0751aa7895a941f1adecaf1a7d581114ec7da 100644 --- a/src/test/compile-fail/borrowck-move-by-capture.rs +++ b/src/test/compile-fail/borrowck-move-by-capture.rs @@ -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 }; } diff --git a/src/test/compile-fail/borrowck-move-in-irrefut-pat.rs b/src/test/compile-fail/borrowck-move-in-irrefut-pat.rs index c7b573562e3484747c7d272b28e7cd9f7d9ddc19..c5d23925a89b1f2d25c5470e2b43ea00a318457c 100644 --- a/src/test/compile-fail/borrowck-move-in-irrefut-pat.rs +++ b/src/test/compile-fail/borrowck-move-in-irrefut-pat.rs @@ -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) where F: FnOnce(&String) {} fn arg_item(&_x: &String) {} //~^ ERROR cannot move out of dereference of `&`-pointer diff --git a/src/test/compile-fail/borrowck-report-with-custom-diagnostic.rs b/src/test/compile-fail/borrowck-report-with-custom-diagnostic.rs index 82189c6b7c1f1b7fa4e1e240ec275b555b7cba66..0a47353683cfb7cfa82483a199c9767260e81183 100644 --- a/src/test/compile-fail/borrowck-report-with-custom-diagnostic.rs +++ b/src/test/compile-fail/borrowck-report-with-custom-diagnostic.rs @@ -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 diff --git a/src/test/compile-fail/break-outside-loop.rs b/src/test/compile-fail/break-outside-loop.rs index d72398a6ac5a71d2d80a2e0b8a12a5e44d1ebeab..1f257b8a5cba847d2b0d281a1ac0c78bea9cbbf4 100644 --- a/src/test/compile-fail/break-outside-loop.rs +++ b/src/test/compile-fail/break-outside-loop.rs @@ -14,7 +14,7 @@ struct Foo { fn cond() -> bool { true } -fn foo(_: ||) {} +fn foo(_: F) where F: FnOnce() {} fn main() { let pth = break; //~ ERROR: `break` outside of loop diff --git a/src/test/compile-fail/closure-bounds-cant-promote-superkind-in-struct.rs b/src/test/compile-fail/closure-bounds-cant-promote-superkind-in-struct.rs index 1ff9dc9dac4c296315b271d3660ab22e344f9d14..a02d6b7f5173acc3ea6b4f4f36b03baf020f4c02 100644 --- a/src/test/compile-fail/closure-bounds-cant-promote-superkind-in-struct.rs +++ b/src/test/compile-fail/closure-bounds-cant-promote-superkind-in-struct.rs @@ -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 where F: FnOnce() + 'static + Send { + field: F, } -fn foo(blk: ||:'static) -> X { - return X { field: blk }; //~ ERROR expected bounds `Send` +fn foo(blk: F) -> X 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 index 6b25e4be2d9a3f033e9e51d53ebcc379a74ef3e4..0000000000000000000000000000000000000000 --- a/src/test/compile-fail/closure-bounds-not-builtin.rs +++ /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 or the MIT license -// , 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() {} diff --git a/src/test/compile-fail/closure-bounds-static-cant-capture-borrowed.rs b/src/test/compile-fail/closure-bounds-static-cant-capture-borrowed.rs index 6769740294bc6c7892c78c9b55048c05c3ff3b20..d27529bad43052b776fc8702005e62cd1c01425d 100644 --- a/src/test/compile-fail/closure-bounds-static-cant-capture-borrowed.rs +++ b/src/test/compile-fail/closure-bounds-static-cant-capture-borrowed.rs @@ -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(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 }) } diff --git a/src/test/compile-fail/closure-bounds-subtype.rs b/src/test/compile-fail/closure-bounds-subtype.rs index 5bd9f20dd834368d7913a6c691360b25c841af78..509fffc5c9a882e2806b64b587fbf15d1c73e7e5 100644 --- a/src/test/compile-fail/closure-bounds-subtype.rs +++ b/src/test/compile-fail/closure-bounds-subtype.rs @@ -9,19 +9,19 @@ // except according to those terms. -fn take_any(_: ||) { +fn take_any(_: F) where F: FnOnce() { } -fn take_const_owned(_: ||:Sync+Send) { +fn take_const_owned(_: F) where F: FnOnce() + Sync + Send { } -fn give_any(f: ||) { +fn give_any(f: F) where F: FnOnce() { take_any(f); } -fn give_owned(f: ||:Send) { +fn give_owned(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() {} diff --git a/src/test/compile-fail/closure-reform-bad.rs b/src/test/compile-fail/closure-reform-bad.rs index 1e1889c7339d26ce6e430545bdf71cd5fb7987ac..ef01c96addeb8f555f4ba26919e7f3b65b73c961 100644 --- a/src/test/compile-fail/closure-reform-bad.rs +++ b/src/test/compile-fail/closure-reform-bad.rs @@ -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 index 7a1ebed0a82acb433a9d128ae54485fce6fe090b..0000000000000000000000000000000000000000 --- a/src/test/compile-fail/closure-that-fails.rs +++ /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 or the MIT license -// , 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 index 52f4c4749e224f90e1455befddc899c5cf7557a6..0000000000000000000000000000000000000000 --- a/src/test/compile-fail/coerce-bare-fn-to-closure-and-proc.rs +++ /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 or the MIT license -// , 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() { } diff --git a/src/test/compile-fail/dead-code-closure-bang.rs b/src/test/compile-fail/dead-code-closure-bang.rs index 0aa3c40fa5f88c64b1f38034a28635e5d2ceffe0..46f5f41d7282f89254c2c022629204c0aefe2f39 100644 --- a/src/test/compile-fail/dead-code-closure-bang.rs +++ b/src/test/compile-fail/dead-code-closure-bang.rs @@ -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 } diff --git a/src/test/compile-fail/extern-wrong-value-type.rs b/src/test/compile-fail/extern-wrong-value-type.rs index 6b01b83db21fd31d0c097a459a52f00c9ba10411..d7586af291e8638d77de1aa3344366c5c7272220 100644 --- a/src/test/compile-fail/extern-wrong-value-type.rs +++ b/src/test/compile-fail/extern-wrong-value-type.rs @@ -11,8 +11,10 @@ extern fn f() { } +fn is_fn(_: 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() } diff --git a/src/test/compile-fail/fn-variance-1.rs b/src/test/compile-fail/fn-variance-1.rs index 2277f7080af75c464225f56ee34b52336f579f1d..039628b67528289e2780b50d4f3441ea3199d748 100644 --- a/src/test/compile-fail/fn-variance-1.rs +++ b/src/test/compile-fail/fn-variance-1.rs @@ -12,7 +12,7 @@ fn takes_imm(x: &int) { } fn takes_mut(x: &mut int) { } -fn apply(t: T, f: |T|) { +fn apply(t: T, f: F) where F: FnOnce(T) { f(t) } diff --git a/src/test/compile-fail/immut-function-arguments.rs b/src/test/compile-fail/immut-function-arguments.rs index 71328acdd7017f406af5dbeafc876af001aa186b..827e648cca86d0a32113bf2a6ca38cecbea4cd2f 100644 --- a/src/test/compile-fail/immut-function-arguments.rs +++ b/src/test/compile-fail/immut-function-arguments.rs @@ -14,7 +14,7 @@ fn f(y: Box) { } fn g() { - let _frob: |Box| = |q| { *q = 2; }; //~ ERROR cannot assign + let _frob = |&: q: Box| { *q = 2; }; //~ ERROR cannot assign } diff --git a/src/test/compile-fail/issue-10291.rs b/src/test/compile-fail/issue-10291.rs index 924132c6de26bff8023a066ecc71ff66e77813df..dec4fc3b8f5b274649bb7f06a280f1cd50a64210 100644 --- a/src/test/compile-fail/issue-10291.rs +++ b/src/test/compile-fail/issue-10291.rs @@ -9,7 +9,7 @@ // except according to those terms. fn test<'x>(x: &'x int) { - drop::< for<'z>|&'z int| -> &'z int >(|z| { + drop:: FnMut(&'z int) -> &'z int>>(box |z| { x //~^ ERROR cannot infer an appropriate lifetime }); diff --git a/src/test/compile-fail/issue-11192.rs b/src/test/compile-fail/issue-11192.rs index 18a00d15eafe36610d5763fa63a6a28251e2fd20..f496c1e1227dbcc3b9be173558453f298a2c5e2c 100644 --- a/src/test/compile-fail/issue-11192.rs +++ b/src/test/compile-fail/issue-11192.rs @@ -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); diff --git a/src/test/compile-fail/issue-11873.rs b/src/test/compile-fail/issue-11873.rs index e1acab4008a9b1a65586d8859ee05775b8a61469..89667937531536fe306c3eb881b6a1e0dc772d02 100644 --- a/src/test/compile-fail/issue-11873.rs +++ b/src/test/compile-fail/issue-11873.rs @@ -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(); diff --git a/src/test/compile-fail/issue-14182.rs b/src/test/compile-fail/issue-14182.rs index 24256e31118e35b616ce779039e2cc2d1c2e7d3f..5033576a23482e2847b8bac03c1ccc99fb6e8300 100644 --- a/src/test/compile-fail/issue-14182.rs +++ b/src/test/compile-fail/issue-14182.rs @@ -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` diff --git a/src/test/compile-fail/issue-16939.rs b/src/test/compile-fail/issue-16939.rs index 7ec3fef5c878eb05a060356e60fa5b169b03392c..9d2212b69cee116de1d270b87f1010416b4ab45a 100644 --- a/src/test/compile-fail/issue-16939.rs +++ b/src/test/compile-fail/issue-16939.rs @@ -14,7 +14,7 @@ // wrong arity. fn _foo (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 index ad2ebff59bc51ad226ac51c9c04267772539bf75..0000000000000000000000000000000000000000 --- a/src/test/compile-fail/issue-17636.rs +++ /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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -trait MyItem {} -impl MyItem for T {} - -pub fn build_archive<'a, I: MyItem<&'a (|&uint|:'a)>>(files: I) {} - -fn main() { - build_archive(&(|_| { })); -//~^ ERROR not implemented -} diff --git a/src/test/compile-fail/issue-17651.rs b/src/test/compile-fail/issue-17651.rs index ab396edddf49c1031dce42f0a69a9a6d1ff952f0..970b14c7eb7cc612224a3e12d1bbf226bbd78c5d 100644 --- a/src/test/compile-fail/issue-17651.rs +++ b/src/test/compile-fail/issue-17651.rs @@ -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] } diff --git a/src/test/compile-fail/issue-18343.rs b/src/test/compile-fail/issue-18343.rs index 1608d2137fc3216ee92862d8f79619c584b9aa09..f87a0d774fa7c7c9745b833654d097c658aa5d29 100644 --- a/src/test/compile-fail/issue-18343.rs +++ b/src/test/compile-fail/issue-18343.rs @@ -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 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 index e93acb3f064af5c38b441e4d8d33e4e4fee808d7..0000000000000000000000000000000000000000 --- a/src/test/compile-fail/issue-18345.rs +++ /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 or the MIT license -// , 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() {} diff --git a/src/test/compile-fail/issue-18783.rs b/src/test/compile-fail/issue-18783.rs index 8097d93ca07458a855fc3adaac8e0be440ff5520..3a0fbddf8185fa3d9fdb5345023d79b131d150f4 100644 --- a/src/test/compile-fail/issue-18783.rs +++ b/src/test/compile-fail/issue-18783.rs @@ -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); } -impl<'c> Push<'c> for RefCell> { - fn push<'f: 'c>(&self, fun: ||:'f -> ()) { +impl<'c> Push<'c> for RefCell>> { + fn push<'f: 'c>(&self, fun: Box) { 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 index aa7c4c3060bdb93ebd4a7a04df865dad2ae4ff60..0000000000000000000000000000000000000000 --- a/src/test/compile-fail/issue-19009.rs +++ /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 or the MIT license -// , 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 index 545e3f8acb139caf7eecd36d2df47779ae4d0bed..0000000000000000000000000000000000000000 --- a/src/test/compile-fail/issue-19141.rs +++ /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 or the MIT license -// , 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 index e5d8d3327199b9dfc361d0c1c9c2014fcfbe2b71..0000000000000000000000000000000000000000 --- a/src/test/compile-fail/issue-20193.rs +++ /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 or the MIT license -// , 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 index 3ff4557ae80ed3155449e1864ec15be361fb8a24..0000000000000000000000000000000000000000 --- a/src/test/compile-fail/issue-20228-1.rs +++ /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 or the MIT license -// , 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 index 5fec4268bf7c2b78cb3cfa10b27babf86f8b4dbc..0000000000000000000000000000000000000000 --- a/src/test/compile-fail/issue-20228-2.rs +++ /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 or the MIT license -// , 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() { -} diff --git a/src/test/compile-fail/issue-2149.rs b/src/test/compile-fail/issue-2149.rs index b688cafb67459aab05c1701e8eb6968083c9c430..691660f897157f309dfcb52a2e3420b4db1dd729 100644 --- a/src/test/compile-fail/issue-2149.rs +++ b/src/test/compile-fail/issue-2149.rs @@ -9,17 +9,17 @@ // except according to those terms. trait vec_monad { - fn bind(&self, f: |A| -> Vec ); + fn bind(&self, f: F) where F: FnMut(A) -> Vec; } impl vec_monad for Vec { - fn bind(&self, f: |A| -> Vec ) { + fn bind(&self, mut f: F) where F: FnMut(A) -> Vec { 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` } diff --git a/src/test/compile-fail/issue-3044.rs b/src/test/compile-fail/issue-3044.rs index 0f7cc2cb72b8e2b05b73dcb6456119e3ade48d33..c67d6b1ce8f7ce17e063dcc42ab31835527ca254 100644 --- a/src/test/compile-fail/issue-3044.rs +++ b/src/test/compile-fail/issue-3044.rs @@ -11,7 +11,7 @@ fn main() { let needlesArr: Vec = vec!('a', 'f'); - needlesArr.iter().fold(|x, y| { + needlesArr.iter().fold(|&: x, y| { }); //~^^ ERROR this function takes 2 parameters but 1 parameter was supplied // diff --git a/src/test/compile-fail/issue-3563.rs b/src/test/compile-fail/issue-3563.rs index 38f28bd79dfa1905d9ed09d82583c03d4b5f1ee4..86ab9be77fc6808389e948f913e33d1ac10ff23e 100644 --- a/src/test/compile-fail/issue-3563.rs +++ b/src/test/compile-fail/issue-3563.rs @@ -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() {} diff --git a/src/test/compile-fail/issue-4335.rs b/src/test/compile-fail/issue-4335.rs index eadd16348b2e8573b81138986176cd7d9aca6f4e..d4f9ea5b276f9fc4ed4165528e021999db1e37c5 100644 --- a/src/test/compile-fail/issue-4335.rs +++ b/src/test/compile-fail/issue-4335.rs @@ -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 } -fn f<'r, T>(v: &'r T) -> ||: 'r -> T { - id(|| *v) //~ ERROR cannot infer +fn f<'r, T>(v: &'r T) -> Box 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 index 5063a78e38348d6eb0e4e8fcbdaf4ebfe70f7e30..0000000000000000000000000000000000000000 --- a/src/test/compile-fail/issue-4523.rs +++ /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 or the MIT license -// , 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 -} diff --git a/src/test/compile-fail/issue-5216.rs b/src/test/compile-fail/issue-5216.rs index 18af9736ed9f8408224d80d0c78095a9d1e0a189..fef414ce978a8756e263cc821d6035950611033d 100644 --- a/src/test/compile-fail/issue-5216.rs +++ b/src/test/compile-fail/issue-5216.rs @@ -9,12 +9,12 @@ // except according to those terms. fn f() { } -struct S(||); //~ ERROR explicit lifetime bound required +struct S(Box); //~ ERROR explicit lifetime bound required pub static C: S = S(f); fn g() { } -type T = ||; //~ ERROR explicit lifetime bound required +type T = Box; //~ ERROR explicit lifetime bound required pub static D: T = g; fn main() {} diff --git a/src/test/compile-fail/issue-5239-1.rs b/src/test/compile-fail/issue-5239-1.rs index 88b08655caad2547d3fc066932c15cf1e1062859..1691688fd84645f65d31446cae23cdd48d3e2f44 100644 --- a/src/test/compile-fail/issue-5239-1.rs +++ b/src/test/compile-fail/issue-5239-1.rs @@ -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` } diff --git a/src/test/compile-fail/issue-6801.rs b/src/test/compile-fail/issue-6801.rs index 5925f6869391a1d4f6280a08567d8bac6e3a714c..433ae3bf89e03a540c9965ef21f327556d044c52 100644 --- a/src/test/compile-fail/issue-6801.rs +++ b/src/test/compile-fail/issue-6801.rs @@ -17,13 +17,13 @@ fn twice(x: Box) -> uint { *x * 2 } -fn invoke(f: || -> uint) { +fn invoke(f: F) where F: FnOnce() -> uint { f(); } fn main() { let x : Box = box 9; - let sq : || -> uint = || { *x * *x }; + let sq = |:| { *x * *x }; twice(x); //~ ERROR: cannot move out of invoke(sq); diff --git a/src/test/compile-fail/issue-7573.rs b/src/test/compile-fail/issue-7573.rs index 0e978a09edd2d8669ae60c7dd7f147e6978065ae..897afb1c10245a256ddeb449afe47292b8b44b6b 100644 --- a/src/test/compile-fail/issue-7573.rs +++ b/src/test/compile-fail/issue-7573.rs @@ -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(mut f: F) where F: FnMut(&CrateId) { let stuff = ["foo", "bar"]; for l in stuff.iter() { diff --git a/src/test/compile-fail/kindck-copy.rs b/src/test/compile-fail/kindck-copy.rs index 8868c7f8256da5b646386e049ae389a028c9de66..b5725249812f6ccd2edfb018b5d3fddbe9d62ded 100644 --- a/src/test/compile-fail/kindck-copy.rs +++ b/src/test/compile-fail/kindck-copy.rs @@ -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>(); diff --git a/src/test/compile-fail/kindck-send-object.rs b/src/test/compile-fail/kindck-send-object.rs index 3b67e98f42ca81d55e51967c243fa74a41952ef5..c300096caf1e09c87bcb4f8e6c99d8e9cecbe837 100644 --- a/src/test/compile-fail/kindck-send-object.rs +++ b/src/test/compile-fail/kindck-send-object.rs @@ -27,14 +27,9 @@ fn box_object_with_no_bound_not_ok<'a>() { assert_send::>(); //~ 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::>(); - assert_send::<||:Send>; } fn main() { } diff --git a/src/test/compile-fail/lint-unused-mut-variables.rs b/src/test/compile-fail/lint-unused-mut-variables.rs index 29b4686198be1fc8a91a539d3282ba4e5b3cef9d..7513e1bc21a4a7e1a953beb1dcbde9af804cb43d 100644 --- a/src/test/compile-fail/lint-unused-mut-variables.rs +++ b/src/test/compile-fail/lint-unused-mut-variables.rs @@ -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) where F: FnOnce() {} // make sure the lint attribute can be turned off #[allow(unused_mut)] diff --git a/src/test/compile-fail/lint-unused-unsafe.rs b/src/test/compile-fail/lint-unused-unsafe.rs index df3feefa881f3f28231da76f42a16c03d62c80c4..5c8e73e674751d109db04ffec9e4d657e0abae90 100644 --- a/src/test/compile-fail/lint-unused-unsafe.rs +++ b/src/test/compile-fail/lint-unused-unsafe.rs @@ -20,7 +20,7 @@ mod foo { } } -fn callback(_f: || -> T) -> T { panic!() } +fn callback(_f: F) -> T where F: FnOnce() -> T { panic!() } unsafe fn unsf() {} fn bad1() { unsafe {} } //~ ERROR: unnecessary `unsafe` block diff --git a/src/test/compile-fail/liveness-closure-require-ret.rs b/src/test/compile-fail/liveness-closure-require-ret.rs index 6466310eb4d2e133b681961478cc29941c38cd6e..82de02f09813ce9a7ca0acd663f32048cd1007a9 100644 --- a/src/test/compile-fail/liveness-closure-require-ret.rs +++ b/src/test/compile-fail/liveness-closure-require-ret.rs @@ -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) -> int where F: FnOnce() -> int { f() } fn main() { println!("{}", force(|| {})); } //~ ERROR mismatched types diff --git a/src/test/compile-fail/moves-based-on-type-block-bad.rs b/src/test/compile-fail/moves-based-on-type-block-bad.rs index ee57377943d12b28a962c6316dee3b81cdcc7f24..14af49dfc49c5d379c9907fb9b49e66041d659a9 100644 --- a/src/test/compile-fail/moves-based-on-type-block-bad.rs +++ b/src/test/compile-fail/moves-based-on-type-block-bad.rs @@ -20,7 +20,7 @@ enum E { Baz } -fn f(s: &S, g: |&S|) { +fn f(s: &S, g: G) where G: FnOnce(&S) { g(s) } diff --git a/src/test/compile-fail/moves-based-on-type-move-out-of-closure-env-issue-1965.rs b/src/test/compile-fail/moves-based-on-type-move-out-of-closure-env-issue-1965.rs index f9614574abda970b749a44f43b6781085caa7e74..ab762332ee43da3ba48d32eeca32b4ca3cfd4b25 100644 --- a/src/test/compile-fail/moves-based-on-type-move-out-of-closure-env-issue-1965.rs +++ b/src/test/compile-fail/moves-based-on-type-move-out-of-closure-env-issue-1965.rs @@ -14,5 +14,5 @@ fn test(_x: Box) {} fn main() { let i = box 3; - let _f = || test(i); //~ ERROR cannot move out + let _f = |&:| test(i); //~ ERROR cannot move out } diff --git a/src/test/compile-fail/moves-based-on-type-no-recursive-stack-closure.rs b/src/test/compile-fail/moves-based-on-type-no-recursive-stack-closure.rs index 2a73b769895eeeb75be648157400f0bc3d73d75d..787e25ea319544606154d49020210379426a1f91 100644 --- a/src/test/compile-fail/moves-based-on-type-no-recursive-stack-closure.rs +++ b/src/test/compile-fail/moves-based-on-type-no-recursive-stack-closure.rs @@ -12,11 +12,13 @@ // 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 } 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(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 } diff --git a/src/test/compile-fail/pptypedef.rs b/src/test/compile-fail/pptypedef.rs index 4de56e32f560a98ba7dbb34e459bede38f950d01..ebda4e9103d604669547d28dd73e1d4e2a2aef8f 100644 --- a/src/test/compile-fail/pptypedef.rs +++ b/src/test/compile-fail/pptypedef.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn let_in(x: T, f: |T|) {} +fn let_in(x: T, f: F) where F: FnOnce(T) {} fn main() { let_in(3u, |i| { assert!(i == 3i); }); diff --git a/src/test/compile-fail/refutable-pattern-in-fn-arg.rs b/src/test/compile-fail/refutable-pattern-in-fn-arg.rs index 954d4b23e30faa942734b7a752d885591b0116d4..575e9864a92d3bd633febe9e08cdfb73c86acf9f 100644 --- a/src/test/compile-fail/refutable-pattern-in-fn-arg.rs +++ b/src/test/compile-fail/refutable-pattern-in-fn-arg.rs @@ -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); } diff --git a/src/test/compile-fail/region-bound-on-closure-outlives-call.rs b/src/test/compile-fail/region-bound-on-closure-outlives-call.rs index 13ab7acaf48353b99391e48826941e33afe59d4d..9e8281faf2f567c4f4bf4561182420c0771a1885 100644 --- a/src/test/compile-fail/region-bound-on-closure-outlives-call.rs +++ b/src/test/compile-fail/region-bound-on-closure-outlives-call.rs @@ -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(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 index bb895a318ff17d272128783425d352b16278e6a0..0000000000000000000000000000000000000000 --- a/src/test/compile-fail/regionck-closure-lifetimes.rs +++ /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 or the MIT license -// , 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() {} diff --git a/src/test/compile-fail/regions-addr-of-upvar-self.rs b/src/test/compile-fail/regions-addr-of-upvar-self.rs index 7a146c043c8389cfb776c42dc104be176c666f5e..fb60d8f7b27a4acb442fe0fcc7b3fafc3b5911d3 100644 --- a/src/test/compile-fail/regions-addr-of-upvar-self.rs +++ b/src/test/compile-fail/regions-addr-of-upvar-self.rs @@ -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; }; diff --git a/src/test/compile-fail/regions-bounded-by-send.rs b/src/test/compile-fail/regions-bounded-by-send.rs index e15cb25295aac7defa8ec6fa8766911fedf96830..0628bbb8bb08eb70a85813bb450bd8c8ee155da3 100644 --- a/src/test/compile-fail/regions-bounded-by-send.rs +++ b/src/test/compile-fail/regions-bounded-by-send.rs @@ -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>); diff --git a/src/test/compile-fail/regions-creating-enums.rs b/src/test/compile-fail/regions-creating-enums.rs index b15f0405d23c69bb5651e2003765a495b0aef151..1774c9fada946fc6a3806735a0052ace3f3d6a48 100644 --- a/src/test/compile-fail/regions-creating-enums.rs +++ b/src/test/compile-fail/regions-creating-enums.rs @@ -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 } } diff --git a/src/test/compile-fail/regions-escape-bound-fn-2.rs b/src/test/compile-fail/regions-escape-bound-fn-2.rs index 66103eb95888ac941e1cf123c8641d2b0978c584..547accbf0860d27ce85d7b65aedc27f0c709123d 100644 --- a/src/test/compile-fail/regions-escape-bound-fn-2.rs +++ b/src/test/compile-fail/regions-escape-bound-fn-2.rs @@ -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) where F: FnOnce(&int) { let x = 3; f(&x); } diff --git a/src/test/compile-fail/regions-escape-bound-fn.rs b/src/test/compile-fail/regions-escape-bound-fn.rs index fee84cf9656d1ceaae73f4fb5d02a75c55a63579..6d67bd80650fad0afa66f5e2a9e46087345eaa59 100644 --- a/src/test/compile-fail/regions-escape-bound-fn.rs +++ b/src/test/compile-fail/regions-escape-bound-fn.rs @@ -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) where F: FnOnce(&int) { let x = 3; f(&x); } diff --git a/src/test/compile-fail/regions-escape-method.rs b/src/test/compile-fail/regions-escape-method.rs index f92c264784ae6a402dc6d8d60e69e29d63b4abdd..e3771cfebba255cf7f656f3e4153486b0c6c6829 100644 --- a/src/test/compile-fail/regions-escape-method.rs +++ b/src/test/compile-fail/regions-escape-method.rs @@ -16,7 +16,7 @@ struct S; impl S { - fn f(&self, _: |&i32| -> B) { + fn f(&self, _: F) where F: FnOnce(&i32) -> B { } } diff --git a/src/test/compile-fail/regions-escape-via-trait-or-not.rs b/src/test/compile-fail/regions-escape-via-trait-or-not.rs index adc960b069d05d89f798d1a7e7673c5445e1189a..873d4cea0395e627f2dcbfcecdef8b4c59e19c81 100644 --- a/src/test/compile-fail/regions-escape-via-trait-or-not.rs +++ b/src/test/compile-fail/regions-escape-via-trait-or-not.rs @@ -20,7 +20,7 @@ fn get(self) -> int { } } -fn with(f: |x: &int| -> R) -> int { +fn with(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 index 91a6ff789ea39fb9ca31fba3b84b238711b82b7f..0000000000000000000000000000000000000000 --- a/src/test/compile-fail/regions-fn-subtyping.rs +++ /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 or the MIT license -// , 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(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::(of::()) 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 index 854584ec535e66ddb57ae48002b9c1a82e8bd3af..0000000000000000000000000000000000000000 --- a/src/test/compile-fail/regions-fns.rs +++ /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 or the MIT license -// , 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() { -} diff --git a/src/test/compile-fail/regions-free-region-ordering-callee.rs b/src/test/compile-fail/regions-free-region-ordering-callee.rs index 435d10a0a29a1c07db7a43a40d2ca3bfee547143..6e59a29b8cf2236f8e57110c0f4d00171b5eb47a 100644 --- a/src/test/compile-fail/regions-free-region-ordering-callee.rs +++ b/src/test/compile-fail/regions-free-region-ordering-callee.rs @@ -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 index 76bbe71cf75b5ba067ded39edfc32b3d20ef2ccb..0000000000000000000000000000000000000000 --- a/src/test/compile-fail/regions-freevar.rs +++ /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 or the MIT license -// , 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 - }) -} diff --git a/src/test/compile-fail/regions-infer-at-fn-not-param.rs b/src/test/compile-fail/regions-infer-at-fn-not-param.rs index 8af341e3ace42b9d949319d92199f98008180d8b..0c250e38258cec518bddb3a48a81e14c965be69b 100644 --- a/src/test/compile-fail/regions-infer-at-fn-not-param.rs +++ b/src/test/compile-fail/regions-infer-at-fn-not-param.rs @@ -9,15 +9,15 @@ // except according to those terms. struct parameterized1<'a> { - g: ||: 'a + g: Box } struct not_parameterized1 { - g: ||: 'static + g: Box } struct not_parameterized2 { - g: ||: 'static + g: Box } fn take1<'a>(p: parameterized1) -> parameterized1<'a> { p } diff --git a/src/test/compile-fail/regions-infer-borrow-scope-within-loop.rs b/src/test/compile-fail/regions-infer-borrow-scope-within-loop.rs index cf1fa2cfc4c2cbd8986f850bf48f8d06becf6086..c8edd936bf28b232a16e7fa50e33aded71fef4ef 100644 --- a/src/test/compile-fail/regions-infer-borrow-scope-within-loop.rs +++ b/src/test/compile-fail/regions-infer-borrow-scope-within-loop.rs @@ -11,7 +11,10 @@ fn borrow(x: &T) -> &T {x} -fn foo(cond: || -> bool, make_box: || -> Box) { +fn foo(mut cond: C, mut make_box: M) where + C: FnMut() -> bool, + M: FnMut() -> Box, +{ let mut y: ∫ loop { let x = make_box(); diff --git a/src/test/compile-fail/regions-infer-call-3.rs b/src/test/compile-fail/regions-infer-call-3.rs index 66f958c789336a1b778d7028d062e942379bb91d..ac41f2a5b3e47be208a6c53d257990538ab6dc51 100644 --- a/src/test/compile-fail/regions-infer-call-3.rs +++ b/src/test/compile-fail/regions-infer-call-3.rs @@ -10,7 +10,7 @@ fn select<'r>(x: &'r int, y: &'r int) -> &'r int { x } -fn with(f: |x: &int| -> T) -> T { +fn with(f: F) -> T where F: FnOnce(&int) -> T { f(&20) } diff --git a/src/test/compile-fail/regions-infer-invariance-due-to-mutability-3.rs b/src/test/compile-fail/regions-infer-invariance-due-to-mutability-3.rs index 33573cae0f66d5a2aa78d6c2d0b0348433de651d..190e444fe7e830bc92879e0e8792547767f753bb 100644 --- a/src/test/compile-fail/regions-infer-invariance-due-to-mutability-3.rs +++ b/src/test/compile-fail/regions-infer-invariance-due-to-mutability-3.rs @@ -10,7 +10,7 @@ struct invariant<'a> { - f: |x: &mut &'a int|: 'static + f: Box, } fn to_same_lifetime<'r>(bi: invariant<'r>) { diff --git a/src/test/compile-fail/regions-infer-invariance-due-to-mutability-4.rs b/src/test/compile-fail/regions-infer-invariance-due-to-mutability-4.rs index 66dcb5fdebd2d0fa3d4bee961aadf0b807854160..71d0c988c5e274e0849c8c6b8b24c4169d0f14d6 100644 --- a/src/test/compile-fail/regions-infer-invariance-due-to-mutability-4.rs +++ b/src/test/compile-fail/regions-infer-invariance-due-to-mutability-4.rs @@ -10,7 +10,7 @@ struct invariant<'a> { - f: ||: 'static -> &mut &'a int + f: Box FnOnce() -> &'b mut &'a int + 'static>, } fn to_same_lifetime<'r>(bi: invariant<'r>) { diff --git a/src/test/compile-fail/regions-infer-not-param.rs b/src/test/compile-fail/regions-infer-not-param.rs index b84f13ec37feb44d16654af4e6bf795c965046f3..323ebc3c20b37c3aad95cc84735b4de70bdc0483 100644 --- a/src/test/compile-fail/regions-infer-not-param.rs +++ b/src/test/compile-fail/regions-infer-not-param.rs @@ -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 } struct indirect2<'a> { // But here it is set to 'a - g: |direct<'a>|: 'static + g: Box) + 'static> } fn take_direct<'a,'b>(p: direct<'a>) -> direct<'b> { p } //~ ERROR mismatched types diff --git a/src/test/compile-fail/regions-name-undeclared.rs b/src/test/compile-fail/regions-name-undeclared.rs index ffd1501075e94c594b3e3f7c9932f742654196c1..b9c721159f2b44c125117afe7e7523f6b047a821 100644 --- a/src/test/compile-fail/regions-name-undeclared.rs +++ b/src/test/compile-fail/regions-name-undeclared.rs @@ -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 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 FnOnce(&'a int, + &'b int, //~ ERROR undeclared lifetime + Box FnOnce(&'a int, + &'b int)>, + &'b int)>, //~ ERROR undeclared lifetime c: &'a int) //~ ERROR undeclared lifetime { } diff --git a/src/test/compile-fail/regions-nested-fns-2.rs b/src/test/compile-fail/regions-nested-fns-2.rs index a08cf2263894dfc5396a63164f119f48588b16a8..b7fe893a1f5bbca1a2857c8b9212e0238b02bdcc 100644 --- a/src/test/compile-fail/regions-nested-fns-2.rs +++ b/src/test/compile-fail/regions-nested-fns-2.rs @@ -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) where F: for<'z> FnOnce(&'z int) -> &'z int {} fn nested() { let y = 3; diff --git a/src/test/compile-fail/regions-nested-fns.rs b/src/test/compile-fail/regions-nested-fns.rs index f4654367970d11d052b16a23f73f54b8933e3113..5d8ef718ef0d354b7bfe93720256f002b8f55c2a 100644 --- a/src/test/compile-fail/regions-nested-fns.rs +++ b/src/test/compile-fail/regions-nested-fns.rs @@ -14,13 +14,13 @@ fn nested<'x>(x: &'x int) { let y = 3; let mut ay = &y; - ignore::< for<'z>|&'z int|>(|z| { + ignore:: FnMut(&'z int)>>(box |z| { ay = x; //~ ERROR cannot infer ay = &y; ay = z; }); - ignore::< for<'z>|&'z int| -> &'z int>(|z| { + ignore::< Box 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; diff --git a/src/test/compile-fail/regions-ref-in-fn-arg.rs b/src/test/compile-fail/regions-ref-in-fn-arg.rs index 47fca8bb8df2374e83395d5a46599afbf96441cd..f9eecb60c6af118a72680ad92e3ef5fb1f7bc9b6 100644 --- a/src/test/compile-fail/regions-ref-in-fn-arg.rs +++ b/src/test/compile-fail/regions-ref-in-fn-arg.rs @@ -13,7 +13,7 @@ fn arg_item(box ref x: Box) -> &'static int { x //~^ ERROR borrowed value does not live long enough } -fn with(f: |Box| -> R) -> R { f(box 3) } +fn with(f: F) -> R where F: FnOnce(Box) -> R { f(box 3) } fn arg_closure() -> &'static int { with(|box ref x| x) //~ ERROR borrowed value does not live long enough diff --git a/src/test/compile-fail/regions-ret-borrowed-1.rs b/src/test/compile-fail/regions-ret-borrowed-1.rs index 997775efa84b52d60756dfc3ed3c62652f37dbbb..bd14d31217e88269ee580d55bdb45ed2fa255b03 100644 --- a/src/test/compile-fail/regions-ret-borrowed-1.rs +++ b/src/test/compile-fail/regions-ret-borrowed-1.rs @@ -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(f: for<'a>|x: &'a int| -> R) -> R { +fn with(f: F) -> R where F: for<'a> FnOnce(&'a int) -> R { f(&3) } diff --git a/src/test/compile-fail/regions-ret-borrowed.rs b/src/test/compile-fail/regions-ret-borrowed.rs index 465f4410fbbccb2d05451c0db6240e5433815a9f..4dfd4f1709a6f2894da09c0d2a7deac419595b32 100644 --- a/src/test/compile-fail/regions-ret-borrowed.rs +++ b/src/test/compile-fail/regions-ret-borrowed.rs @@ -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(f: |x: &int| -> R) -> R { +fn with(f: F) -> R where F: FnOnce(&int) -> R { f(&3) } diff --git a/src/test/compile-fail/regions-return-ref-to-upvar-issue-17403.rs b/src/test/compile-fail/regions-return-ref-to-upvar-issue-17403.rs index aedaced5794a784a9449be54262e31beab676478..d7b2a45cc63bb6f10457472e5ba11db80dbc0604 100644 --- a/src/test/compile-fail/regions-return-ref-to-upvar-issue-17403.rs +++ b/src/test/compile-fail/regions-return-ref-to-upvar-issue-17403.rs @@ -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(); - } } diff --git a/src/test/compile-fail/regions-steal-closure.rs b/src/test/compile-fail/regions-steal-closure.rs index 7ffc6a75cff8ca9ac9d5a8b48a3d5fecf355f45b..991040bc62fea1ef8f4151002c6187db889e9283 100644 --- a/src/test/compile-fail/regions-steal-closure.rs +++ b/src/test/compile-fail/regions-steal-closure.rs @@ -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, } -fn box_it<'r>(x: ||: 'r) -> closure_box<'r> { +fn box_it<'r>(x: Box) -> 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(()); } diff --git a/src/test/compile-fail/type-arg-out-of-scope.rs b/src/test/compile-fail/type-arg-out-of-scope.rs index ac2f9d0379f64d1a63bd3c468ceb032e53bca8c6..3249794e5c822a879e0b83e6f5356cb1b93510bc 100644 --- a/src/test/compile-fail/type-arg-out-of-scope.rs +++ b/src/test/compile-fail/type-arg-out-of-scope.rs @@ -10,6 +10,6 @@ // error-pattern:can't use type parameters from outer function; try using fn foo(x: T) { - fn bar(f: |T| -> T) { } + fn bar(f: Box T>) { } } fn main() { foo(1); }