2017-11-22 16:39:46 -06:00
|
|
|
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2017-12-06 15:25:10 -06:00
|
|
|
// Test a case where we are trying to prove `'x: 'y` and are forced to
|
|
|
|
// approximate the shorter end-point (`'y`) to with `'static`. This is
|
|
|
|
// because `'y` is higher-ranked but we know of only irrelevant
|
|
|
|
// relations to other regions. Note that `'static` shows up in the
|
|
|
|
// stderr output as `'0`.
|
|
|
|
//
|
|
|
|
// FIXME(#45827) Because of shortcomings in the MIR type checker,
|
|
|
|
// these errors are not (yet) reported.
|
2017-11-22 16:39:46 -06:00
|
|
|
|
2018-04-09 04:28:00 -05:00
|
|
|
// compile-flags:-Zborrowck=mir -Zverbose
|
2017-11-22 16:39:46 -06:00
|
|
|
|
|
|
|
#![feature(rustc_attrs)]
|
|
|
|
|
|
|
|
use std::cell::Cell;
|
|
|
|
|
|
|
|
// Callee knows that:
|
|
|
|
//
|
|
|
|
// 'x: 'a
|
2017-12-06 15:25:10 -06:00
|
|
|
// 'y: 'b
|
2017-11-22 16:39:46 -06:00
|
|
|
//
|
|
|
|
// so the only way we can ensure that `'x: 'y` is to show that
|
|
|
|
// `'a: 'static`.
|
|
|
|
fn establish_relationships<'a, 'b, F>(_cell_a: &Cell<&'a u32>, _cell_b: &Cell<&'b u32>, _closure: F)
|
|
|
|
where
|
|
|
|
F: for<'x, 'y> FnMut(
|
|
|
|
&Cell<&'a &'x u32>, // shows that 'x: 'a
|
2017-12-06 15:25:10 -06:00
|
|
|
&Cell<&'b &'y u32>, // shows that 'y: 'b
|
2017-11-22 16:39:46 -06:00
|
|
|
&Cell<&'x u32>,
|
|
|
|
&Cell<&'y u32>,
|
|
|
|
),
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
fn demand_y<'x, 'y>(_cell_x: &Cell<&'x u32>, _cell_y: &Cell<&'y u32>, _y: &'y u32) {}
|
|
|
|
|
|
|
|
#[rustc_regions]
|
|
|
|
fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
|
2017-12-06 15:25:10 -06:00
|
|
|
establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
|
2018-09-06 21:57:05 -05:00
|
|
|
//~^ ERROR borrowed data escapes outside of function
|
|
|
|
//~| ERROR unsatisfied lifetime constraints
|
2017-11-22 16:39:46 -06:00
|
|
|
// Only works if 'x: 'y:
|
|
|
|
demand_y(x, y, x.get())
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {}
|