diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-09-19 09:59:45 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-09-19 09:59:45 -0700 |
| commit | 63cee1ada360fc7ee2199cfa77934a88006101fb (patch) | |
| tree | 7578a660b73c42d0abe1434a2a6cd2d04407c9f0 /src/test | |
| parent | af3889f6979647b9bd2dc5f5132d80e3e5b405a5 (diff) | |
| parent | 7c00d77e8bd18d2e1873e8e995885b3500a88a0d (diff) | |
| download | rust-63cee1ada360fc7ee2199cfa77934a88006101fb.tar.gz rust-63cee1ada360fc7ee2199cfa77934a88006101fb.zip | |
rollup merge of #17041 : pcwalton/right-unboxed-closure-sugar
Diffstat (limited to 'src/test')
10 files changed, 51 insertions, 17 deletions
diff --git a/src/test/compile-fail/borrowck-unboxed-closures.rs b/src/test/compile-fail/borrowck-unboxed-closures.rs index d822bb22e2a..03438b1d7e1 100644 --- a/src/test/compile-fail/borrowck-unboxed-closures.rs +++ b/src/test/compile-fail/borrowck-unboxed-closures.rs @@ -10,17 +10,17 @@ #![feature(overloaded_calls)] -fn a<F:|&: int, int| -> int>(mut f: F) { +fn a<F:Fn(int, int) -> int>(mut f: F) { let g = &mut f; f(1, 2); //~ ERROR cannot borrow `f` as immutable //~^ ERROR cannot borrow `f` as immutable } -fn b<F:|&mut: int, int| -> int>(f: F) { +fn b<F:FnMut(int, int) -> int>(f: F) { f(1, 2); //~ ERROR cannot borrow immutable argument } -fn c<F:|: int, int| -> int>(f: F) { +fn c<F:FnOnce(int, int) -> int>(f: F) { f(1, 2); f(1, 2); //~ ERROR use of moved value } diff --git a/src/test/compile-fail/unboxed-closure-sugar-nonexistent-trait.rs b/src/test/compile-fail/unboxed-closure-sugar-nonexistent-trait.rs new file mode 100644 index 00000000000..f51160a1b23 --- /dev/null +++ b/src/test/compile-fail/unboxed-closure-sugar-nonexistent-trait.rs @@ -0,0 +1,18 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn f<F:Nonexist(int) -> int>(x: F) {} //~ ERROR unresolved trait + +type Typedef = int; + +fn g<F:Typedef(int) -> int>(x: F) {} //~ ERROR `Typedef` is not a trait + +fn main() {} + diff --git a/src/test/compile-fail/unboxed-closure-sugar-wrong-trait.rs b/src/test/compile-fail/unboxed-closure-sugar-wrong-trait.rs new file mode 100644 index 00000000000..a751ae1c518 --- /dev/null +++ b/src/test/compile-fail/unboxed-closure-sugar-wrong-trait.rs @@ -0,0 +1,17 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +trait Trait {} + +fn f<F:Trait(int) -> int>(x: F) {} +//~^ ERROR unboxed function trait must be one of `Fn`, `FnMut`, or `FnOnce` + +fn main() {} + diff --git a/src/test/compile-fail/unboxed-closures-wrong-trait.rs b/src/test/compile-fail/unboxed-closures-wrong-trait.rs index 27f1da75c3a..97ad64a77ba 100644 --- a/src/test/compile-fail/unboxed-closures-wrong-trait.rs +++ b/src/test/compile-fail/unboxed-closures-wrong-trait.rs @@ -10,7 +10,7 @@ #![feature(lang_items, overloaded_calls, unboxed_closures)] -fn c<F:|: int, int| -> int>(f: F) -> int { +fn c<F:FnOnce(int, int) -> int>(f: F) -> int { f(5, 6) } diff --git a/src/test/run-pass/fn-trait-sugar.rs b/src/test/run-pass/fn-trait-sugar.rs index ccb5634f7a2..b0947f46a86 100644 --- a/src/test/run-pass/fn-trait-sugar.rs +++ b/src/test/run-pass/fn-trait-sugar.rs @@ -21,7 +21,7 @@ impl FnMut<(int,),int> for S { } } -fn call_it<F:|int|->int>(mut f: F, x: int) -> int { +fn call_it<F:FnMut(int)->int>(mut f: F, x: int) -> int { f.call_mut((x,)) + 3 } diff --git a/src/test/run-pass/unboxed-closures-all-traits.rs b/src/test/run-pass/unboxed-closures-all-traits.rs index c362a83e60c..d9120495155 100644 --- a/src/test/run-pass/unboxed-closures-all-traits.rs +++ b/src/test/run-pass/unboxed-closures-all-traits.rs @@ -10,15 +10,15 @@ #![feature(lang_items, overloaded_calls, unboxed_closures)] -fn a<F:|&: int, int| -> int>(f: F) -> int { +fn a<F:Fn(int, int) -> int>(f: F) -> int { f(1, 2) } -fn b<F:|&mut: int, int| -> int>(mut f: F) -> int { +fn b<F:FnMut(int, int) -> int>(mut f: F) -> int { f(3, 4) } -fn c<F:|: int, int| -> int>(f: F) -> int { +fn c<F:FnOnce(int, int) -> int>(f: F) -> int { f(5, 6) } diff --git a/src/test/run-pass/unboxed-closures-drop.rs b/src/test/run-pass/unboxed-closures-drop.rs index f20dddcae54..a455e4d2032 100644 --- a/src/test/run-pass/unboxed-closures-drop.rs +++ b/src/test/run-pass/unboxed-closures-drop.rs @@ -41,15 +41,15 @@ impl Drop for Droppable { } } -fn a<F:|&: int, int| -> int>(f: F) -> int { +fn a<F:Fn(int, int) -> int>(f: F) -> int { f(1, 2) } -fn b<F:|&mut: int, int| -> int>(mut f: F) -> int { +fn b<F:FnMut(int, int) -> int>(mut f: F) -> int { f(3, 4) } -fn c<F:|: int, int| -> int>(f: F) -> int { +fn c<F:FnOnce(int, int) -> int>(f: F) -> int { f(5, 6) } diff --git a/src/test/run-pass/unboxed-closures-single-word-env.rs b/src/test/run-pass/unboxed-closures-single-word-env.rs index 754b1f70644..aef6956118e 100644 --- a/src/test/run-pass/unboxed-closures-single-word-env.rs +++ b/src/test/run-pass/unboxed-closures-single-word-env.rs @@ -13,15 +13,15 @@ #![feature(overloaded_calls, unboxed_closures)] -fn a<F:|&: int, int| -> int>(f: F) -> int { +fn a<F:Fn(int, int) -> int>(f: F) -> int { f(1, 2) } -fn b<F:|&mut: int, int| -> int>(mut f: F) -> int { +fn b<F:FnMut(int, int) -> int>(mut f: F) -> int { f(3, 4) } -fn c<F:|: int, int| -> int>(f: F) -> int { +fn c<F:FnOnce(int, int) -> int>(f: F) -> int { f(5, 6) } diff --git a/src/test/run-pass/unboxed-closures-unique-type-id.rs b/src/test/run-pass/unboxed-closures-unique-type-id.rs index 55d89d4e4f6..f35daa65a43 100644 --- a/src/test/run-pass/unboxed-closures-unique-type-id.rs +++ b/src/test/run-pass/unboxed-closures-unique-type-id.rs @@ -21,8 +21,7 @@ use std::ptr; -pub fn replace_map<'a, T, F>(src: &mut T, prod: F) -where F: |: T| -> T { +pub fn replace_map<'a, T, F>(src: &mut T, prod: F) where F: FnOnce(T) -> T { unsafe { *src = prod(ptr::read(src as *mut T as *const T)); } } diff --git a/src/test/run-pass/where-clauses-unboxed-closures.rs b/src/test/run-pass/where-clauses-unboxed-closures.rs index ae005b4ae53..808e937bc72 100644 --- a/src/test/run-pass/where-clauses-unboxed-closures.rs +++ b/src/test/run-pass/where-clauses-unboxed-closures.rs @@ -13,7 +13,7 @@ struct Bencher; // ICE -fn warm_up<'a, F>(f: F) where F: |&: &'a mut Bencher| { +fn warm_up<'a, F>(f: F) where F: Fn(&'a mut Bencher) { } fn main() { |
