3 fn closure_expecting_bound<F>(_: F)
9 fn closure_expecting_free<'a, F>(_: F)
15 fn expect_bound_supply_nothing() {
16 // Because `x` is inferred to have a bound region, we cannot allow
17 // it to escape into `f`:
18 let mut f: Option<&u32> = None;
19 closure_expecting_bound(|x| {
20 f = Some(x); //~ ERROR borrowed data escapes outside of closure
24 fn expect_bound_supply_bound() {
25 // Because `x` is inferred to have a bound region, we cannot allow
26 // it to escape into `f`, even with an explicit type annotation on
28 let mut f: Option<&u32> = None;
29 closure_expecting_bound(|x: &u32| {
30 f = Some(x); //~ ERROR borrowed data escapes outside of closure
34 fn expect_free_supply_nothing() {
35 let mut f: Option<&u32> = None;
36 closure_expecting_free(|x| f = Some(x)); // OK
39 fn expect_free_supply_bound() {
40 let mut f: Option<&u32> = None;
42 // Here, even though the annotation `&u32` could be seen as being
43 // bound in the closure, we permit it to be defined as a free
44 // region (which is inferred to something in the fn body).
45 closure_expecting_free(|x: &u32| f = Some(x)); // OK
48 fn expect_free_supply_named<'x>() {
49 let mut f: Option<&u32> = None;
51 // Here, even though the annotation `&u32` could be seen as being
52 // bound in the closure, we permit it to be defined as a free
53 // region (which is inferred to something in the fn body).
54 closure_expecting_free(|x: &'x u32| f = Some(x)); // OK