diff options
| author | bors <bors@rust-lang.org> | 2014-12-04 08:52:47 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-12-04 08:52:47 +0000 |
| commit | 53e8bd641a4d3495fb4ffb12e732390d9b4ff93e (patch) | |
| tree | 06bb72cfc78e0956825adc0c3de2d9c7b5d8c19c /src/test | |
| parent | 3c89031e1f213030f0514c8dcb9e6fa19ddbd323 (diff) | |
| parent | f2731ffb52a5873800df4ef2dfa28da9c4302976 (diff) | |
| download | rust-53e8bd641a4d3495fb4ffb12e732390d9b4ff93e.tar.gz rust-53e8bd641a4d3495fb4ffb12e732390d9b4ff93e.zip | |
auto merge of #19449 : nikomatsakis/rust/unboxed-closure-fn-impl, r=pcwalton
Implement the `Fn` trait for bare fn pointers in the compiler rather than doing it using hard-coded impls. This means that it works also for more complex fn types involving bound regions.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/compile-fail/issue-15965.rs | 4 | ||||
| -rw-r--r-- | src/test/compile-fail/issue-18532.rs | 2 | ||||
| -rw-r--r-- | src/test/compile-fail/unboxed-closures-unsafe-extern-fn.rs | 28 | ||||
| -rw-r--r-- | src/test/compile-fail/unboxed-closures-wrong-abi.rs | 28 | ||||
| -rw-r--r-- | src/test/compile-fail/unboxed-closures-wrong-arg-type-extern-fn.rs | 29 | ||||
| -rw-r--r-- | src/test/run-pass/unboxed-closures-extern-fn-hr.rs | 45 | ||||
| -rw-r--r-- | src/test/run-pass/unboxed-closures-extern-fn.rs | 2 |
7 files changed, 132 insertions, 6 deletions
diff --git a/src/test/compile-fail/issue-15965.rs b/src/test/compile-fail/issue-15965.rs index 856cd1b0f3f..935e6770658 100644 --- a/src/test/compile-fail/issue-15965.rs +++ b/src/test/compile-fail/issue-15965.rs @@ -11,8 +11,6 @@ fn main() { return { return () } //~ ERROR the type of this value must be known in this context - () //~^ ERROR the type of this value must be known in this context -//~^^ ERROR notation; the first type parameter for the function trait is neither a tuple nor unit -//~^^^ ERROR overloaded calls are experimental + () ; } diff --git a/src/test/compile-fail/issue-18532.rs b/src/test/compile-fail/issue-18532.rs index 943d326182f..9cf922ae990 100644 --- a/src/test/compile-fail/issue-18532.rs +++ b/src/test/compile-fail/issue-18532.rs @@ -17,6 +17,4 @@ fn main() { (return)((),()); //~^ ERROR the type of this value must be known - //~^^ ERROR the type of this value must be known - //~^^^ ERROR cannot use call notation } diff --git a/src/test/compile-fail/unboxed-closures-unsafe-extern-fn.rs b/src/test/compile-fail/unboxed-closures-unsafe-extern-fn.rs new file mode 100644 index 00000000000..a82689b1649 --- /dev/null +++ b/src/test/compile-fail/unboxed-closures-unsafe-extern-fn.rs @@ -0,0 +1,28 @@ +// 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. + +// Tests that unsafe extern fn pointers do not implement any Fn traits. + +#![feature(unboxed_closures)] + +use std::ops::{Fn,FnMut,FnOnce}; + +unsafe fn square(x: &int) -> int { (*x) * (*x) } + +fn call_it<F:Fn(&int)->int>(_: &F, _: int) -> int { 0 } +fn call_it_mut<F:FnMut(&int)->int>(_: &mut F, _: int) -> int { 0 } +fn call_it_once<F:FnOnce(&int)->int>(_: F, _: int) -> int { 0 } + +fn main() { + let x = call_it(&square, 22); //~ ERROR not implemented + let y = call_it_mut(&mut square, 22); //~ ERROR not implemented + let z = call_it_once(square, 22); //~ ERROR not implemented +} + diff --git a/src/test/compile-fail/unboxed-closures-wrong-abi.rs b/src/test/compile-fail/unboxed-closures-wrong-abi.rs new file mode 100644 index 00000000000..920e91958ee --- /dev/null +++ b/src/test/compile-fail/unboxed-closures-wrong-abi.rs @@ -0,0 +1,28 @@ +// 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. + +// Tests that unsafe extern fn pointers do not implement any Fn traits. + +#![feature(unboxed_closures)] + +use std::ops::{Fn,FnMut,FnOnce}; + +extern "C" fn square(x: &int) -> int { (*x) * (*x) } + +fn call_it<F:Fn(&int)->int>(_: &F, _: int) -> int { 0 } +fn call_it_mut<F:FnMut(&int)->int>(_: &mut F, _: int) -> int { 0 } +fn call_it_once<F:FnOnce(&int)->int>(_: F, _: int) -> int { 0 } + +fn main() { + let x = call_it(&square, 22); //~ ERROR not implemented + let y = call_it_mut(&mut square, 22); //~ ERROR not implemented + let z = call_it_once(square, 22); //~ ERROR not implemented +} + diff --git a/src/test/compile-fail/unboxed-closures-wrong-arg-type-extern-fn.rs b/src/test/compile-fail/unboxed-closures-wrong-arg-type-extern-fn.rs new file mode 100644 index 00000000000..a7a7b1c6762 --- /dev/null +++ b/src/test/compile-fail/unboxed-closures-wrong-arg-type-extern-fn.rs @@ -0,0 +1,29 @@ +// 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. + +// Tests that unsafe extern fn pointers do not implement any Fn traits. + +#![feature(unboxed_closures)] + +use std::ops::{Fn,FnMut,FnOnce}; + +unsafe fn square(x: int) -> int { x * x } +// note: argument type here is `int`, not `&int` + +fn call_it<F:Fn(&int)->int>(_: &F, _: int) -> int { 0 } +fn call_it_mut<F:FnMut(&int)->int>(_: &mut F, _: int) -> int { 0 } +fn call_it_once<F:FnOnce(&int)->int>(_: F, _: int) -> int { 0 } + +fn main() { + let x = call_it(&square, 22); //~ ERROR not implemented + let y = call_it_mut(&mut square, 22); //~ ERROR not implemented + let z = call_it_once(square, 22); //~ ERROR not implemented +} + diff --git a/src/test/run-pass/unboxed-closures-extern-fn-hr.rs b/src/test/run-pass/unboxed-closures-extern-fn-hr.rs new file mode 100644 index 00000000000..df753f0f33e --- /dev/null +++ b/src/test/run-pass/unboxed-closures-extern-fn-hr.rs @@ -0,0 +1,45 @@ +// 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. + +// Checks that higher-ranked extern fn pointers implement the full range of Fn traits. + +#![feature(unboxed_closures)] + +use std::ops::{Fn,FnMut,FnOnce}; + +fn square(x: &int) -> int { (*x) * (*x) } + +fn call_it<F:Fn(&int)->int>(f: &F, x: int) -> int { + (*f)(&x) +} + +fn call_it_boxed(f: &Fn(&int) -> int, x: int) -> int { + f.call((&x,)) +} + +fn call_it_mut<F:FnMut(&int)->int>(f: &mut F, x: int) -> int { + (*f)(&x) +} + +fn call_it_once<F:FnOnce(&int)->int>(f: F, x: int) -> int { + f(&x) +} + +fn main() { + let x = call_it(&square, 22); + let x1 = call_it_boxed(&square, 22); + let y = call_it_mut(&mut square, 22); + let z = call_it_once(square, 22); + assert_eq!(x, square(&22)); + assert_eq!(x1, square(&22)); + assert_eq!(y, square(&22)); + assert_eq!(z, square(&22)); +} + diff --git a/src/test/run-pass/unboxed-closures-extern-fn.rs b/src/test/run-pass/unboxed-closures-extern-fn.rs index 2628bd90eef..58657c2b718 100644 --- a/src/test/run-pass/unboxed-closures-extern-fn.rs +++ b/src/test/run-pass/unboxed-closures-extern-fn.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// Checks that extern fn points implement the full range of Fn traits. +// Checks that extern fn pointers implement the full range of Fn traits. #![feature(unboxed_closures)] #![feature(unboxed_closures)] |
