]> git.lizzy.rs Git - rust.git/blob - src/test/ui/closure-expected-type/expect-fn-supply-fn.rs
a4e43da91baf8d805275a5913d807202a9014c40
[rust.git] / src / test / ui / closure-expected-type / expect-fn-supply-fn.rs
1 fn with_closure_expecting_fn_with_free_region<F>(_: F)
2     where F: for<'a> FnOnce(fn(&'a u32), &i32)
3 {
4 }
5
6 fn with_closure_expecting_fn_with_bound_region<F>(_: F)
7     where F: FnOnce(fn(&u32), &i32)
8 {
9 }
10
11 fn expect_free_supply_free_from_fn<'x>(x: &'x u32) {
12     // Here, the type given for `'x` "obscures" a region from the
13     // expected signature that is bound at closure level.
14     with_closure_expecting_fn_with_free_region(|x: fn(&'x u32), y| {});
15     //~^ ERROR mismatched types
16     //~| ERROR mismatched types
17 }
18
19 fn expect_free_supply_free_from_closure() {
20     // A variant on the previous test. Here, the region `'a` will be
21     // bound at the closure level, just as is expected, so no error
22     // results.
23     type Foo<'a> = fn(&'a u32);
24     with_closure_expecting_fn_with_free_region(|_x: Foo<'_>, y| {});
25 }
26
27 fn expect_free_supply_bound() {
28     // Here, we are given a function whose region is bound at closure level,
29     // but we expect one bound in the argument. Error results.
30     with_closure_expecting_fn_with_free_region(|x: fn(&u32), y| {});
31     //~^ ERROR type mismatch
32 }
33
34 fn expect_bound_supply_free_from_fn<'x>(x: &'x u32) {
35     // Here, we are given a `fn(&u32)` but we expect a `fn(&'x
36     // u32)`. In principle, this could be ok, but we demand equality.
37     with_closure_expecting_fn_with_bound_region(|x: fn(&'x u32), y| {});
38     //~^ ERROR type mismatch
39 }
40
41 fn expect_bound_supply_free_from_closure() {
42     // A variant on the previous test. Here, the region `'a` will be
43     // bound at the closure level, but we expect something bound at
44     // the argument level.
45     type Foo<'a> = fn(&'a u32);
46     with_closure_expecting_fn_with_bound_region(|x: Foo<'_>, y| {
47     //~^ ERROR type mismatch
48     });
49 }
50
51 fn expect_bound_supply_bound<'x>(x: &'x u32) {
52     // No error in this case. The supplied type supplies the bound
53     // regions, and hence we are able to figure out the type of `y`
54     // from the expected type
55     with_closure_expecting_fn_with_bound_region(|x: for<'z> fn(&'z u32), y| {
56     });
57 }
58
59 fn main() { }