]> git.proxmox.com Git - rustc.git/blob - src/test/ui/nll/closure-requirements/escape-argument-callee.rs
New upstream version 1.63.0+dfsg1
[rustc.git] / src / test / ui / nll / closure-requirements / escape-argument-callee.rs
1 // Test closure that:
2 //
3 // - takes an argument `y` with lifetime `'a` (in the code, it's anonymous)
4 // - stores `y` into another, longer-lived spot with lifetime `'b`
5 //
6 // Because `'a` and `'b` are two different, unrelated higher-ranked
7 // regions with no relationship to one another, this is an error. This
8 // error is reported by the closure itself and is not propagated to
9 // its creator: this is because `'a` and `'b` are higher-ranked
10 // (late-bound) regions and the closure is not allowed to propagate
11 // additional where clauses between higher-ranked regions, only those
12 // that appear free in its type (hence, we see it before the closure's
13 // "external requirements" report).
14
15 // compile-flags:-Zverbose
16
17 #![feature(rustc_attrs)]
18
19 #[rustc_regions]
20 fn test() {
21 let x = 44;
22 let mut p = &x;
23
24 {
25 let y = 22;
26 let mut closure = expect_sig(|p, y| *p = y);
27 //~^ ERROR
28 closure(&mut p, &y);
29 }
30
31 deref(p);
32 }
33
34 fn expect_sig<F>(f: F) -> F
35 where F: FnMut(&mut &i32, &i32)
36 {
37 f
38 }
39
40 fn deref(_p: &i32) { }
41
42 fn main() { }