]> git.proxmox.com Git - rustc.git/blob
f210346a82a675b1f9a5062cbd063f320a56306d
[rustc.git] /
1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // Test a case where we setup relationships like `'x: 'a` or `'a: 'x`,
12 // where `'x` is bound in closure type but `'a` is free. This forces
13 // us to approximate `'x` one way or the other.
14
15 // compile-flags:-Znll -Zborrowck=mir -Zverbose
16
17 #![feature(rustc_attrs)]
18
19 use std::cell::Cell;
20
21 fn foo<'a, F>(_cell: Cell<&'a u32>, _f: F)
22 where
23 F: for<'x> FnOnce(Cell<&'a u32>, Cell<&'x u32>),
24 {
25 }
26
27 #[rustc_regions]
28 fn case1() {
29 let a = 0;
30 let cell = Cell::new(&a);
31 foo(cell, |cell_a, cell_x| {
32 //~^ WARNING not reporting region error due to -Znll
33 cell_a.set(cell_x.get()); // forces 'x: 'a, error in closure
34 //~^ ERROR does not outlive free region
35 })
36 }
37
38 #[rustc_regions]
39 fn case2() {
40 let a = 0;
41 let cell = Cell::new(&a);
42 //~^ ERROR `a` does not live long enough
43
44 // As you can see in the stderr output, this closure propoagates a
45 // requirement that `'a: 'static'.
46 foo(cell, |cell_a, cell_x| {
47 cell_x.set(cell_a.get()); // forces 'a: 'x, implies 'a = 'static -> borrow error
48 })
49 }
50
51 fn main() { }