]>
git.proxmox.com Git - rustc.git/blob - src/test/ui/nll/closure-requirements/propagate-approximated-ref.rs
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 // Rather convoluted setup where we infer a relationship between two
12 // free regions in the closure signature (`'a` and `'b`) on the basis
13 // of a relationship between two bound regions (`'x` and `'y`).
15 // The idea is that, thanks to invoking `demand_y`, `'x: 'y` must
16 // hold, where `'x` and `'y` are bound regions. The closure can't
17 // prove that directly, and because `'x` and `'y` are bound it cannot
18 // ask the caller to prove it either. But it has bounds on `'x` and
19 // `'y` in terms of `'a` and `'b`, and it can propagate a relationship
20 // between `'a` and `'b` to the caller.
22 // Note: the use of `Cell` here is to introduce invariance. One less
25 // compile-flags:-Zborrowck=mir -Zverbose
27 #![feature(rustc_attrs)]
36 // so if we are going to ensure that `'x: 'y`, then `'a: 'b` must
38 fn establish_relationships
<'a
, 'b
, F
>(_cell_a
: &Cell
<&'a
u32>, _cell_b
: &Cell
<&'b
u32>, _closure
: F
)
41 &Cell
<&'a
&'x
u32>, // shows that 'x: 'a
42 &Cell
<&'y
&'b
u32>, // shows that 'b: 'y
49 fn demand_y
<'x
, 'y
>(_cell_x
: &Cell
<&'x
u32>, _cell_y
: &Cell
<&'y
u32>, _y
: &'y
u32) {}
52 fn supply
<'a
, 'b
>(cell_a
: Cell
<&'a
u32>, cell_b
: Cell
<&'b
u32>) {
53 establish_relationships(&cell_a
, &cell_b
, |_outlives1
, _outlives2
, x
, y
| {
54 //~^ ERROR lifetime mismatch
56 // Only works if 'x: 'y:
57 demand_y(x
, y
, x
.get()) //~ WARNING not reporting region error due to nll