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.
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.
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.
15 // compile-flags:-Znll -Zborrowck=mir -Zverbose
17 #![feature(rustc_attrs)]
21 fn foo<'a, F>(_cell: Cell<&'a u32>, _f: F)
23 F: for<'x> FnOnce(Cell<&'a u32>, Cell<&'x u32>),
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
41 let cell = Cell::new(&a);
42 //~^ ERROR `a` does not live long enough
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