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