diff --git a/src/test/compile-fail/access-mode-in-closures.rs b/src/test/compile-fail/access-mode-in-closures.rs index e1696f0e63e..f15157d126e 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 453d7ffdad5..f14668192f8 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 e268b0e93fd..00000000000 --- 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 76af956a26f..00000000000 --- 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 e14911d3508..a6801a6a51a 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 1b4e5891f94..2804b8c48a7 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 a37717ed5d9..e519e57d178 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 002ae5a7d28..6dbdff9441d 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 886026e45d9..47a47d04432 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 @@ fn g() { } 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 @@ fn h() { } 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 8163df5e967..30e1421ba26 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 6d382854d49..0f284b53849 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 @@ fn g() { } 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 dfe5de09c50..a9cc9e967f6 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 febc84ccd44..9a772cc49b8 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 735d9ece9b1..23c90fcf574 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 @@ impl Drop for Foo { 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 d759a5738bd..5496a9dd4b3 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 07e2ff08466..33c284c71b3 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 a84a025d8a8..0428ee83065 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 8a7ecde700a..f798d170f96 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 6adcfad33f4..ff038b545d5 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 de8c7d9def4..85fc7fb87b3 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 9bd2d48b29a..5c282495cc2 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 bfa890ada9f..b6a71fcd446 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 d678fd48f21..0ada3db47a4 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 200d208d140..7849475ec67 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 9c9641bccfa..35f0751aa78 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 c7b573562e3..c5d23925a89 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 82189c6b7c1..0a47353683c 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 d72398a6ac5..1f257b8a5cb 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 1ff9dc9dac4..a02d6b7f517 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 6b25e4be2d9..00000000000 --- 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 6769740294b..d27529bad43 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 5bd9f20dd83..509fffc5c9a 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 1e1889c7339..ef01c96adde 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 7a1ebed0a82..00000000000 --- 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 52f4c4749e2..00000000000 --- 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 0aa3c40fa5f..46f5f41d728 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 6b01b83db21..d7586af291e 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 2277f7080af..039628b6752 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 71328acdd70..827e648cca8 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 924132c6de2..dec4fc3b8f5 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 18a00d15eaf..f496c1e1227 100644 --- a/src/test/compile-fail/issue-11192.rs +++ b/src/test/compile-fail/issue-11192.rs @@ -20,7 +20,7 @@ impl Drop for Foo { 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 e1acab4008a..89667937531 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 24256e31118..5033576a234 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 7ec3fef5c87..9d2212b69ce 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 ad2ebff59bc..00000000000 --- 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 ab396edddf4..970b14c7eb7 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 1608d2137fc..f87a0d774fa 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 e93acb3f064..00000000000 --- 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 8097d93ca07..3a0fbddf818 100644 --- a/src/test/compile-fail/issue-18783.rs +++ b/src/test/compile-fail/issue-18783.rs @@ -13,8 +13,8 @@ use std::cell::RefCell; 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 aa7c4c3060b..00000000000 --- 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 545e3f8acb1..00000000000 --- 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 e5d8d332719..00000000000 --- 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 3ff4557ae80..00000000000 --- 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 5fec4268bf7..00000000000 --- 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 b688cafb674..691660f8971 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 0f7cc2cb72b..c67d6b1ce8f 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 38f28bd79df..86ab9be77fc 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 eadd16348b2..d4f9ea5b276 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 5063a78e383..00000000000 --- 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 18af9736ed9..fef414ce978 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 88b08655caa..1691688fd84 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 5925f686939..433ae3bf89e 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 0e978a09edd..897afb1c102 100644 --- a/src/test/compile-fail/issue-7573.rs +++ b/src/test/compile-fail/issue-7573.rs @@ -25,7 +25,7 @@ impl 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 8868c7f8256..b5725249812 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 3b67e98f42c..c300096caf1 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 29b4686198b..7513e1bc21a 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 main() { _ => {} } - 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 main() { 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 df3feefa881..5c8e73e6747 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 6466310eb4d..82de02f0981 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 ee57377943d..14af49dfc49 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 f9614574abd..ab762332ee4 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 2a73b769895..787e25ea319 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 4de56e32f56..ebda4e9103d 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 954d4b23e30..575e9864a92 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 13ab7acaf48..9e8281faf2f 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 bb895a318ff..00000000000 --- 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 7a146c043c8..fb60d8f7b27 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 e15cb25295a..0628bbb8bb0 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 b15f0405d23..1774c9fada9 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 66103eb9588..547accbf086 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 fee84cf9656..6d67bd80650 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 f92c264784a..e3771cfebba 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 adc960b069d..873d4cea039 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 @@ impl<'a> Deref for &'a 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 91a6ff789ea..00000000000 --- 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 854584ec535..00000000000 --- 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 435d10a0a29..6e59a29b8cf 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 76bbe71cf75..00000000000 --- 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 8af341e3ace..0c250e38258 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 cf1fa2cfc4c..c8edd936bf2 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 66f958c7893..ac41f2a5b3e 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 33573cae0f6..190e444fe7e 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 66dcb5fdebd..71d0c988c5e 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 b84f13ec37f..323ebc3c20b 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 ffd1501075e..b9c721159f2 100644 --- a/src/test/compile-fail/regions-name-undeclared.rs +++ b/src/test/compile-fail/regions-name-undeclared.rs @@ -43,19 +43,16 @@ fn bar<'a>(x: &'a int) { // &'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 a08cf226389..b7fe893a1f5 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 f4654367970..5d8ef718ef0 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 47fca8bb8df..f9eecb60c6a 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 997775efa84..bd14d31217e 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 465f4410fbb..4dfd4f1709a 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 aedaced5794..d7b2a45cc63 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 7ffc6a75cff..991040bc62f 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 ac2f9d0379f..3249794e5c8 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); }